ActorManagerComponent.cs 841 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using System.Collections.Generic;
  2. namespace Model
  3. {
  4. [ObjectEvent]
  5. public class ActorManagerComponentEvent : ObjectEvent<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.Add(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. this.dictionary.TryGetValue(id, out Entity entity);
  32. return entity;
  33. }
  34. public override void Dispose()
  35. {
  36. if (this.Id == 0)
  37. {
  38. return;
  39. }
  40. base.Dispose();
  41. }
  42. }
  43. }