示例#1
0
 void AddNeighbourNode(int xOffset, int yOffset, Vector2Int parentPos, AStarPathfinder aStarSearch)
 {
     if (ValidNeigbour(xOffset, yOffset) &&
         !(parentPos.x == nodeIndex.x + xOffset && parentPos.y == nodeIndex.y + yOffset))
     {
         Vector2Int neighbourPos = new Vector2Int(nodeIndex.x + xOffset, nodeIndex.y + yOffset);
         //Debug.Log("neighbourPos:" + neighbourPos);
         MapSearchNode newNode = pathfinder.AllocateMapSearchNode(neighbourPos);
         aStarSearch.AddSuccessor(newNode);
     }
 }
示例#2
0
        void AddNeighbourNodeOfAttachVolume(int xOffset, int yOffset, Vector2Int parentPos, AStarPathfinder aStarSearch)
        {
            int src_xOffset = xOffset;
            int src_yOffset = yOffset;

            bool flag   = true;
            int  volume = aStarSearch.volume;

            if (src_xOffset != 0)
            {
                xOffset += ((xOffset >= 0) ? volume : -volume);
                for (int y = -volume; y <= volume; y++)
                {
                    flag = ValidNeigbour(xOffset, y + src_yOffset);
                    if (flag == false)
                    {
                        return;
                    }
                }
            }

            if (src_yOffset != 0)
            {
                yOffset += ((yOffset >= 0) ? volume : -volume);
                for (int x = -volume; x <= volume; x++)
                {
                    flag = ValidNeigbour(x + src_xOffset, yOffset);
                    if (flag == false)
                    {
                        return;
                    }
                }
            }

            if (flag && !(parentPos.x == nodeIndex.x + src_xOffset && parentPos.y == nodeIndex.y + src_yOffset))
            {
                Vector2Int    neighbourPos = new Vector2Int(nodeIndex.x + src_xOffset, nodeIndex.y + src_yOffset);
                MapSearchNode newNode      = pathfinder.AllocateMapSearchNode(neighbourPos);
                aStarSearch.AddSuccessor(newNode);
            }
        }