using LTGame; using Gameplay.Unit; namespace Gameplay.Bullet { using UnityEngine; public class BulletStateUnitLockFly : BaseBulletState { private Vector3 _targetPos; private GameUnit _targetUnit; private float _flySpeed; public BulletStateUnitLockFly(ViewBullet owner) : base(owner, EBulletState.UnitLockFly) { } protected override void _OnEnter(NBaseState exitState, object param) { base._OnEnter(exitState, param); _targetUnit = owner.lockUnit; _targetPos = _targetUnit.transData.pos; _flySpeed = owner.rawConfig.FlySpeed; } protected override void _OnRunning() { base._OnRunning(); var currentPos = owner.rootObj.transform.position; if (!_targetUnit.statusData.isDead) { // 更新位置 _targetPos = _targetUnit.transData.pos; } var targetPos = _targetPos; var toTargetPos = targetPos - currentPos; var toTargetPosLength = toTargetPos.magnitude; var toTargetPosDir = toTargetPos.normalized; var moveDistance = _flySpeed * Time.deltaTime; if (moveDistance >= toTargetPosLength) { owner.rootObj.transform.position = targetPos; isFinished = true; switch (owner.rawConfig.BulletType) { case EBulletType.UNIT_LOCK: nextState = EBulletState.DamageUnit; break; case EBulletType.UNIT_LOCK_BOOM: nextState = EBulletState.PosBoom; break; default: DebugUtil.LogError("[BulletStateUnitLockFly: _OnRunning] 未支持的子弹类型: " + owner.rawConfig.BulletType); nextState = EBulletState.Destroy; break; } } else { var newPos = currentPos + toTargetPosDir * moveDistance; owner.rootObj.transform.position = newPos; } } } }