Disposer.cs 595 B

12345678910111213141516171819202122232425262728293031323334353637
  1. using System;
  2. using MongoDB.Bson.Serialization.Attributes;
  3. namespace Model
  4. {
  5. [BsonKnownTypes(typeof(Component))]
  6. public abstract class Disposer : Object, IDisposable
  7. {
  8. [BsonIgnoreIfDefault]
  9. [BsonDefaultValue(1L)]
  10. [BsonElement]
  11. [BsonId]
  12. public long Id { get; set; }
  13. [BsonIgnore]
  14. public bool IsFromPool { get; set; }
  15. protected Disposer()
  16. {
  17. this.Id = IdGenerater.GenerateId();
  18. }
  19. protected Disposer(long id)
  20. {
  21. this.Id = id;
  22. }
  23. public virtual void Dispose()
  24. {
  25. this.Id = 0;
  26. if (this.IsFromPool)
  27. {
  28. Game.ObjectPool.Recycle(this);
  29. }
  30. }
  31. }
  32. }