移除Core,新增各接口用于sdk扩展

This commit is contained in:
yhh
2020-12-30 16:28:07 +08:00
parent f934890fac
commit d84ffcc2b7
28 changed files with 2008 additions and 653 deletions

View File

@@ -116,6 +116,28 @@ module es {
public onAddedToEntity() {
if (this._colliderRequiresAutoSizing) {
Insist.isTrue(this instanceof BoxCollider || this instanceof CircleCollider, "只有框和圆的碰撞器可以自动创建");
let renderable = this.entity.getComponent<RenderableComponent>(RenderableComponent);
if (renderable == null)
console.warn("Collider没有形状也没有RenderableComponent。不知道如何确定它的大小。");
if (renderable != null) {
let renderableBounds = renderable.bounds.clone();
// 我们在这里需要大小*反比例因为当我们自动调整Collider的大小时它需要没有一个缩放的Renderable
let width = renderableBounds.width / this.entity.transform.scale.x;
let height = renderableBounds.height / this.entity.transform.scale.y;
if (this instanceof CircleCollider) {
this.radius = Math.max(width, height) * 0.5;
// 获取Renderable的中心将其转移到本地坐标并将其作为我们碰撞器的localOffset
this.localOffset = Vector2.subtract(renderableBounds.center, this.entity.transform.position);
} else if (this instanceof BoxCollider) {
this.width = width;
this.height = height;
this.localOffset = Vector2.subtract(renderableBounds.center, this.entity.transform.position);
}
}
}
this._isParentEntityAddedToScene = true;