123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- using System.Linq;
- namespace ET.Server
- {
- public class PlayerComponentAwakeSystem : AwakeSystem<PlayerComponent>
- {
- protected override void Awake(PlayerComponent self)
- {
- PlayerComponent.PlayerComponentList.Add(self);
- }
- }
- public class PlayerComponentDestroySystem : DestroySystem<PlayerComponent>
- {
- protected override void Destroy(PlayerComponent self)
- {
- foreach(var player in PlayerComponent.PlayerComponentList)
- {
- if(player == self)
- {
- PlayerComponent.PlayerComponentList.Remove(player);
- return;
- }
- }
- }
- }
- [FriendOf(typeof(PlayerComponent))]
- public static class PlayerComponentSystem
- {
- public static void Add(this PlayerComponent self, Player player)
- {
- self.idPlayers.Add(player.Id, player);
- }
- public static Player Get(this PlayerComponent self, long id)
- {
- self.idPlayers.TryGetValue(id, out Player gamer);
- return gamer;
- }
- public static void Remove(this PlayerComponent self, long id)
- {
- self.idPlayers.Remove(id);
- //TODO: 删除ice战斗服里的player
- }
- public static Player[] GetAll(this PlayerComponent self)
- {
- return self.idPlayers.Values.ToArray();
- }
- //从所有scene的 Playerlist中找到某个player
- public static Player SearchAll(long id)
- {
- foreach(var component in PlayerComponent.PlayerComponentList)
- {
- var player = component.Get(id);
- if(player != null)
- {
- return player;
- }
- }
- return null;
- }
- }
- }
|