Exemple #1
0
    public void GenerateChunkedTiles(int startX, int startY, float[,] heightNoiseArray)
    {
        int count      = 0;
        int chunkXSize = 100;
        int chunkYSize = 100;

        tiles = new WorldTile[chunkXSize * chunkYSize];

        for (int x = startX; x < startX + chunkXSize; x++)
        {
            for (int y = startY; y < startY + chunkYSize; y++)
            {
                float currentHeight = heightNoiseValues[x, y];

                for (int i = 0; i < regions.Length; i++)
                {
                    if (currentHeight <= regions[i].height)
                    {
                        tiles[count] = new WorldTile(i, x, y);
                        count++;

                        break;
                    }
                }
            }
        }

        tileCollection = new WorldTileCollection(tiles, "worldTiles");

        using (StreamWriter stream = new StreamWriter(streamPath + startX.ToString() + "_" + startY.ToString() + ".json"))
        {
            string json = JsonUtility.ToJson(tileCollection, true);
            stream.Write(json);
        }
    }
Exemple #2
0
    public void GenerateTiles(float[,] heightNoiseArray, float[,] moistureNoiseArray, float[,] tempNoiseArray)
    {
        int count      = 0;
        int chunkXSize = chunkSize;
        int chunkYSize = chunkSize;

        tiles = new WorldTile[mapWidth * mapHeight];

        for (int y = 0; y < mapHeight; y++)
        {
            for (int x = 0; x < mapWidth; x++)
            {
                float currentHeight = heightNoiseValues[x, y];

                for (int i = 0; i < regions.Length; i++)
                {
                    if (currentHeight <= regions[i].height)
                    {
                        tiles[count] = new WorldTile(i, x, y);
                        count++;

                        break;
                    }
                }
            }
        }

        tileCollection = new WorldTileCollection(tiles, "worldTiles");

        using (StreamWriter stream = new StreamWriter(streamPath + ".json"))
        {
            string json = JsonUtility.ToJson(tileCollection, true);
            stream.Write(json);
        }
    }
Exemple #3
0
 /// <summary>
 /// Switches the decorations of the provided points, with the provided state.
 /// </summary>
 /// <param name="tilePositions">points of  the desired tiles to be edited</param>
 /// <param name="state">the state to switch to</param>
 public void SwitchTileDecoration(HashSet <Point> tilePositions, TileStates state)
 {
     foreach (Point position in tilePositions)
     {
         if (WorldTileCollection.ContainsKey(position) == false)
         {
             continue;
         }
         WorldTileCollection[position].Decorator.ApplyTileState(state);
     }
 }
Exemple #4
0
    public void StartChunkGenerator(int x, int y, int size)
    {
        using (StreamReader stream = new StreamReader(streamPath + x.ToString() + "_" + y.ToString() + ".json"))
        {
            string json = stream.ReadToEnd();

            tileCollection = JsonUtility.FromJson <WorldTileCollection>(json);
        }


        for (int i = 0; i < tileCollection.tiles.Length; i++)
        {
            WorldTile wt = tileCollection.tiles[i];
            for (int type = 0; type < TerrainGenerator.instance.regions.Length; type++)
            {
                if ((int)wt.type == type)
                {
                    regions[type].grid.SetTile(new Vector3Int(wt.x, wt.y, (int)wt.type), regions[type].tile);
                }
            }
        }
    }