Esempio n. 1
0
    /// <summary>Creates a row of editor tiles based on the given parameters.</summary>
    /// <param name="tiles">List of tile info that could be included in the row (used primarily for loading grids).</param>
    /// <param name="xOffset">The x position of teh first tile.</param>
    /// <param name="zOffset">The z position of all tiles in the row.</param>
    /// <param name="gridIndex">The index of the row in the grid.</param>
    /// <param name="numHexes">The number of desired tiles in the row.</param>
    private void CreateRow(List <TileInfo> tiles, float xOffset, float zOffset, int gridIndex, int numHexes)
    {
        EditorList list = new EditorList();

        if (gridIndex > grid.Count - 1)
        {
            grid.Add(list);
        }
        else if (gridIndex > -1)
        {
            grid.Insert(gridIndex, list);
        }
        else
        {
            return;
        }

        for (int n = 0; n < numHexes; n++)
        {
            EditorTile tile = CreateTile(list, xOffset - (n * gridSpacing), zOffset);

            if (tile != null)
            {
                bool       teleport    = false;
                Vector2Int teleportPos = Vector2Int.left;
                list.Add(tile);
                if (tiles != null && tiles.Count > 0)
                {
                    while (tiles.Count > 0 && tiles[0].IsInvalid())
                    {
                        tiles.RemoveAt(0);
                    }

                    if (tiles.Count > 0 && MatchSpace(gridIndex, n, tiles[0].GetPosition()))
                    {
                        TileType type = tiles[0].GetInfoType();
                        if (type == TileType.Teleport)
                        {
                            //Sets teleporter parner Position
                            teleportPos = tiles[0].GetTeleportPosition();
                            //Sets teleporter's color
                            editorParams.tileVariants[TileType.Teleport].variant = tiles[0].GetVariant();
                            teleport = true;
                        }
                        else if (type == TileType.Removed)
                        {
                            removedTileButtons.Add(tile.gridButton);
                        }



                        tile.UpdateTile(type, tiles[0].GetVariant());
                        tiles.RemoveAt(0);
                    }
                }

                if (teleport)
                {
                    if (CheckTilePosition(teleportPos))
                    {
                        tile.SetTeleportDesination(GetTile(teleportPos), editorParams.tileVariants[TileType.Teleport].variant);
                    }
                }
            }
            else
            {
                Debug.LogError("Error: Grid Creator's Editor Tile prefab does not have a EditorTile component!");
            }
        }
    }