/// <summary> /// Instantiating fast and dirty but works fine environmental objects. /// </summary> /// <param name="sourceData"> /// The source Data. /// </param> private void InstantiateEnvironments(ITerrainData sourceData) { //int num = Random.Range(2, 5); int num = 12; this.mushrooms.Clear(); // We use naive approach here for (int i = 0; i < num; i++) { bool duplicate; Transform block; do { block = this.PickNonOcuppiedBlock(sourceData); duplicate = this.mushrooms.Any( go => go.transform.position.Equals(block.position)); }while (duplicate); // Debug.Log("Block Location: " + block.position.x + " " + block.position.y); var mush = Instantiate(this.mushroom, block); mush.transform.localPosition = Vector3.zero; this.mushrooms.Add(mush); // Manually set these tile to undeployable // block.GetComponent<SelectNode>().SetCanDeploy(false); } }
private Transform PickNonOcuppiedBlock(ITerrainData sourceData) { int x; int y; do { x = Random.Range(0, 8); y = Random.Range(0, 8); }while (sourceData.GetTileTypeAt(x, y) == Tiles.Path || sourceData.GetTileTypeAt(x, y) == Tiles.Water); return(this.tileBlocks[x, y]); }
/// <summary> /// Instantiate all tiles. Must call generator.Initialize before using this function. /// This function will destroy any existing tileBlock GameObjects. /// </summary> /// <param name="sourceData"> /// The source Data. /// </param> private void InstantiateTiles(ITerrainData sourceData) { // Re instantiate all tiles for (var x = 0; x < TG.Dimension; x++) { for (var y = 0; y < TG.Dimension; y++) { Tiles tileType = sourceData.GetTileTypeAt(x, y); var instance = this.InstantiateTileAt(tileType, x, y); this.tileBlocks[x, y] = instance.transform; } } }
public static List <int[]> getTerrainData() { List <int[]> res = new List <int[]>(); string data = getData(MapTypes.Terrain); Debug.Log(data); ITerrainData decodedData = JsonUtility.FromJson <ITerrainData>(data); foreach (var line in decodedData.data) { res.Add(line.line); } Debug.Log(decodedData.data.Length); return(res); }
public Division(ITerrainData terrain) { Id = Guid.NewGuid(); _terrain = terrain; }