ActorManagerComponent.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System.Collections.Generic;
  2. namespace ETModel
  3. {
  4. [ObjectSystem]
  5. public class ActorManagerComponentAwakeSystem : AwakeSystem<ActorManagerComponent>
  6. {
  7. public override void Awake(ActorManagerComponent self)
  8. {
  9. self.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. Log.Info($"add actor: {entity.Id} {entity.GetType().Name}");
  24. dictionary[entity.Id] = entity;
  25. }
  26. public void Remove(long id)
  27. {
  28. Entity entity;
  29. if (!this.dictionary.TryGetValue(id, out entity))
  30. {
  31. return;
  32. }
  33. Log.Info($"remove actor: {entity.Id} {entity.GetType().Name}");
  34. this.dictionary.Remove(id);
  35. }
  36. public Entity Get(long id)
  37. {
  38. Entity entity = null;
  39. this.dictionary.TryGetValue(id, out entity);
  40. return entity;
  41. }
  42. public override void Dispose()
  43. {
  44. if (this.IsDisposed)
  45. {
  46. return;
  47. }
  48. base.Dispose();
  49. }
  50. }
  51. }