public void GenerateLevelFromLevelData() { DeleteLevel(); iTileSize = lvlExit.MaxSize; BuildLevelTiles(lvlExit.MaxSize); string[] sLevelData = lvlExit.levelBuild.Split(MMConstants.LEVEL_SEPARATOR); int iColorObjectIdx = 0, iRotationIdx = 0, iObjMoveIdx = 0; for (int i = 0; i < sLevelData.Length; i++) { tiles[i].GetComponent <Tile>().ttTile = (MMEnums.TileType) int.Parse(sLevelData[i]); if (MMUtils.IsColorObject(tiles[i].GetComponent <Tile>().ttTile)) { tiles[i].GetComponent <Tile>().clrObject = lvlExit.objColor[iColorObjectIdx]; iColorObjectIdx++; } if (MMUtils.IsScenarioObject(tiles[i].GetComponent <Tile>().ttTile)) { tiles[i].transform.rotation = Quaternion.Euler(lvlExit.objRotation[iRotationIdx]); iRotationIdx++; } if (MMUtils.IsPushableObject(tiles[i].GetComponent <Tile>().ttTile)) { tiles[i].GetComponent <Tile>().bMovementOn = lvlExit.objMovementEnabled[iObjMoveIdx]; iObjMoveIdx++; } } RefreshTiles(); }
public void GetLevelData() { lvlExit.levelBuild = ""; Vector3[] v3ObjectsRotations = new Vector3[iNumberOfObjects]; Color[] clrObjects = new Color[iNumberOfColors]; bool[] bMovementObjects = new bool[iNumberOfMovementObjects]; int iObjIndex = 0, iClrIndex = 0, iObjMoveIndex = 0; for (int i = 0; i < tiles.Length; i++) { lvlExit.levelBuild += ((int)tiles[i].GetComponent <Tile>().ttTile).ToString() + MMConstants.LEVEL_SEPARATOR; if (MMUtils.IsScenarioObject(tiles[i].GetComponent <Tile>().ttTile)) { v3ObjectsRotations[iObjIndex] = tiles[i].transform.rotation.eulerAngles; iObjIndex++; } if (MMUtils.IsColorObject(tiles[i].GetComponent <Tile>().ttTile)) { clrObjects[iClrIndex] = tiles[i].GetComponent <Tile>().clrObject; iClrIndex++; } if (MMUtils.IsPushableObject(tiles[i].GetComponent <Tile>().ttTile)) { bMovementObjects[iObjMoveIndex] = tiles[i].GetComponent <Tile>().bMovementOn; iObjMoveIndex++; } } lvlExit.objColor = new Color[iNumberOfColors]; lvlExit.objColor = (Color[])clrObjects.Clone(); lvlExit.objRotation = new Vector3[iNumberOfObjects]; lvlExit.objRotation = (Vector3[])v3ObjectsRotations.Clone(); lvlExit.objMovementEnabled = new bool[iNumberOfMovementObjects]; lvlExit.objMovementEnabled = (bool[])bMovementObjects.Clone(); lvlExit.levelBuild = lvlExit.levelBuild.Substring(0, lvlExit.levelBuild.Length - 1); lvlExit.MaxSize = iTileSize; #if UNITY_EDITOR AssetDatabase.SaveAssets(); EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene()); EditorUtility.SetDirty(lvlExit); #endif print("DATA GENERATED!"); }