GamePlayerComponentSystem.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using System.Linq;
  2. namespace ET.Server
  3. {
  4. public class PlayerComponentAwakeSystem: AwakeSystem<GamePlayerComponent>
  5. {
  6. /// <summary>
  7. /// 游戏服在线玩家组件创建
  8. /// </summary>
  9. /// <param name="self"></param>
  10. protected override void Awake(GamePlayerComponent self)
  11. {
  12. }
  13. }
  14. public class PlayerComponentDestroySystem: DestroySystem<GamePlayerComponent>
  15. {
  16. /// <summary>
  17. /// 游戏服在线玩家组件销毁
  18. /// </summary>
  19. /// <param name="self"></param>
  20. protected override void Destroy(GamePlayerComponent self)
  21. {
  22. }
  23. }
  24. [FriendOf(typeof (GamePlayerComponent))]
  25. public static class GamePlayerComponentSystem
  26. {
  27. public static void Add(this GamePlayerComponent self, WNPlayer player)
  28. {
  29. if (!self.idPlayers.ContainsKey(player.Id))
  30. {
  31. self.idPlayers.Add(player.Id, player);
  32. }
  33. }
  34. public static WNPlayer Get(this GamePlayerComponent self, long id)
  35. {
  36. self.idPlayers.TryGetValue(id, out WNPlayer gamer);
  37. return gamer;
  38. }
  39. public static void Remove(this GamePlayerComponent self, long id)
  40. {
  41. self.idPlayers.Remove(id);
  42. }
  43. public static WNPlayer[] GetAll(this GamePlayerComponent self)
  44. {
  45. return self.idPlayers.Values.ToArray();
  46. }
  47. }
  48. }