Files
cocos4/cocos/physics/components/collider/box-collider-component.ts
T
2019-09-16 17:21:52 +08:00

78 lines
1.6 KiB
TypeScript

/**
* @category physics
*/
import {
ccclass,
executeInEditMode,
executionOrder,
menu,
property,
} from '../../../core/data/class-decorator';
import { Vec3 } from '../../../core/math';
import { BoxShapeBase } from '../../api';
import { createBoxShape } from '../../instance';
import { ColliderComponent } from './collider-component';
/**
* @zh
* 盒子碰撞器
*/
@ccclass('cc.BoxColliderComponent')
@executionOrder(98)
@menu('Components/BoxCollider')
@executeInEditMode
export class BoxColliderComponent extends ColliderComponent {
private _shape!: BoxShapeBase;
/// PRIVATE PROPERTY ///
@property
private _size: Vec3 = new Vec3(0, 0, 0);
constructor () {
super();
if (!CC_EDITOR) {
this._shape = createBoxShape(this._size);
this._shape.setUserData(this);
this._shapeBase = this._shape;
}
}
/// COMPONENT LIFECYCLE ///
protected onLoad () {
super.onLoad();
if (!CC_EDITOR) {
this.size = this._size;
this._shape.setScale(this.node.worldScale);
}
}
/// PUBLIC PROPERTY GETTER\SETTER ///
/**
* @en
* Get or set the size of the box, in local space.
* @zh
* 获取或设置盒的大小。
*/
@property({ type: Vec3 })
public get size () {
return this._size;
}
public set size (value) {
Vec3.copy(this._size, value);
if (!CC_EDITOR) {
this._shape.setSize(this._size);
if (CC_PHYSICS_BUILTIN) {
this._shape.setScale(this.node.worldScale);
}
}
}
}