public IBufferValue[] ActionHandle(BuffHandlerVar buffHandlerVar) { Buff_RangeDetection buff_RangeDetection = (Buff_RangeDetection)buffHandlerVar.data; if (!buffHandlerVar.GetBufferValue(out BufferValue_Pos bufferValue_Pos)) { return(null); } //主要目的是返回多个群体目标对象 BufferValue_TargetUnits bufferValue_TargetUnits = new BufferValue_TargetUnits(); PolyshapeQueryCallback polyshapeQueryCallback = new PolyshapeQueryCallback(); AABB ab = new AABB(); switch (buff_RangeDetection.shapeType) { case Buff_RangeDetection.CollisionShape.Box: //根据传入进来的方向和位置计算做范围检测的区域 if (!buffHandlerVar.GetBufferValue(out BufferValue_Dir bufferValue_Dir)) { Log.Error("Box检测没有收到方向 " + buffHandlerVar.skillId); return(null); } Vector2 pos = bufferValue_Pos.aimPos.ToVector2(); var transform = new Transform(in pos, bufferValue_Dir.dir.ToRotation2D().Angle); var Vertices = new Vector2[4]; float hx = buff_RangeDetection.shapeValue.x; float hy = buff_RangeDetection.shapeValue.y; Vertices[0].Set(-hx, -hy); Vertices[1].Set(hx, -hy); Vertices[2].Set(hx, hy); Vertices[3].Set(-hx, hy); for (var i = 0; i < 4; ++i) { Vertices[i] = MathUtils.Mul(transform, Vertices[i]); } ab.UpperBound = ab.LowerBound = Vertices[0]; for (var i = 1; i < 4; ++i) { var v = Vertices[i]; ab.LowerBound = Vector2.Min(ab.LowerBound, v); ab.UpperBound = Vector2.Max(ab.UpperBound, v); } var r = new Vector2(Settings.PolygonRadius, Settings.PolygonRadius); ab.LowerBound -= r; ab.UpperBound += r; break; case Buff_RangeDetection.CollisionShape.Circle: pos = bufferValue_Pos.aimPos.ToVector2(); transform = new Transform(in pos, 0); var p = MathUtils.Mul(transform.Rotation, transform.Position); float raidus = buff_RangeDetection.shapeValue.x; ab.LowerBound.Set(p.X - raidus, p.Y - raidus); ab.UpperBound.Set(p.X + raidus, p.Y + raidus); break; } //Log.Debug(ab.LowerBound.ToString() + ab.UpperBound.ToString()); PhysicWorldComponent.Instance.world.QueryAABB(polyshapeQueryCallback, ab); if (polyshapeQueryCallback.units == null || polyshapeQueryCallback.units.Count == 0) { Log.Debug("没有检测到任何单位"); return(null); } for (int i = polyshapeQueryCallback.units.Count - 1; i >= 0; i--) { //默认层(一般是特效,墙壁等) if (polyshapeQueryCallback.units[i].UnitData.groupIndex == GroupIndex.Default || polyshapeQueryCallback.units[i].UnitData.unitLayer == UnitLayer.Default) { polyshapeQueryCallback.units.RemoveAt(i); continue; } if (buff_RangeDetection.FindFriend) { if (polyshapeQueryCallback.units[i].UnitData.groupIndex != buffHandlerVar.source.UnitData.groupIndex) { polyshapeQueryCallback.units.RemoveAt(i); continue; } } else { if (polyshapeQueryCallback.units[i].UnitData.groupIndex == buffHandlerVar.source.UnitData.groupIndex) { polyshapeQueryCallback.units.RemoveAt(i); continue; } } //高度区域检测 if (Math.Abs((bufferValue_Pos.aimPos.y + buff_RangeDetection.halfHeight) - (polyshapeQueryCallback.units[i].Position.y + polyshapeQueryCallback.units[i].OffsetY)) > (buff_RangeDetection.halfHeight + polyshapeQueryCallback.units[i].HalfHeight)) { polyshapeQueryCallback.units.RemoveAt(i); Log.Debug("目前高度不在检测的范围内!"); continue; } else { Log.Debug("目前高度在检测的范围内!"); } } //拿到了所有检测到的Unit bufferValue_TargetUnits.targets = polyshapeQueryCallback.units.ToArray(); // Log.Debug("范围检测到了 " + bufferValue_TargetUnits.targets.Length+ " 个目标"); return(new IBufferValue[] { bufferValue_TargetUnits }); }
public static async ETTask <bool> Execute(this Pipeline_WaitForInput pipeline_WaitForInput, SkillHelper.ExecuteSkillParams skillParams) { await ETTask.CompletedTask; #if !SERVER switch (pipeline_WaitForInput.inputType) { //等待用户输入,可能有正确输入/取消/输入超时三种情况 case InputType.Tar: CommandInput_UseSkill commandInput_UseSkill = new CommandInput_UseSkill(); if (skillParams.source != UnitComponent.Instance.MyUnit) { //非玩家角色使用技能直接跳过等待输入步骤. //非玩家角色使用技能的输入来自于其他地方(服务器下发) return(true); } if (SkillHelper.tempData.ContainsKey((skillParams.source, pipeline_WaitForInput.pipelineSignal))) { //可能还存在着之前使用技能时找到的数据. 所以这里清理掉它 SkillHelper.tempData.Remove((skillParams.source, pipeline_WaitForInput.pipelineSignal)); } BufferValue_TargetUnits bufferValue_TargetUnits = new BufferValue_TargetUnits(); bufferValue_TargetUnits.targets = new Unit[1]; if (UnitComponent.Instance.MyUnit.GetComponent <InputComponent>().GetInputTarget(out bufferValue_TargetUnits.targets[0], pipeline_WaitForInput.findFriend, skillParams.source.UnitData.groupIndex)) { UnityEngine.Vector3 _forward1 = bufferValue_TargetUnits.targets[0].Position - skillParams.source.Position; skillParams.source.Rotation = UnityEngine.Quaternion.LookRotation(new UnityEngine.Vector3(_forward1.x, 0, _forward1.z), UnityEngine.Vector3.up); commandInput_UseSkill.skillId = skillParams.skillId; commandInput_UseSkill.pipelineSignal = pipeline_WaitForInput.pipelineSignal; commandInput_UseSkill.bufferValue = bufferValue_TargetUnits; UnitComponent.Instance.MyUnit.GetComponent <CommandComponent>().CollectCommandInput(commandInput_UseSkill); } else { Log.Debug("找不到目标! 技能终止!"); return(false); } break; case InputType.Dir: commandInput_UseSkill = new CommandInput_UseSkill(); if (skillParams.source != UnitComponent.Instance.MyUnit) { //非玩家角色使用技能直接跳过等待输入步骤. //非玩家角色使用技能的输入来自于其他地方(服务器下发) return(true); } if (SkillHelper.tempData.ContainsKey((skillParams.source, pipeline_WaitForInput.pipelineSignal))) { //可能还存在着之前使用技能时找到的数据. 所以这里清理掉它 SkillHelper.tempData.Remove((skillParams.source, pipeline_WaitForInput.pipelineSignal)); } //直接智能施法模式 BufferValue_Dir bufferValue_Dir = new BufferValue_Dir(); bufferValue_Dir.dir = UnitComponent.Instance.MyUnit.GetComponent <InputComponent>().GetInputDir(); //直接改变使用技能时角色的转向 skillParams.source.Rotation = UnityEngine.Quaternion.LookRotation(bufferValue_Dir.dir, UnityEngine.Vector3.up); commandInput_UseSkill.skillId = skillParams.skillId; commandInput_UseSkill.pipelineSignal = pipeline_WaitForInput.pipelineSignal; commandInput_UseSkill.bufferValue = bufferValue_Dir; UnitComponent.Instance.MyUnit.GetComponent <CommandComponent>().CollectCommandInput(commandInput_UseSkill); break; case InputType.Pos: commandInput_UseSkill = new CommandInput_UseSkill(); if (skillParams.source != UnitComponent.Instance.MyUnit) { //非玩家角色使用技能直接跳过等待输入步骤. //非玩家角色使用技能的输入来自于其他地方(服务器下发) return(true); } if (SkillHelper.tempData.ContainsKey((skillParams.source, pipeline_WaitForInput.pipelineSignal))) { //可能还存在着之前使用技能时找到的数据. 所以这里清理掉它 SkillHelper.tempData.Remove((skillParams.source, pipeline_WaitForInput.pipelineSignal)); } BufferValue_Pos bufferValue_Pos = new BufferValue_Pos(); if (!UnitComponent.Instance.MyUnit.GetComponent <InputComponent>().GetInputPos(out bufferValue_Pos.aimPos)) { return(false); } //直接改变使用技能时角色的转向 UnityEngine.Vector3 forward = bufferValue_Pos.aimPos - skillParams.source.Position; skillParams.source.Rotation = UnityEngine.Quaternion.LookRotation(new UnityEngine.Vector3(forward.x, 0, forward.z), UnityEngine.Vector3.up); commandInput_UseSkill.skillId = skillParams.skillId; commandInput_UseSkill.pipelineSignal = pipeline_WaitForInput.pipelineSignal; commandInput_UseSkill.bufferValue = bufferValue_Pos; UnitComponent.Instance.MyUnit.GetComponent <CommandComponent>().CollectCommandInput(commandInput_UseSkill); break; case InputType.Charge: break; case InputType.Spell: break; case InputType.ContinualSpell: SpellForTime(pipeline_WaitForInput.value, skillParams).Coroutine(); break; } #else switch (pipeline_WaitForInput.inputType) { case InputType.Tar: break; case InputType.Dir: break; case InputType.Pos: break; case InputType.Charge: break; case InputType.Spell: break; case InputType.ContinualSpell: SpellForTime(pipeline_WaitForInput.value, skillParams).Coroutine(); break; } #endif return(true); }