示例#1
0
        private static void LoadData()
        {
            for (int index = 0; index < GridData.TileData.Count; index++)
            {
                TileTypePerPosition tileTypePerPosition = GridData.TileData[index];
                tileTypePerPosition.Value = UserSettings.GameData.GridData[tileTypePerPosition.Key].TileType;

                GridData.TileData[index] = tileTypePerPosition;
            }
        }
示例#2
0
        /// <summary>
        /// Set the TileType of a tile at a given position
        /// </summary>
        public void ChangeTile(Vector2Int gridPosition, TileType newType)
        {
            int length = TileData.Count;

            for (int i = 0; i < length; i++)
            {
                TileTypePerPosition pair = TileData[i];

                if (pair.Key.Equals(gridPosition))
                {
                    pair.Value  = newType;
                    TileData[i] = pair;
                    break;
                }
            }
        }
示例#3
0
        /// <summary>
        /// Generate the grid using the provided GridData will return the grid as a 2d array of tiles
        /// </summary>
        public AbstractTile[,] GenerateGrid(GridData data, Transform parent)
        {
            DestroyChildren();

            AbstractTile[,] grid = new AbstractTile[data.GridSize.y, data.GridSize.x];

            List <TileTypePerPosition> tileData = data.TileData;
            int length = tileData.Count;

            for (int i = 0; i < length; i++)
            {
                TileTypePerPosition tileDatum    = tileData[i];
                Vector2Int          gridPosition = tileDatum.Key;

                AbstractTile tile = InstantiateTile(data, parent, tileDatum.Value, gridPosition);
                grid[gridPosition.y, gridPosition.x] = tile;
                AddNeighborsToTile(grid, tile);
            }

            return(grid);
        }