123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- using Animancer;
- using Core.Event.Event;
- using Fort23.Core;
- using OfficeOpenXml.FormulaParsing.Excel.Functions.Logical;
- using UnityEngine;
- using UnityEngine.AI;
- namespace GameLogic.Combat.Hero.State
- {
- public class CombatHeroMoveState : CombatHeroStateBasic
- {
- protected Vector3 lasetTaregtPoint;
- protected Vector3 lastMovePoint;
- protected HeroPlayStateInfoBasic _transitionAsset;
- protected bool isStop;
- public CombatHeroMoveState(CombatHeroEntity combatHeroEntity) : base(combatHeroEntity)
- {
- }
- public override bool IsUpdateLockTarget()
- {
- return false;
- }
- protected override void ProEnter()
- {
- EventManager.Instance.AddEventListener(CustomEventType.RefreshFull,RefreshFull);
- combatHeroEntity.CombatAIBasic.NavMeshAgent.Warp(combatHeroEntity.dotPos);
- Start();
- }
- protected void Start()
- {
- lasetTaregtPoint = new Vector3(999999, 99999, 99999);
- _transitionAsset = combatHeroEntity.combatHeroAnimtion.Play("run");
- combatHeroEntity.CombatAIBasic.NavMeshAgent.updateRotation = false;
- if ( combatHeroEntity.CombatAIBasic.NavMeshAgent.isOnNavMesh == false)
- {
- Debug.LogError("对象错误");
- }
- combatHeroEntity.CombatAIBasic.NavMeshAgent.isStopped = true;
- combatHeroEntity.CombatAIBasic.NavMeshAgent.obstacleAvoidanceType =
- ObstacleAvoidanceType.HighQualityObstacleAvoidance;
- combatHeroEntity.CombatAIBasic.NavMeshAgent.avoidancePriority = 40;
- }
- protected void RefreshFull(IEventData ieEventData)
- {
- RefreshFullEventData data = (RefreshFullEventData)ieEventData;
- if (data.isFullShow&&!isStop)
- {
- isStop = true;
- combatHeroEntity.CombatAIBasic.NavMeshAgent.isStopped = true;
- combatHeroEntity.CombatAIBasic.NavMeshAgent.velocity = Vector3.zero;
- combatHeroEntity.CombatAIBasic.NavMeshAgent.avoidancePriority = 50;
- }
- else if(isStop)
- {
- Start();
- isStop = false;
- }
- }
- protected override void ProExit()
- {
- EventManager.Instance.RemoveEventListener(CustomEventType.RefreshFull,RefreshFull);
- combatHeroEntity.CombatAIBasic.NavMeshAgent.isStopped = true;
- combatHeroEntity.CombatAIBasic.NavMeshAgent.velocity = Vector3.zero;
- combatHeroEntity.CombatAIBasic.NavMeshAgent.avoidancePriority = 50;
- // combatHeroEntity.CombatAIBasic.NavMeshAgent.acceleration = 0;
- }
- protected void SetNewPath(Vector3 taregtPos)
- {
- lastMovePoint = combatHeroEntity.dotPos;
- lasetTaregtPoint = taregtPos;
- combatHeroEntity.CombatAIBasic.NavMeshAgent.isStopped = false;
- // combatHeroEntity.CombatAIBasic.NavMeshAgent.acceleration = 8;
- combatHeroEntity.CombatAIBasic.NavMeshAgent.SetDestination(taregtPos);
- }
- protected override void ProUpdate(float t)
- {
-
- if (combatHeroEntity.CombatAIBasic.currFocusTarget == null)
- {
- combatHeroEntity.CombatAIBasic.ChangeState(CombatHeroStateType.idle);
- return;
- }
- Vector3 targetPos = combatHeroEntity.CombatAIBasic.currFocusTarget.dotPos;
- Vector3 myPos = combatHeroEntity.dotPos;
-
- float dis = combatHeroEntity.CurrCombatHeroInfo.maxDisTo;
- if (combatHeroEntity.CombatAIBasic.currFocusTarget is BannerHero)
- {
- dis = 1;
- }
-
- if (Vector3.SqrMagnitude(targetPos - myPos) >
- dis)
- {
- if (Vector3.SqrMagnitude(lasetTaregtPoint - targetPos) > 1)
- {
- SetNewPath(targetPos);
- }
- }
- else
- {
- combatHeroEntity.CombatAIBasic.ChangeState(CombatHeroStateType.idle);
- return;
- }
- if (_transitionAsset != null)
- {
- float v = combatHeroEntity.CombatAIBasic.NavMeshAgent.velocity.sqrMagnitude;
-
- float v2 = v / (combatHeroEntity.IsEnemy?9:36);
- _transitionAsset.SetSpeed(Mathf.Clamp(v2, 0.2f, 1.5f));
- }
-
- if ( combatHeroEntity.CombatAIBasic.NavMeshAgent.isOnNavMesh&&!combatHeroEntity.CombatAIBasic.NavMeshAgent.isStopped)
- {
- Vector3 nextPos = myPos;
- Vector3 p = nextPos - lastMovePoint;
- lastMovePoint = myPos;
- if (p.sqrMagnitude > 0.00001)
- {
- combatHeroEntity.combatHeroGameObject.rotation = Quaternion.Lerp(
- combatHeroEntity.combatHeroGameObject.rotation, Quaternion.LookRotation(p.normalized), 0.5f);
- }
- }
- }
- }
- }
|