Component.cs 617 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using MongoDB.Bson.Serialization.Attributes;
  2. namespace Base
  3. {
  4. /// <summary>
  5. /// Component的Id与Owner Entity Id一样
  6. /// </summary>
  7. public abstract class Component : Object
  8. {
  9. [BsonIgnore]
  10. public Entity Owner { get; set; }
  11. protected Component()
  12. {
  13. ObjectManager.Add(this);
  14. }
  15. protected Component(long id): base(id)
  16. {
  17. ObjectManager.Add(this);
  18. }
  19. public T GetComponent<T>() where T: Component
  20. {
  21. return this.Owner.GetComponent<T>();
  22. }
  23. public override void Dispose()
  24. {
  25. if (this.Id == 0)
  26. {
  27. return;
  28. }
  29. base.Dispose();
  30. ObjectManager.Remove(this.Id);
  31. }
  32. }
  33. }