PlayerComponent.cs 784 B

123456789101112131415161718192021222324252627282930313233343536
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. namespace ET
  4. {
  5. public class PlayerComponent : Entity, IAwake, IDestroy, IAppClose
  6. {
  7. private readonly Dictionary<long, Player> idPlayers = new Dictionary<long, Player>();
  8. public void Add(Player player)
  9. {
  10. idPlayers.Add(player.AccountId, player);
  11. }
  12. public Player Get(long id)
  13. {
  14. idPlayers.TryGetValue(id, out Player gamer);
  15. return gamer;
  16. }
  17. public void Remove(long id)
  18. {
  19. idPlayers.Remove(id);
  20. }
  21. public int Count
  22. {
  23. get { return idPlayers.Count; }
  24. }
  25. public Player[] GetAll()
  26. {
  27. return idPlayers.Values.ToArray();
  28. }
  29. }
  30. }