NQXDEYOPZBO7AZJHBEBNMBR3QFE4OAQFK4FHOIGKD7TXE256X23AC
2ICHN37Z2OZ455ALKTMXTV5JOULQBN5UN46OM6JCHMF3CPNHFF3AC
HXTSBPAP75A7EC4RKWYQMVPPHPNZFPHUORBZWDHGEB6MPAGI7G7AC
A6K2SVTQ3JQ3TC3F44H3ERSX47TRQ6R5EJGIRJKFGKZG6I4HOATQC
N6YTMLNYZLR4BEDGYC7RJQ43KJ3XZFILZ6ODN26Z7RF3LZ6LVUOQC
VZRSH4U473FCZOP5EXURPXXN5J6F3ZLT435YY7A2JHLG2ZZB5KLQC
QZXURLSF73UL67TIXDHMVS7DCFZLQJAPJ6BAGRGXOHH46VMNKGPQC
6BA5NHNF3UWSL65KCWSXLRTPGYVS4N4NORDJ4FZTZ5SRRDPI4YZAC
M2C63XUU3TKYAUPPSPEFVF4CMBQMCVLZATANFWQW35MMYNRB2SEAC
NavMeshAgent _agent;
float _originalStoppingDistance;
float _desiredStoppingDistance;
bool _isFirstAdvance = true;
static State resetState = new(false, 0f, false);
if (unit == null) {
throw new ArgumentNullException("unit");
}
if (stoppingDistance < 0) {
throw new ArgumentException("Cannot be < 0", "stoppingDistance");
}
if (unit.TryGetComponent(out _agent) == false) {
throw new ArgumentException("Missing NavMeshAgent", "unit");
}
_desiredStoppingDistance = stoppingDistance;
_lastTargetPosition = target.position;
_moveAction = new(unit, _lastTargetPosition, stoppingDistance);
if (_isFirstAdvance) {
_originalStoppingDistance = _agent.stoppingDistance;
_agent.stoppingDistance = _desiredStoppingDistance;
_agent.isStopped = false;
if (_lastTargetPosition != _target.position) {
else {
if (_lastTargetPosition != _target.position) {
_lastTargetPosition = _target.position;
_agent.SetDestination(_lastTargetPosition);
}
}
bool isAdvanced = _agent.pathPending || _agent.remainingDistance > _agent.stoppingDistance;
float completionStatus = CompletionStatus();
return new State(isAdvanced, completionStatus, isAdvanced);
return _moveAction.Advance();
_agent.isStopped = true;
_agent.stoppingDistance = _originalStoppingDistance;
_agent.ResetPath();
_isFirstAdvance = true;
return resetState;
return _moveAction.Cancel();
readonly public struct State : IActionState
{
public bool IsAdvanced { get; }
public float CompletionStatus { get; }
public bool IsMoving { get; }
public State(bool isAdvanced, float completionStatus, bool isMoving) {
IsAdvanced = isAdvanced;
CompletionStatus = completionStatus;
IsMoving = isMoving;
}
}