Пример #1
0
        private static unsafe NativeList <MapNode> GetPassableNeighbours(int2 currentNode,
                                                                         NativeArray2D <MapNode> gridCopy, MapNode *currentNodePtr)
        {
            NativeList <MapNode> neighbours = new NativeList <MapNode>(8, Allocator.Temp);

            //Find all neighbours on the grid by checking if all surrounding nodes are within grid bounds and are valid nodes to traverse to.
            for (int x = -1; x <= 1; ++x)
            {
                int xIndex = currentNode.x + x;

                if (!gridCopy.CheckXBounds(xIndex))
                {
                    continue;
                }

                for (int y = -1; y <= 1; ++y)
                {
                    if (x == 0 && y == 0)
                    {
                        continue;
                    }

                    int yIndex = currentNode.y + y;

                    if (!gridCopy.CheckYBounds(yIndex))
                    {
                        continue;
                    }

                    MapNode neighbour = gridCopy[xIndex, yIndex];
                    if (neighbour.occupiedBy != OccupiedBy.Nothing || neighbour.state == NodeState.Closed)
                    {
                        continue;
                    }

                    TestNeighbour(gridCopy, ref neighbour, currentNodePtr, neighbours);
                }
            }

            return(neighbours);
        }