mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-01 07:42:38 +08:00
4bc2739786
* Vmath (#4895) * vmath refactor * value-type API change * vmath change update * conflict fix * value types change * translate modify (#4917) * value types bug fixed (#4940) * playground update (#4946) * bug fixed * bug fixed * bug fixed * bug fix * util modify * create remove & ccenum rename * export by cc.math * Rename value-types to math * util funtion deprecated warn * value-types change * color test fix * color API change
78 lines
1.7 KiB
TypeScript
78 lines
1.7 KiB
TypeScript
/**
|
|
* @category physics
|
|
*/
|
|
|
|
import {
|
|
ccclass,
|
|
executeInEditMode,
|
|
executionOrder,
|
|
menu,
|
|
property,
|
|
} from '../../../../core/data/class-decorator';
|
|
import { Vec3 } from '../../../../core/math';
|
|
import { BoxShapeBase } from '../../../physics/api';
|
|
import { createBoxShape } from '../../../physics/instance';
|
|
import { ColliderComponent } from './collider-component';
|
|
|
|
/**
|
|
* @zh
|
|
* 盒子碰撞器
|
|
*/
|
|
@ccclass('cc.BoxColliderComponent')
|
|
@executionOrder(98)
|
|
@menu('Components/BoxColliderComponent')
|
|
@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_BUILT_IN) {
|
|
this._shape.setScale(this.node.worldScale);
|
|
}
|
|
}
|
|
}
|
|
}
|