riversong code showcase
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
using Cysharp.Threading.Tasks;
|
||||
using Unity.Mathematics;
|
||||
using UnityEngine;
|
||||
|
||||
namespace DanieleMarotta.RiversongCodeShowcase
|
||||
{
|
||||
public class FollowPathIntentExecutionLogic : IntentExecutionLogic
|
||||
{
|
||||
private ITileSpace _tileSpace;
|
||||
|
||||
private IAgentCommonLogic _agentCommonLogic;
|
||||
|
||||
public override UniTask InitializeAsync(IServiceLocator serviceLocator)
|
||||
{
|
||||
_tileSpace = serviceLocator.GetService<ITileSpace>();
|
||||
_agentCommonLogic = serviceLocator.GetService<IAgentCommonLogic>();
|
||||
|
||||
return UniTask.CompletedTask;
|
||||
}
|
||||
|
||||
public override IntentExecutionResult OnStartingIntent(Agent agent, in AgentIntent intent)
|
||||
{
|
||||
agent.PathIndex = 0;
|
||||
|
||||
return IntentExecutionResult.Success;
|
||||
}
|
||||
|
||||
public override IntentExecutionResult Execute(Agent agent, in AgentIntent intent)
|
||||
{
|
||||
ref var path = ref agent.GetPathRW();
|
||||
if (path.StepCount <= 1) return IntentExecutionResult.Success;
|
||||
|
||||
var nextTile = path.Steps[agent.PathIndex + 1];
|
||||
var targetPosition = (float3)_tileSpace.TileToWorld(nextTile);
|
||||
var targetReached = _agentCommonLogic.MoveAgent(agent, targetPosition, Time.deltaTime);
|
||||
|
||||
var lastStepReached = targetReached && ++agent.PathIndex >= path.StepCount - 1 - intent.StopBeforeGoalStepCount;
|
||||
return lastStepReached ? IntentExecutionResult.Success : IntentExecutionResult.InProgress;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user