1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
-
- 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<uint, BattleObject> UnitList = new();
- public HashMap<uint, BattleObject>.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<UnitMgr>
- {
- protected override void Awake(UnitMgr self)
- {
- UnitMgr.Instance = self;
- self.RecycleUnits();
- }
- }
- [ObjectSystem]
- public class UnitMgrDestroySystem : DestroySystem<UnitMgr>
- {
- protected override void Destroy(UnitMgr self)
- {
- self.RecycleUnits();
- UnitMgr.Instance = null;
- }
- }
- }
|