public void Init(BodyComponent bodyComponent, int side) { this.bodyComponent = bodyComponent; this.side = side; //this.transform.position = this.bodyComponent.transform.position; this.transform.parent = this.bodyComponent.transform; this.transform.localPosition = Vector3.zero; Vector3 pos = this.transform.position; //float scale = this.bodyComponent.GetScale (); //float offset = scale / 2; float offset = this.bodyComponent.transform.localScale.x / 2.0f; switch (this.side) { case 0: pos.y -= offset; break; case 5: pos.y += offset; break; case 1: pos.x -= offset; break; case 4: pos.x += offset; break; case 2: pos.z -= offset; break; case 3: pos.z += offset; break; } this.transform.position = pos; }
public static Entity AddComponent(this Entity entity, DrawableComponent drawableComponent, BodyComponent bodyComponent) { if (drawableComponent == null || bodyComponent == null) { throw new ArgumentNullException($"Argument {nameof(drawableComponent)} or {nameof(bodyComponent)} can't be null!"); } // This is necessary because Aether.Physics2D works better with negative Y gravity. // See samples: https://github.com/tainicom/Aether.Physics2D/tree/master/Samples drawableComponent.DrawInUICamera = false; entity.AddComponent(drawableComponent).AddComponent(bodyComponent); return(entity); }