Component.cs 520 B

12345678910111213141516171819202122232425262728293031323334353637
  1. namespace Hotfix
  2. {
  3. public abstract class Component: Disposer
  4. {
  5. public Entity Owner { get; set; }
  6. public T GetOwner<T>() where T : Entity
  7. {
  8. return this.Owner as T;
  9. }
  10. protected Component()
  11. {
  12. }
  13. protected Component(long id): base(id)
  14. {
  15. }
  16. public T GetComponent<T>() where T : Component
  17. {
  18. return this.Owner.GetComponent<T>();
  19. }
  20. public override void Dispose()
  21. {
  22. if (this.Id == 0)
  23. {
  24. return;
  25. }
  26. base.Dispose();
  27. this.Owner.RemoveComponent(this.GetType());
  28. }
  29. }
  30. }