using CommonLang; namespace ET.Client { [ComponentOf(typeof(Scene))] public class UnitMgr : Entity, IAwake, IDestroy { public static UnitMgr Instance; public BattleActor Actor { get; set; } public uint ActorId { get { return Actor.Id; } } private HashMap UnitList = new(); public HashMap.ValueCollection AllUnits { get { return UnitList.Values; } } public BattleObject GetUnit(uint id) { return UnitList.ContainsKey(id) ? UnitList[id] : null; } public void PutUnit(uint id, BattleObject obj) { UnitList[id] = obj; } public void RemoveUnit(uint id) { if (UnitList.ContainsKey(id)) { UnitList.Remove(id); } } public void RecycleUnits() { foreach (var kp in UnitList) { kp.Value.OnSleep(); } UnitList.Clear(); } } [ObjectSystem] public class UnitMgrAwakeSystem : AwakeSystem { protected override void Awake(UnitMgr self) { UnitMgr.Instance = self; self.RecycleUnits(); } } [ObjectSystem] public class UnitMgrDestroySystem : DestroySystem { protected override void Destroy(UnitMgr self) { self.RecycleUnits(); UnitMgr.Instance = null; } } }