예제 #1
0
    private void CreateWayTilesList()
    {
        bool isWayListReady = false;
        bool isExistWayTile;

        Tile currentTile = StartWayTile;
        Tile nextTile;

        for (int i = 0; i < wayTilesCount; i++)
        {
            if (!isWayListReady)
            {
                CheckNeighborWayTile(currentTile, out isExistWayTile, out nextTile);

                if (isExistWayTile)
                {
                    if (nextTile == null)
                    {
                        isWayListReady = true;
                    }

                    else if (WayTiles.Count == 0)
                    {
                        WayTiles.Add(currentTile.Node, currentTile);
                        currentTile.IsWayTile = false;
                        currentTile           = nextTile;
                    }

                    else if (nextTile.Node == FinalWayTile.Node)
                    {
                        WayTiles.Add(currentTile.Node, currentTile);
                        WayTiles.Add(nextTile.Node, nextTile);
                        currentTile.IsWayTile = false;
                        nextTile.IsWayTile    = false;
                        isWayListReady        = true;
                    }

                    else if (nextTile != null)
                    {
                        if (!WayTiles.ContainsKey(currentTile.Node))
                        {
                            WayTiles.Add(currentTile.Node, currentTile);
                            currentTile = nextTile;
                        }
                    }
                }

                else
                {
                    isWayListReady = true;
                }
            }
        }
    }
예제 #2
0
    private void CreateWaypoints()
    {
        GameObject wayPoint;

        int previousIndex = 0;
        int currentIndex  = 1;
        int nextIndex     = 2;

        Node previousNode, currentNode, nextNode;

        foreach (KeyValuePair <Node, Tile> tile in WayTiles)
        {
            previousNode = WayTiles.ElementAt(previousIndex).Key;
            currentNode  = WayTiles.ElementAt(currentIndex).Key;
            nextNode     = WayTiles.ElementAt(nextIndex).Key;

            if (tile.Key == StartWayTile.Node)
            {
                wayPoint = CreateWaypoint(tile.Value);
                WayPoints.Add(wayPoint.transform);
            }

            else if (tile.Key == FinalWayTile.Node)
            {
                wayPoint = CreateWaypoint(WayTiles.ElementAt(nextIndex).Value);
                WayPoints.Add(wayPoint.transform);
            }

            else
            {
                if (CheckOnCornerTile(previousNode, currentNode, nextNode))
                {
                    wayPoint = CreateWaypoint(WayTiles.ElementAt(currentIndex).Value);
                    WayPoints.Add(wayPoint.transform);
                }

                if (nextIndex != wayTilesCount - 1)
                {
                    previousIndex++;
                    currentIndex++;
                    nextIndex++;
                }
            }
        }
    }