/// <summary> /// 多点自动寻路 /// </summary> /// <param name="_targetPosList"></param> /// <param name="playerPos">目标点Player位置</param> /// <param name="playerRot">目标点player角度</param> /// <param name="camPos">目标点Camera位置</param> /// <param name="camRot">目标点Camera角度</param> /// <param name="time">运动时间</param> /// <param name="OnComplete">回调方法</param> public void MoveToDestination(List <Vector3> _targetPosList, Vector3 playerPos, Vector3 playerRot, Vector3 camPos, Vector3 camRot, float time, float fieldofView, Action OnComplete = null) { foreach (var pos in _targetPosList) { targetPosList.Add(pos); } //需要应用寻路系统 FirstViewControl.instance.SetPlayerState(PlayerControlState.aI); isXunLuIng = true; mainCamTrans.DOMoveY(1.6f, 0.7f); mainCamTrans.DOLocalRotate(Vector3.zero, 0.7f); DOTween.To(() => mainCamTrans.gameObject.GetComponent <Camera>().fieldOfView, x => mainCamTrans.gameObject.GetComponent <Camera>().fieldOfView = x, 60, 0.7f).OnComplete(() => { player_Nav.enabled = true; player_Nav.destination = targetPosList[0]; moveToAction = () => { FirstViewControl.instance.MoveToDestination(playerPos, playerRot, camPos, camRot, 0, 1f, fieldofView).OnComplete(() => { if (OnComplete != null) { OnComplete.Invoke(); } }); }; }); }
private void InitStateMachine() { blackboard = new StateBlackboard(); blackboard.Add <bool>(BlackboardKey.DamageFlag, false); blackboard.Add <bool>(BlackboardKey.RepeatDamageFlag, false); blackboard.Add <Transform>(BlackboardKey.Transform, transform); blackboard.Add <float>(BlackboardKey.RunRange, 3f); EnemyIdleState idleState = EnemyIdleState.Create(blackboard, animator, "Idle", 0); StateNode idleNode = new StateNode(idleState, new Condition(() => { return(true); })); SetAnimTriggerAction idleAction = new SetAnimTriggerAction(blackboard, animator, "Idle"); SetAnimTriggerAction runAction = new SetAnimTriggerAction(blackboard, animator, "Run"); TimerAction timerAction = new TimerAction(blackboard, 0.5f, 1.5f); SetRandomDestinationAction destinationAction = new SetRandomDestinationAction(blackboard, transform.position, 6f); MoveToDestinationAction moveToAction = new MoveToDestinationAction(blackboard, navAgent); SetSkillAction setSkillAction = new SetSkillAction(blackboard, skillController); LookAtTargetAction lookAtAction = new LookAtTargetAction(blackboard, transform); SetAnimTriggerAction attackAction = new SetAnimTriggerAction(blackboard, animator, BlackboardKey.AnimTrigger, true); RangedAttackState attackState = new RangedAttackState(blackboard, idleAction, timerAction, destinationAction, runAction, moveToAction, setSkillAction, lookAtAction, attackAction, 300); StateNode attackNode = new StateNode(attackState, new Condition(() => target != null)); DamageState damageState = DamageState.Create(blackboard, animator, "Damage", 500); StateNode damageNode = new StateNode(damageState, new Condition(() => { return(blackboard.Get <bool>(BlackboardKey.DamageFlag)); })); DeathState deathState = DeathState.Create(blackboard, animator, "Death", int.MaxValue); StateNode deathNode = new StateNode(deathState, new Condition(() => { return(!self.IsAlive); })); List <StateNode> nodes = new List <StateNode>(); nodes.Add(idleNode); nodes.Add(attackNode); nodes.Add(damageNode); nodes.Add(deathNode); stateMachine = new StateMachine(blackboard, nodes, idleState); }
/// <summary> /// 外调方法 /// </summary> /// <param name="room">房间编号</param> /// <param name="_targetPos">自动寻路目标点</param> /// <param name="playerPos">目标点Player位置</param> /// <param name="playerRot">目标点player角度</param> /// <param name="camPos">目标点Camera位置</param> /// <param name="camRot">目标点Camera角度</param> /// <param name="time">运动时间</param> /// <param name="OnComplete">回调方法</param> public void MoveToDestination(Room room, Vector3 _targetPos, Vector3 playerPos, Vector3 playerRot, Vector3 camPos, Vector3 camRot, float time, float fieldofView, Action OnComplete = null) { targetPosList.Add(_targetPos); if (room == curRoom) { //不需要应用寻路系统 FirstViewControl.instance.SetPlayerState(PlayerControlState.anim); FirstViewControl.instance.MoveToDestination(playerPos, playerRot, camPos, camRot, 0, time, 60); StartCoroutine(Delay(time, OnComplete)); } else { //需要应用寻路系统 FirstViewControl.instance.SetPlayerState(PlayerControlState.aI); isXunLuIng = true; mainCamTrans.DOMoveY(1.6f, 0.7f); mainCamTrans.DOLocalRotate(Vector3.zero, 0.7f); DOTween.To(() => mainCamTrans.gameObject.GetComponent <Camera>().fieldOfView, x => mainCamTrans.gameObject.GetComponent <Camera>().fieldOfView = x, 60, 0.7f).OnComplete(() => { player_Nav.enabled = true; player_Nav.destination = targetPosList[0]; moveToAction = () => { FirstViewControl.instance.MoveToDestination(playerPos, playerRot, camPos, camRot, 0, 1f, fieldofView).OnComplete(() => { if (OnComplete != null) { OnComplete.Invoke(); } }); }; }); } }