PlayerComponentSystem.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using System.Linq;
  2. namespace ET.Server
  3. {
  4. public class PlayerComponentAwakeSystem : AwakeSystem<PlayerComponent>
  5. {
  6. protected override void Awake(PlayerComponent self)
  7. {
  8. PlayerComponent.PlayerComponentList.Add(self);
  9. }
  10. }
  11. public class PlayerComponentDestroySystem : DestroySystem<PlayerComponent>
  12. {
  13. protected override void Destroy(PlayerComponent self)
  14. {
  15. foreach(var player in PlayerComponent.PlayerComponentList)
  16. {
  17. if(player == self)
  18. {
  19. PlayerComponent.PlayerComponentList.Remove(player);
  20. return;
  21. }
  22. }
  23. }
  24. }
  25. [FriendOf(typeof(PlayerComponent))]
  26. public static class PlayerComponentSystem
  27. {
  28. public static void Add(this PlayerComponent self, Player player)
  29. {
  30. self.idPlayers.Add(player.Id, player);
  31. }
  32. public static Player Get(this PlayerComponent self, long id)
  33. {
  34. self.idPlayers.TryGetValue(id, out Player gamer);
  35. return gamer;
  36. }
  37. public static void Remove(this PlayerComponent self, long id)
  38. {
  39. self.idPlayers.Remove(id);
  40. //TODO: 删除ice战斗服里的player
  41. }
  42. public static Player[] GetAll(this PlayerComponent self)
  43. {
  44. return self.idPlayers.Values.ToArray();
  45. }
  46. //从所有scene的 Playerlist中找到某个player
  47. public static Player SearchAll(long id)
  48. {
  49. foreach(var component in PlayerComponent.PlayerComponentList)
  50. {
  51. var player = component.Get(id);
  52. if(player != null)
  53. {
  54. return player;
  55. }
  56. }
  57. return null;
  58. }
  59. }
  60. }