//技能特效与位移 public void AttackEffect(EntityBase entity, int skillId) { //读取技能配置表 SkillCfg skillData = resSvc.GetSkillCfg(skillId); entity.curtSkillCfg = skillData; //判断是否忽略碰撞 if (!skillData.isCollide) { //忽略碰撞 Physics.IgnoreLayerCollision(9, 10); timerSvc.AddTimeTask((id) => { Physics.IgnoreLayerCollision(9, 10, false); }, skillData.skillTime); } if (skillData.isBreak == false) { //霸体状态 entity.entityState = EntityState.BtState; } if (entity.enitityType == EnitityType.Player) { //攻击和技能的智能方向锁定 if (entity.GetMoveDir() == Vector2.zero) { Vector2 dir = entity.CalcTargetDir(); //自动攻击最近怪物 if (dir != Vector2.zero) { entity.SetAtkDir(dir, false); } } else { entity.SetAtkDir(entity.GetMoveDir()); } } entity.SetAction(skillData.aniAction); //播放动画 entity.SetFx(skillData.fx, skillData.skillTime); //播放特效 List <int> skillMoveLst = skillData.skillMoveLst; //技能位移 long timeSum = 0; entity.SetSkillMove(true); entity.SetIsCtrl(false); for (int i = 0; i < skillMoveLst.Count; i++) { SkillMoveCfg skillMoveData = resSvc.GetSkillMoveCfg(skillMoveLst[i]); long delayTime = skillMoveData.delayTime; //延迟释放时间 float distance = skillMoveData.moveDis; //移动距离 long time = skillMoveData.moveTime; //消耗时间 float speed = distance / (time / 1000.0f); //计算 每秒速度 = 距离 / 时间 //计算延迟 //开始位移 timeSum += delayTime; int taskId_1 = timerSvc.AddTimeTask((id) => { entity.SetSkillMove(true, speed); entity.RemoveMoveTask(id); }, timeSum); entity.AddMoveTask(taskId_1); //计算延迟 //结束位移 timeSum += time; int taskId_2 = timerSvc.AddTimeTask((id) => { entity.SetSkillMove(true, 0); entity.RemoveMoveTask(id); }, timeSum); entity.AddMoveTask(taskId_2); } //等待技能释放完成回到Idle状态 entity.skillEndCb = timerSvc.AddTimeTask((taskID) => { entity.SetSkillMove(false); entity.SetIsCtrl(true); entity.Idle(); }, skillData.skillTime); }