Component.cs 622 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  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 { protected get; set; }
  11. protected T GetOwner<T>() where T: Entity
  12. {
  13. return this.Owner as T;
  14. }
  15. protected Component()
  16. {
  17. }
  18. protected Component(long id): base(id)
  19. {
  20. }
  21. protected T GetComponent<T>() where T: Component
  22. {
  23. return this.Owner.GetComponent<T>();
  24. }
  25. public override void Dispose()
  26. {
  27. if (this.Id == 0)
  28. {
  29. return;
  30. }
  31. base.Dispose();
  32. }
  33. }
  34. }