-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
cylinder-collider.ts
110 lines (96 loc) · 2.54 KB
/
cylinder-collider.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/**
* @category physics
*/
import {
ccclass,
help,
executeInEditMode,
menu,
tooltip,
type,
serializable,
} from 'cc.decorator';
import { Collider } from './collider';
import { ICylinderShape } from '../../../spec/i-physics-shape';
import { EDITOR, TEST } from 'internal:constants';
import { EAxisDirection, EColliderType } from '../../physics-enum';
/**
* @en
* Cylinder collider component.
* @zh
* 圆柱体碰撞器。
*/
@ccclass('cc.CylinderCollider')
@help('i18n:cc.CylinderCollider')
@menu('Physics/CylinderCollider')
@executeInEditMode
export class CylinderCollider extends Collider {
/// PUBLIC PROPERTY GETTER\SETTER ///
/**
* @en
* Gets or sets the radius of the circle on the cylinder body, in local space.
* @zh
* 获取或设置圆柱体上圆面半径。
*/
@tooltip('圆柱体上圆面的半径')
public get radius () {
return this._radius;
}
public set radius (value) {
if (this._radius == value) return;
if (value < 0) value = 0;
this._radius = value;
if (!EDITOR && !TEST) {
this.shape.setRadius(value);
}
}
/**
* @en
* Gets or sets the cylinder body is at the corresponding axial height, in local space.
* @zh
* 获取或设置圆柱体在相应轴向的高度。
*/
@tooltip('圆柱体在相应轴向的高度')
public get height () {
return this._height;
}
public set height (value) {
if (this._height == value) return;
if (value < 0) value = 0;
this._height = value;
if (!EDITOR && !TEST) {
this.shape.setHeight(value);
}
}
/**
* @en
* Gets or sets the cylinder direction, in local space.
* @zh
* 获取或设置在圆柱体本地空间上的方向。
*/
@type(EAxisDirection)
public get direction () {
return this._direction;
}
public set direction (value: EAxisDirection) {
if (this._direction == value) return;
if (value < EAxisDirection.X_AXIS || value > EAxisDirection.Z_AXIS) return;
this._direction = value;
if (!EDITOR && !TEST) {
this.shape.setDirection(value);
}
}
public get shape () {
return this._shape as ICylinderShape;
}
/// PRIVATE PROPERTY ///
@serializable
private _radius = 0.5;
@serializable
private _height = 2;
@serializable
private _direction = EAxisDirection.Y_AXIS;
constructor () {
super(EColliderType.CYLINDER);
}
}