ActorManagerComponent.cs 896 B

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