using System.Collections.Generic; using System.Linq; namespace ET.Server { public class SessionPlayerComponentAwakeSystem: AwakeSystem { protected override void Awake(SessionPlayerComponent self) { self?.Init(); } } public class SessionPlayerComponentDestroySystem: DestroySystem { protected override void Destroy(SessionPlayerComponent self) { // 发送断线消息 Log.Warning($"玩家断线了, plyerId={self.PlayerId}"); } } [FriendOf(typeof (SessionPlayerComponent))] public static class SessionPlayerComponentSystem { /// /// 初始化数据 /// /// public static void Init(this SessionPlayerComponent self) { self.PlayerList = new List(); self.PlayerId = 0; } /// /// 是否存在 /// /// /// /// public static bool IsExist(this SessionPlayerComponent self, long playerId) { return self.PlayerList.Any(info => info != null && info.Id == playerId); } /// /// 获取 /// /// /// /// public static PlayerInfo Get(this SessionPlayerComponent self, long playerId) { return self.PlayerList.FirstOrDefault(info => info != null && info.Id == playerId); } /// /// 添加 /// /// /// public static void Add(this SessionPlayerComponent self, PlayerInfo info) { if (info != null) { self.PlayerList.Add(info); } } /// /// 获取玩家实体 /// /// /// public static WNPlayer GetMyPlayer(this SessionPlayerComponent self) { return self.DomainScene().GetComponent().Get(self.PlayerId); } } }