// 2,1|0-0|0-2|# private void GenerateLevel() { string sAllLevels = ReadString(); string[] sLevelsSplited = sAllLevels.Split(BSConstants.LEVEL_LEVEL_SEPARATOR); int iRndLevel = BSUtils.RandInt(0, sLevelsSplited.Length - 2); string sLevel = sLevelsSplited[iRndLevel]; string[] sTiles = sLevel.Split(BSConstants.LEVEL_TILE_SEPARATOR); //GetSize string[] sSize = sTiles[0].Split(BSConstants.LEVEL_SIZE_SEPARATOR); Debug.Log("LEVELIDX : " + iRndLevel + " |Level length " + sSize.Length); Debug.Log("Level> " + sSize[0] + "-" + sSize[1]); //Tiles between 1- sTiles.length - 2 goMatrixTerrain = new GameObject[int.Parse(sSize[0]), int.Parse(sSize[1])]; v2TileSize = new Vector2(int.Parse(sSize[0]), int.Parse(sSize[1])); for (int i = 0; i < int.Parse(sSize[0]); i++) { for (int j = 0; j < int.Parse(sSize[0]); j++) { GameObject go = Instantiate(prefabTile); go.transform.localPosition = new Vector3(i, 0, j); goMatrixTerrain[i, j] = go; GameObject goOnTop, goOnBot; MeshRenderer goTopTile = go.GetComponentsInChildren <MeshRenderer>()[0]; MeshRenderer goBotTile = go.GetComponentsInChildren <MeshRenderer>()[1]; string sTopTileType = sTiles[1 + i * int.Parse(sSize[0]) + j].Split(BSConstants.LEVEL_TILE_UPDOWN_SEPARATOR)[0]; string sBotTileType = sTiles[1 + i * int.Parse(sSize[0]) + j].Split(BSConstants.LEVEL_TILE_UPDOWN_SEPARATOR)[1]; go.GetComponentInChildren <Tile>().SetBotTileType((BSEnums.TileType) int.Parse(sBotTileType)); go.GetComponentInChildren <Tile>().SetTopTileType((BSEnums.TileType) int.Parse(sTopTileType)); if (sTopTileType == ((int)BSEnums.TileType.AIR).ToString()) { goTopTile.enabled = false; goBotTile.enabled = false; } else if (sTopTileType == ((int)BSEnums.TileType.FIXED).ToString()) { goTopTile.material = fixedMaterial; } else if (sTopTileType == ((int)BSEnums.TileType.TRAP).ToString()) { goTopTile.material = trapMaterial; goOnTop = Instantiate(prefTrap, goTopTile.transform); goOnTop.transform.localScale = BSConstants.V3_SPIKE_SCALE; goOnTop.transform.localPosition = BSConstants.V3_SPIKE_POSITION_IN_TILE; } else if (sTopTileType == ((int)BSEnums.TileType.ENEMY).ToString()) { goOnTop = Instantiate(prefEnemy, goTopTile.transform); goOnTop.GetComponent <Enemy>().InitializeEnemy(true, new Vector3(i, 0, j)); goTopTile.material = rotatingMaterialTop; goOnTop.transform.localScale = BSConstants.V3_ENEMY_SCALE; goOnTop.transform.localPosition = BSConstants.V3_ENEMY_POSITION_IN_TILE; } else if (sTopTileType == ((int)BSEnums.TileType.ENTRANCE).ToString()) { goOnTop = Instantiate(prefEntrance, goTopTile.transform); goTopTile.material = rotatingMaterialTop; goOnTop.transform.localScale = BSConstants.V3_ENTRANCE_SCALE; goOnTop.transform.localPosition = BSConstants.V3_ENTRANCE_POSITION_IN_TILE; v2EntrancePosition = new Vector2(i, j); } else if (sTopTileType == ((int)BSEnums.TileType.EXIT).ToString()) { goOnTop = Instantiate(prefEntrance, goTopTile.transform); goTopTile.material = rotatingMaterialTop; goOnTop.transform.localScale = BSConstants.V3_ENTRANCE_SCALE; goOnTop.transform.localPosition = BSConstants.V3_ENTRANCE_POSITION_IN_TILE; Debug.Log("EXIT: " + i + "," + j); v2ExitPositionTop = new Vector2(i, j); } if (sBotTileType == ((int)BSEnums.TileType.AIR).ToString()) { goTopTile.enabled = false; goBotTile.enabled = false; } else if (sBotTileType == ((int)BSEnums.TileType.FIXED).ToString()) { goBotTile.material = fixedMaterial; } else if (sBotTileType == ((int)BSEnums.TileType.TRAP).ToString()) { goBotTile.material = trapMaterial; goOnBot = Instantiate(prefTrap, goBotTile.transform); goOnBot.transform.localScale = BSConstants.V3_SPIKE_SCALE; goOnBot.transform.localPosition = BSConstants.V3_SPIKE_POSITION_IN_TILE; } else if (sBotTileType == ((int)BSEnums.TileType.ENEMY).ToString()) { goOnBot = Instantiate(prefEnemy, goBotTile.transform); goBotTile.material = rotatingMaterialBot; goOnBot.transform.localScale = BSConstants.V3_ENEMY_SCALE; goOnBot.transform.localPosition = BSConstants.V3_ENEMY_POSITION_IN_TILE; goOnBot.GetComponent <Enemy>().InitializeEnemy(false, new Vector3(i, 0, j)); } else if (sBotTileType == ((int)BSEnums.TileType.EXIT).ToString()) { goOnBot = Instantiate(prefEntrance, goBotTile.transform); goBotTile.material = rotatingMaterialBot; goOnBot.transform.localScale = BSConstants.V3_ENTRANCE_SCALE; goOnBot.transform.localPosition = BSConstants.V3_ENTRANCE_POSITION_IN_TILE; Debug.Log("EXIT: " + i + "," + j); v2ExitPositionBot = new Vector2(i, j); } else if (sBotTileType == ((int)BSEnums.TileType.ENTRANCE).ToString()) { goOnBot = Instantiate(prefEntrance, goBotTile.transform); goBotTile.material = rotatingMaterialBot; goOnBot.transform.localScale = BSConstants.V3_ENTRANCE_SCALE; goOnBot.transform.localPosition = BSConstants.V3_ENTRANCE_POSITION_IN_TILE; v2EntrancePosition = new Vector2(i, j); } } } }