Component.cs 511 B

1234567891011121314151617181920212223242526272829303132
  1. namespace Base
  2. {
  3. /// <summary>
  4. /// Component的Id与Owner Entity Id一样
  5. /// </summary>
  6. public abstract class Component: Object
  7. {
  8. public Entity Owner { get; set; }
  9. protected Component()
  10. {
  11. ObjectManager.Add(this);
  12. }
  13. protected Component(long id): base(id)
  14. {
  15. ObjectManager.Add(this);
  16. }
  17. public T GetComponent<T>() where T: Component
  18. {
  19. return this.Owner.GetComponent<T>();
  20. }
  21. public override void Dispose()
  22. {
  23. base.Dispose();
  24. ObjectManager.Remove(this.Id);
  25. }
  26. }
  27. }