ActorManagerComponent.cs 862 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using System.Collections.Generic;
  2. namespace Model
  3. {
  4. [ObjectSystem]
  5. public class ActorManagerComponentSystem : ObjectSystem<ActorManagerComponent>, IAwake
  6. {
  7. public void Awake()
  8. {
  9. this.Get().Awake();
  10. }
  11. }
  12. /// <summary>
  13. /// 用来管理该服务器上所有的Actor对象
  14. /// </summary>
  15. public class ActorManagerComponent : Component
  16. {
  17. private readonly Dictionary<long, Entity> dictionary = new Dictionary<long, Entity>();
  18. public void Awake()
  19. {
  20. }
  21. public void Add(Entity entity)
  22. {
  23. dictionary[entity.Id] = entity;
  24. }
  25. public void Remove(long id)
  26. {
  27. this.dictionary.Remove(id);
  28. }
  29. public Entity Get(long id)
  30. {
  31. Entity entity = null;
  32. this.dictionary.TryGetValue(id, out entity);
  33. return entity;
  34. }
  35. public override void Dispose()
  36. {
  37. if (this.IsDisposed)
  38. {
  39. return;
  40. }
  41. base.Dispose();
  42. }
  43. }
  44. }