ActorComponent.cs 531 B

12345678910111213141516171819202122232425262728
  1. using System.Collections.Generic;
  2. using Common.Base;
  3. using MongoDB.Bson;
  4. namespace Model
  5. {
  6. public class ActorComponent : Component<World>
  7. {
  8. private readonly Dictionary<ObjectId, Actor> actors = new Dictionary<ObjectId, Actor>();
  9. public Actor Get(ObjectId id)
  10. {
  11. return this.actors[id];
  12. }
  13. public void Add(Actor actor)
  14. {
  15. this.actors[actor.Id] = actor;
  16. }
  17. public void Remove(ObjectId id)
  18. {
  19. Actor actor = this.Get(id);
  20. this.actors.Remove(id);
  21. actor.Dispose();
  22. }
  23. }
  24. }