ActorProxyComponent.cs 640 B

12345678910111213141516171819202122232425262728293031
  1. using System.Collections.Generic;
  2. namespace Model
  3. {
  4. public class ActorProxyComponent: Component
  5. {
  6. private readonly Dictionary<long, ActorProxy> dictionary = new Dictionary<long, ActorProxy>();
  7. public ActorProxy Get(long id)
  8. {
  9. if (this.dictionary.TryGetValue(id, out ActorProxy actorProxy))
  10. {
  11. return actorProxy;
  12. }
  13. actorProxy = EntityFactory.CreateWithId<ActorProxy>(id);
  14. this.dictionary[id] = actorProxy;
  15. return actorProxy;
  16. }
  17. public void Remove(long id)
  18. {
  19. ActorProxy actorProxy;
  20. if (!this.dictionary.TryGetValue(id, out actorProxy))
  21. {
  22. return;
  23. }
  24. actorProxy.Dispose();
  25. }
  26. }
  27. }