namespace Base { /// /// Component的Id与Owner Entity Id一样 /// public abstract class Component: Object { public Entity Owner { get; set; } public T GetOwner() where T: Entity { T owner = this.Owner as T; if (owner == null) { Log.Error($"Owner类型是{this.Owner.GetType().Name}, 无法转成: {typeof(T).Name}"); } return owner; } protected Component() { ObjectManager.Add(this); } protected Component(long id): base(id) { ObjectManager.Add(this); } public T GetComponent() where T: Component { return this.Owner.GetComponent(); } public override void Dispose() { base.Dispose(); ObjectManager.Remove(this.Id); } } }