NLDClient-yudde/ProjectNLD/Assets/Code/Scripts/Gameplay/Bullet/State/BulletStateLockPosFly.cs

53 lines
1.4 KiB
C#

using LTGame;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Gameplay.Bullet
{
using Gameplay.Level;
using UnityEngine;
public class BulletStateLockPosFly : BaseBulletState
{
private Vector3 _startPos;
private Vector3 _endPos;
private float _flyTime;
public BulletStateLockPosFly(ViewBullet owner): base(owner, EBulletState.LockPosFly)
{
}
protected override void _OnEnter(NBaseState exitState, object param)
{
base._OnEnter(exitState, param);
_startPos = owner.rootObj.transform.position;
_endPos = owner.map.TGSCellIndex2WorldPosition(owner.targetCellIndex);
var flySpeed = owner.configData.FlySpeed;
_flyTime = Vector3.Distance(_startPos, _endPos) / flySpeed;
}
protected override void _OnRunning()
{
base._OnRunning();
var progress = Mathf.Clamp01(passTime / _flyTime);
var pos = Vector3.Lerp(_startPos, _endPos, progress);
owner.rootObj.transform.position = pos;
if (progress >= 1)
{
owner.rootObj.transform.position = _endPos;
isFinished = true;
nextState = EBulletState.PosBoom;
}
}
}
}