-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
box-collider-component.ts
77 lines (64 loc) · 1.63 KB
/
box-collider-component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/**
* @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/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);
}
}
}
}