Component.cs 598 B

123456789101112131415161718192021222324252627282930313233343536373839
  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. private Entity owner;
  10. public T GetOwner<T>() where T: Entity
  11. {
  12. return this.owner as T;
  13. }
  14. public void SetOwner(Entity entity)
  15. {
  16. this.owner = entity;
  17. }
  18. protected Component()
  19. {
  20. ObjectManager.Add(this);
  21. }
  22. protected Component(long id): base(id)
  23. {
  24. ObjectManager.Add(this);
  25. }
  26. public override void Dispose()
  27. {
  28. base.Dispose();
  29. ObjectManager.Remove(this.Id);
  30. }
  31. }
  32. }