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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public setWidth(width: number): BoxCollider{
|
|
|
|
|
this._colliderRequiresAutoSizing = false;
|
|
|
|
|
let box = this.shape as Box;
|
|
|
|
|
if (width != box.width){
|
|
|
|
|
box.updateBox(width, box.height);
|
|
|
|
|
this._isPositionDirty = true;
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public setHeight(height: number){
|
|
|
|
|
this._colliderRequiresAutoSizing = false;
|
|
|
|
|
let box = this.shape as Box;
|
|
|
|
|
if (height != box.height){
|
|
|
|
|
box.updateBox(box.width, height);
|
|
|
|
|
this._isPositionDirty = true;
|
|
|
|
|
if (this.entity && this._isParentEntityAddedToScene)
|
|
|
|
|
Physics.updateCollider(this);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
constructor(){
|
|
|
|
|
super();
|
|
|
|
|
|
|
|
|
|
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){
|
|
|
|
|
box.updateBox(width, height);
|
|
|
|
|
this._isPositionDirty = true;
|
|
|
|
|
if (this.entity && this._isParentEntityAddedToScene)
|
|
|
|
|
Physics.updateCollider(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return this;
|
|
|
|
|
}
|
2020-06-15 10:42:06 +08:00
|
|
|
}
|