Exemplo n.º 1
0
            public void Execute(Entity entity, int index, ref NavAgent agent, ref AgentPathData pathData)
            {
                agent.DtCrowdAgent = AiCrowd.GetAgent(agent.CrowdIndex);

                if (UpdateActive(ref agent))
                {
                    return;
                }

                if (!agent.Active)
                {
                    return;
                }

                if (Debug)
                {
                    ReadOnlyAgents.Remove(agent.CrowdIndex);
                    NavAgentDebug debug = new NavAgentDebug();
                    debug.NavAgent = agent;
                    debug.PathData = pathData;
                    ReadOnlyAgents.TryAdd(agent.CrowdIndex, debug);
                }



                DynamicBuffer <AgentPathBuffer> pathBuffer = PathLookup[entity];

                pathData.DistanceToDestination = math.distance(agent.Destination, agent.DtCrowdAgent.Position);
                pathData.UsingPath             = pathData.DistanceToDestination > 20f;

                if (agent.SetDestination)
                {
                    agent.SetDestination = false;
                    if (pathData.UsingPath)
                    {
                        bool success = Query.TryFindPath(NavQuerySettings, agent.DtCrowdAgent.Position, agent.Destination, (float3 *)Path.GetUnsafePtr(), out int pathLength);
                        if (success && pathLength > 0)
                        {
                            pathData.CurrentIndex = 0;
                            PathHandler.CopyToBuffer(Path, pathLength, pathBuffer);
                            pathData.PathLength        = pathLength;
                            pathData.LastQueryResult   = 1;
                            agent.SetDestinationFailed = false;
                        }
                        else
                        {
                            agent.SetDestinationFailed = true;
                            pathData.LastQueryResult   = 0;
                        }
                    }
                    else
                    {
                        agent.SetDestinationFailed = false;
                    }
                }

                PathHandler pathHandler = PathHandler.CreateFrom(pathData, pathBuffer);

                pathData.HasPath = pathHandler.HasPath;
                if (pathData.UsingPath && !pathData.HasPath)
                {
                    return;
                }

                if (pathData.DistanceToDestination <= 0.1f)
                {
                    return;
                }

                float3 target = agent.Destination;

                if (pathData.UsingPath)
                {
                    pathHandler.UpdatePathIndex(agent.DtCrowdAgent.Position, 0.5f);
                    pathData.CurrentIndex = pathHandler.CurrentIndex;
                    target = pathHandler.CurrentWaypoint;
                    pathData.CurrentWaypoint    = target;
                    pathData.DistanceToWaypoint = math.distance(target, agent.DtCrowdAgent.Position);
                }

                AiCrowd.RequestMoveAgent(agent.CrowdIndex, target);


                if (agent.UpdateParams == 1)
                {
                    agent.UpdateParams = 0;
                    AiCrowd.SetAgentParams(agent.CrowdIndex, agent.DtAgentParams);
                    agent.DtAgentParams = AiCrowd.GetAgentParams(agent.CrowdIndex);
                }
            }
Exemplo n.º 2
0
 public bool TryGetAgent(int crowdIndex, out NavAgentDebug debug)
 {
     return(ReadOnlyAgents.TryGetValue(crowdIndex, out debug));
 }