2020-07-23 09:10:27 +08:00
|
|
|
|
module es {
|
|
|
|
|
|
export class CircleCollider extends Collider {
|
|
|
|
|
|
/**
|
2020-12-30 16:28:07 +08:00
|
|
|
|
* 创建一个具有半径的CircleCollider。
|
|
|
|
|
|
* 请注意,当指定半径时,如果在实体上使用RenderableComponent,您将需要设置原点来对齐CircleCollider。
|
|
|
|
|
|
* 例如,如果RenderableComponent有一个0,0的原点,并且创建了一个半径为1.5f * renderable.width的CircleCollider,你可以通过设置originNormalied为中心除以缩放尺寸来偏移原点
|
2020-07-23 09:10:27 +08:00
|
|
|
|
*
|
|
|
|
|
|
* @param radius
|
|
|
|
|
|
*/
|
2020-11-23 16:05:06 +08:00
|
|
|
|
constructor(radius: number) {
|
2020-07-23 09:10:27 +08:00
|
|
|
|
super();
|
2020-07-09 15:11:30 +08:00
|
|
|
|
|
2020-11-23 16:05:06 +08:00
|
|
|
|
this.shape = new Circle(radius);
|
2020-07-23 09:10:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-07-28 16:25:20 +08:00
|
|
|
|
public get radius(): number {
|
|
|
|
|
|
return (this.shape as Circle).radius;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public set radius(value: number) {
|
|
|
|
|
|
this.setRadius(value);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-07-23 09:10:27 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 设置圆的半径
|
|
|
|
|
|
* @param radius
|
|
|
|
|
|
*/
|
|
|
|
|
|
public setRadius(radius: number): CircleCollider {
|
2020-12-30 16:28:07 +08:00
|
|
|
|
this._colliderRequiresAutoSizing = false;
|
2020-07-23 09:10:27 +08:00
|
|
|
|
let circle = this.shape as Circle;
|
|
|
|
|
|
if (radius != circle.radius) {
|
|
|
|
|
|
circle.radius = radius;
|
|
|
|
|
|
circle._originalRadius = radius;
|
2020-12-30 16:28:07 +08:00
|
|
|
|
this._isPositionDirty = true;
|
2020-07-09 15:11:30 +08:00
|
|
|
|
|
2020-12-30 16:28:07 +08:00
|
|
|
|
if (this.entity != null && this._isParentEntityAddedToScene)
|
2020-07-23 09:10:27 +08:00
|
|
|
|
Physics.updateCollider(this);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return this;
|
2020-07-09 15:11:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-07-23 09:10:27 +08:00
|
|
|
|
public toString() {
|
|
|
|
|
|
return `[CircleCollider: bounds: ${this.bounds}, radius: ${(this.shape as Circle).radius}]`
|
|
|
|
|
|
}
|
2020-07-09 15:11:30 +08:00
|
|
|
|
}
|
2020-07-23 09:10:27 +08:00
|
|
|
|
}
|