using MongoDB.Bson.Serialization.Attributes; namespace Base { /// /// Component的Id与Owner Entity Id一样 /// public abstract class Component : Object { [BsonIgnore] public Entity Owner { get; set; } 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() { if (this.Id == 0) { return; } long id = this.Id; base.Dispose(); ObjectManager.Remove(id); } } }