Component.cs 639 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using MongoDB.Bson.Serialization.Attributes;
  2. namespace Hotfix
  3. {
  4. [ILBinding]
  5. [BsonKnownTypes(typeof (AConfigComponent))]
  6. public abstract class Component: Disposer
  7. {
  8. [BsonIgnore]
  9. public Entity Owner { get; set; }
  10. public T GetOwner<T>() where T : Entity
  11. {
  12. return this.Owner as T;
  13. }
  14. protected Component()
  15. {
  16. }
  17. protected Component(long id): base(id)
  18. {
  19. }
  20. public T GetComponent<T>() where T : Component
  21. {
  22. return this.Owner.GetComponent<T>();
  23. }
  24. public override void Dispose()
  25. {
  26. if (this.Id == 0)
  27. {
  28. return;
  29. }
  30. base.Dispose();
  31. this.Owner.RemoveComponent(this.GetType());
  32. }
  33. }
  34. }