2020-06-15 10:42:06 +08:00
|
|
|
|
///<reference path="./Collider.ts" />
|
|
|
|
|
|
class BoxCollider extends Collider {
|
|
|
|
|
|
public get width(){
|
|
|
|
|
|
return (this.shape as Box).width;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public set width(value: number){
|
|
|
|
|
|
this.setWidth(value);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-07-08 18:12:17 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 设置BoxCollider的宽度
|
|
|
|
|
|
* @param width
|
|
|
|
|
|
*/
|
2020-06-15 10:42:06 +08:00
|
|
|
|
public setWidth(width: number): BoxCollider{
|
|
|
|
|
|
this._colliderRequiresAutoSizing = false;
|
|
|
|
|
|
let box = this.shape as Box;
|
|
|
|
|
|
if (width != box.width){
|
2020-07-08 18:12:17 +08:00
|
|
|
|
// 更新框,改变边界,如果我们需要更新物理系统中的边界
|
2020-06-15 10:42:06 +08:00
|
|
|
|
box.updateBox(width, box.height);
|
|
|
|
|
|
if (this.entity && this._isParentEntityAddedToScene)
|
|
|
|
|
|
Physics.updateCollider(this);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return this;
|
|
|
|
|
|
}
|
2020-06-15 20:08:21 +08:00
|
|
|
|
|
|
|
|
|
|
public get height(){
|
|
|
|
|
|
return (this.shape as Box).height;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public set height(value: number){
|
|
|
|
|
|
this.setHeight(value);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-07-08 18:12:17 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 设置BoxCollider的高度
|
|
|
|
|
|
* @param height
|
|
|
|
|
|
*/
|
2020-06-15 20:08:21 +08:00
|
|
|
|
public setHeight(height: number){
|
|
|
|
|
|
this._colliderRequiresAutoSizing = false;
|
|
|
|
|
|
let box = this.shape as Box;
|
|
|
|
|
|
if (height != box.height){
|
2020-07-08 18:12:17 +08:00
|
|
|
|
// 更新框,改变边界,如果我们需要更新物理系统中的边界
|
2020-06-15 20:08:21 +08:00
|
|
|
|
box.updateBox(box.width, height);
|
|
|
|
|
|
if (this.entity && this._isParentEntityAddedToScene)
|
|
|
|
|
|
Physics.updateCollider(this);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-07-08 18:12:17 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 零参数构造函数要求RenderableComponent在实体上,这样碰撞器可以在实体被添加到场景时调整自身的大小。
|
|
|
|
|
|
*/
|
2020-06-15 20:08:21 +08:00
|
|
|
|
constructor(){
|
|
|
|
|
|
super();
|
|
|
|
|
|
|
2020-07-07 18:54:19 +08:00
|
|
|
|
// 我们在这里插入一个1x1框作为占位符,直到碰撞器在下一阵被添加到实体并可以获得更精确的自动调整大小数据
|
2020-06-15 20:08:21 +08:00
|
|
|
|
this.shape = new Box(1, 1);
|
|
|
|
|
|
this._colliderRequiresAutoSizing = true;
|
|
|
|
|
|
}
|
2020-06-16 11:22:37 +08:00
|
|
|
|
|
|
|
|
|
|
public setSize(width: number, height: number){
|
|
|
|
|
|
this._colliderRequiresAutoSizing = false;
|
|
|
|
|
|
let box = this.shape as Box;
|
|
|
|
|
|
if (width != box.width || height != box.height){
|
2020-07-08 18:12:17 +08:00
|
|
|
|
// 更新框,改变边界,如果我们需要更新物理系统中的边界
|
2020-06-16 11:22:37 +08:00
|
|
|
|
box.updateBox(width, height);
|
|
|
|
|
|
if (this.entity && this._isParentEntityAddedToScene)
|
|
|
|
|
|
Physics.updateCollider(this);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return this;
|
|
|
|
|
|
}
|
2020-06-15 10:42:06 +08:00
|
|
|
|
}
|