Ejemplo n.º 1
0
            /// <inheritdoc/>
            public void Execute(int index)
            {
                FixedListInt32 neighborIndices = new FixedListInt32();
                int            nodeRow         = index / scanSettings.gridWidth;

                int topIndex   = index + scanSettings.gridWidth;
                int rightIndex = (index + 1) / scanSettings.gridWidth != nodeRow ? -1 : index + 1;
                int botIndex   = index - scanSettings.gridWidth;
                int leftIndex  = (index - 1) / scanSettings.gridWidth != nodeRow ? -1 : index - 1;

                // the order is important, its used by some of the pathfinder algorithms
                neighborIndices.AddNoResize(topIndex);
                neighborIndices.AddNoResize(rightIndex);
                neighborIndices.AddNoResize(botIndex);
                neighborIndices.AddNoResize(leftIndex);

                int numNeighbors = NodeNumNeighbors;

                for (int i = 0; i < numNeighbors; ++i)
                {
                    int neighborIndex       = neighborIndices[i];
                    int neighborsArrayIndex = index * numNeighbors + i;

                    if (neighborIndex < 0 || neighborIndex >= nodesTransforms.Length)
                    {
                        // out of bounds
                        neighbors[neighborsArrayIndex] = new NodeNeighbor(-1, false);
                        continue;
                    }

                    bool canReachNeighbor = CanReachNeighbor(index, neighborIndex);
                    neighbors[neighborsArrayIndex] = new NodeNeighbor(neighborIndex, canReachNeighbor);
                }
            }
Ejemplo n.º 2
0
            /// <inheritdoc/>
            public void Execute(int index)
            {
                int numNeighbors = NodeNeighbors;

                NativeArray <int> neighborIndices = new NativeArray <int>(numNeighbors, Allocator.Temp, NativeArrayOptions.UninitializedMemory);
                int nodeRow = index / scanSettings.gridWidth;

                int topIndex   = index + scanSettings.gridWidth;
                int rightIndex = (index + 1) / scanSettings.gridWidth != nodeRow ? -1 : index + 1;
                int botIndex   = index - scanSettings.gridWidth;
                int leftIndex  = (index - 1) / scanSettings.gridWidth != nodeRow ? -1 : index - 1;

                // Note: the order is important, its used by some of the PathFinder algorithms
                neighborIndices[0] = topIndex;
                neighborIndices[1] = rightIndex;
                neighborIndices[2] = botIndex;
                neighborIndices[3] = leftIndex;

                for (int i = 0; i < numNeighbors; i++)
                {
                    int neighborIndex       = neighborIndices[i];
                    int neighborsArrayIndex = index * numNeighbors + i;

                    if (neighborIndex < 0 || neighborIndex >= nodesTransforms.Length)
                    {
                        // out of bounds
                        neighbors[neighborsArrayIndex] = new NodeNeighbor(-1, false);
                        continue;
                    }

                    bool canReachNeighbor = CanReachNeighbor(index, neighborIndex);
                    neighbors[neighborsArrayIndex] = new NodeNeighbor(neighborIndex, canReachNeighbor);
                }

                neighborIndices.Dispose();
            }