Files
esengine/source/src/ECS/Components/Physics/Colliders/BoxCollider.ts

86 lines
2.8 KiB
TypeScript
Raw Normal View History

2020-06-15 10:42:06 +08:00
///<reference path="./Collider.ts" />
2020-07-23 09:10:27 +08:00
module es {
export class BoxCollider extends Collider {
public get width(){
return (this.shape as Box).width;
}
2020-06-15 10:42:06 +08:00
2020-07-23 09:10:27 +08:00
public set width(value: number){
this.setWidth(value);
}
2020-06-15 10:42:06 +08:00
2020-07-23 09:10:27 +08:00
public get height(){
return (this.shape as Box).height;
2020-06-15 10:42:06 +08:00
}
2020-07-23 09:10:27 +08:00
public set height(value: number){
this.setHeight(value);
}
2020-07-23 09:10:27 +08:00
/**
* RenderableComponent在实体上
*/
constructor(){
super();
2020-07-23 09:10:27 +08:00
// 我们在这里插入一个1x1框作为占位符直到碰撞器在下一阵被添加到实体并可以获得更精确的自动调整大小数据
this.shape = new Box(1, 1);
this._colliderRequiresAutoSizing = true;
}
2020-07-23 09:10:27 +08:00
/**
* BoxCollider的大小
* @param width
* @param height
*/
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);
if (this.entity && this._isParentEntityAddedToScene)
Physics.updateCollider(this);
}
return this;
}
2020-07-23 09:10:27 +08:00
/**
* BoxCollider的宽度
* @param width
*/
public setWidth(width: number): BoxCollider{
this._colliderRequiresAutoSizing = false;
let box = this.shape as Box;
if (width != box.width){
// 更新框,改变边界,如果我们需要更新物理系统中的边界
box.updateBox(width, box.height);
if (this.entity && this._isParentEntityAddedToScene)
Physics.updateCollider(this);
}
2020-07-23 09:10:27 +08:00
return this;
}
2020-07-23 09:10:27 +08:00
/**
* BoxCollider的高度
* @param height
*/
public setHeight(height: number){
this._colliderRequiresAutoSizing = false;
let box = this.shape as Box;
if (height != box.height){
// 更新框,改变边界,如果我们需要更新物理系统中的边界
box.updateBox(box.width, height);
if (this.entity && this._isParentEntityAddedToScene)
Physics.updateCollider(this);
}
}
2020-07-23 09:10:27 +08:00
public toString(){
return `[BoxCollider: bounds: ${this.bounds}]`;
}
}
2020-07-23 09:10:27 +08:00
}