Esempio n. 1
0
        public void Execute()
        {
            // Create Path
            //NativeList<int> pathNodes = new NativeList<int>(Allocator.Temp);
            if (parents[endIndex] == -1)
            {
                Debug.Log("Path not found");
                AgentData ad = agentComponentData[entity];
                ad.pathIndex = 0;
                ad.hasPath   = false;
                agentComponentData[entity] = ad;
            }
            else
            {
                // Path found
                pathBuffer[entity].Clear();
                int currentIdx = endIndex;
                //pathNodes.Add(currentIdx);
                while (parents[currentIdx] != -1)
                {
                    //pathNodes.Add(parents[currentIdx]);


                    Vector3 v1 = Vector3.zero;
                    Vector3 v2 = Vector3.zero;

                    for (int i = nodes[currentIdx].neighboursIndex; i < nodes[currentIdx].neighboursIndex + nodes[currentIdx].neighboursSize; i++)
                    {
                        if (neighbors[i].nodeIndex == parents[currentIdx])
                        {
                            v1 = neighbors[i].portal.v1;
                            v2 = neighbors[i].portal.v2;
                        }
                    }

                    pathBuffer[entity].Add(new PathBuffer {
                        v1 = v1, v2 = v2, nodeIndex = currentIdx
                    });
                    currentIdx = parents[currentIdx];
                }

                AgentData ad = agentComponentData[entity];
                ad.pathIndex               = pathBuffer[entity].Length - 1;
                ad.destination             = ad.getProyectedWayPoint(pathBuffer[entity][ad.pathIndex].v1, pathBuffer[entity][ad.pathIndex].v2);
                ad.hasPath                 = true;
                agentComponentData[entity] = ad;
            }
        }