| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 | using Animancer;using GameLogic.Combat.CombatTool;using UnityEngine;using UnityEngine.AI;namespace GameLogic.Combat.Hero.State{    public class CombatHeroFollowMoveState : CombatHeroStateBasic    {        protected Vector3 lasetTaregtPoint;        protected Vector3 lastMovePoint;        protected HeroPlayStateInfoBasic _transitionAsset;        public float defMoveSpeed;        public CombatHeroFollowMoveState(CombatHeroEntity combatHeroEntity) : base(combatHeroEntity)        {        }        public override bool IsUpdateLockTarget()        {            return false;        }        protected override void ProEnter()        {            lasetTaregtPoint = new Vector3(999999, 99999, 99999);            _transitionAsset = combatHeroEntity.combatHeroAnimtion.Play("run");            combatHeroEntity.CombatAIBasic.NavMeshAgent.updateRotation = false;            combatHeroEntity.CombatAIBasic.NavMeshAgent.isStopped = true;            combatHeroEntity.CombatAIBasic.NavMeshAgent.obstacleAvoidanceType =                ObstacleAvoidanceType.HighQualityObstacleAvoidance;            combatHeroEntity.CombatAIBasic.NavMeshAgent.avoidancePriority = 20;            defMoveSpeed = combatHeroEntity.CombatAIBasic.NavMeshAgent.speed;        }        protected override void ProExit()        {            combatHeroEntity.CombatAIBasic.NavMeshAgent.speed = defMoveSpeed;            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 = CombatController.currActiveCombat.CombatHeroController.GetFollowPos(combatHeroEntity);            Vector3 myPos = combatHeroEntity.dotPos;            float bl = Vector3.SqrMagnitude(lasetTaregtPoint - targetPos) / 1f;            combatHeroEntity.CombatAIBasic.NavMeshAgent.speed = bl * 2.5f + defMoveSpeed;            if (Vector3.SqrMagnitude(lasetTaregtPoint - targetPos) > 1)            {                SetNewPath(targetPos);            }            else            {                if (Vector3.SqrMagnitude(myPos - targetPos) < 0.1f)                {                    combatHeroEntity.CombatAIBasic.ChangeState(CombatHeroStateType.followIdle);                    return;                }            }            if (_transitionAsset != null)            {                float v = combatHeroEntity.CombatAIBasic.NavMeshAgent.velocity.sqrMagnitude;                float v2 = v / 36;                _transitionAsset.SetSpeed(Mathf.Clamp(v2, 0.2f, 1.5f));            }            if (!combatHeroEntity.CombatAIBasic.NavMeshAgent.isStopped)            {                Vector3 nextPos = myPos;                Vector3 p = nextPos - lastMovePoint;                lastMovePoint = myPos;                if (p.sqrMagnitude > 0.0001)                {                    combatHeroEntity.combatHeroGameObject.rotation = Quaternion.Lerp(                        combatHeroEntity.combatHeroGameObject.rotation, Quaternion.LookRotation(p.normalized), 0.5f);                }            }        }    }}
 |