public static void MoveTo(this MoveAndSpellComponent self, Unit unit, Vector3 point) { if (self.Skill == null || (self.Point - point).sqrMagnitude > self.Skill.SkillConfig.PreviewRange[0] / 2f) { self.Point = point; #if !SERVER unit.MoveToAsync(point).Coroutine(); #else unit.FindPathMoveToAsync(point).Coroutine(); #endif } }
/// <summary> /// 释放对目标技能 /// </summary> /// <param name="self"></param> /// <param name="spellSkill"></param> /// <param name="targetEntity"></param> public static void SpellWithTarget(this MoveAndSpellComponent self, SkillAbility spellSkill, CombatUnitComponent targetEntity) { if (!spellSkill.CanUse()) { return; } if (self.Skill != null && self.Skill != spellSkill)//换新技能释放了 { self.Skill = null; self.Target = null; TimerComponent.Instance.Remove(ref self.TimerId); return; } var unit = self.GetParent <CombatUnitComponent>().unit; var nowpos = unit.Position; var point = targetEntity.unit.Position; if (Vector2.Distance(new Vector2(nowpos.x, nowpos.z), new Vector2(point.x, point.z)) > spellSkill.SkillConfig.PreviewRange[0]) { self.MoveTo(unit, point); if (self.Skill == null) { self.Skill = spellSkill; self.Target = targetEntity; self.TimerId = TimerComponent.Instance.NewFrameTimer(TimerType.MoveAndSpellSkill, self); } return; } if (self.Skill != null) { self.Skill = null; self.Target = null; TimerComponent.Instance.Remove(ref self.TimerId); unit.Stop(0); } #if SERVER //单机去掉 self.Parent.GetComponent <SpellComponent>().SpellWithTarget(spellSkill, targetEntity); #else spellSkill.UseSkill(Vector3.zero, targetEntity.Id); #endif }