public static DUnit Get(this DUnitComponent self, long id) { DUnit unit; self.idUnits.TryGetValue(id, out unit); return(unit); }
public static void Remove(this DUnitComponent self, long id) { DUnit unit; self.idUnits.TryGetValue(id, out unit); self.idUnits.Remove(id); unit?.Dispose(); }
public static void UpdateTriggers(this Skill self) { ListComponent <long> deleteList = ListComponent <long> .Create(); DUnitComponent dUnitComponent = self.Domain.GetComponent <DUnitComponent>(); // 刷新MonitorList for (int i = 0; i < self.MonitorList.List.Count; i++) { DUnit unit = dUnitComponent.Get(self.MonitorList.List[i]); if (unit == null) { deleteList.List.Add(unit.Id); continue; } if (unit.GetComponent <UnitStateComponent>().UnitState == (int)UnitState.Death) { deleteList.List.Add(unit.Id); } } for (int i = 0; i < deleteList.List.Count; i++) { self.MonitorList.List.Remove(deleteList.List[i]); } deleteList.List.Clear(); // 刷新MonitorList for (int i = 0; i < self.DamageList.List.Count; i++) { DUnit unit = dUnitComponent.Get(self.DamageList.List[i]); if (unit == null) { deleteList.List.Add(unit.Id); continue; } if (unit.GetComponent <UnitStateComponent>().UnitState == (int)UnitState.Death) { deleteList.List.Add(unit.Id); } } for (int i = 0; i < deleteList.List.Count; i++) { self.DamageList.List.Remove(deleteList.List[i]); } deleteList.List.Clear(); }
public static void UpdateTarget(this Skill self) { if (self.TargetId == 0) { return; } DUnitComponent dUnitComponent = self.Domain.GetComponent <DUnitComponent>(); DUnit unit = dUnitComponent.Get(self.TargetId); if (unit == null) { self.SetSkillTarget(0); return; } }
public static DUnit GetMonitorTarget(this Skill self, SkillTargetCondition condition) { self.UpdateTriggers(); DUnitComponent dUnitComponent = self.Domain.GetComponent <DUnitComponent>(); if (condition == SkillTargetCondition.MaxDistance) { Vector3 srcpos = self.Self.Position; float sqrdis = 0; DUnit selunit = null; for (int i = 0; i < self.MonitorList.List.Count; i++) { DUnit u = dUnitComponent.Get(self.MonitorList.List[i]); float tmpdis = (u.Position - srcpos).sqrMagnitude; if (tmpdis > sqrdis) { selunit = u; } } return(selunit); } else { Vector3 srcpos = self.Self.Position; float sqrdis = float.MaxValue; DUnit selunit = null; for (int i = 0; i < self.MonitorList.List.Count; i++) { DUnit u = dUnitComponent.Get(self.MonitorList.List[i]); float tmpdis = (u.Position - srcpos).sqrMagnitude; if (tmpdis < sqrdis) { selunit = u; } } return(selunit); } }
public static DUnit[] GetAll(this DUnitComponent self) { return(self.idUnits.Values.ToArray()); }
public static void RemoveNoDispose(this DUnitComponent self, long id) { self.idUnits.Remove(id); }
public static void Add(this DUnitComponent self, DUnit unit) { self.idUnits.Add(unit.Id, unit); unit.Parent = self; }