public void SaveGameConfiguration(LaserLevel newLevel) { ConfigToSave.levels.Add(newLevel); string playerToJason = JsonUtility.ToJson(ConfigToSave, true); Debug.Log(playerToJason); string jsonSaveFilePath = Application.dataPath + "/Laser/Scripts/LaserGameConfigsSavedJSONv2.json"; System.IO.File.WriteAllText(jsonSaveFilePath, playerToJason); }
private void SaveAsLevel() { // Debug mode if (loadedLevel != 0) { return; } int inputLevel = Convert.ToInt32(inputSaveAsLevel.text); LaserLevel newLevel = new LaserLevel(); newLevel.level = Convert.ToInt32(inputSaveAsLevel.text); newLevel.boardSize = (int[])gameBoardSize.Clone(); LaserAvailableItems glass = new LaserAvailableItems(); glass.type = "Glass"; glass.quantity = Convert.ToInt32(inputGlassNum.text); LaserAvailableItems mirror = new LaserAvailableItems(); mirror.type = "Mirror"; mirror.quantity = Convert.ToInt32(inputMirrorNum.text); LaserAvailableItems mirrorBlock = new LaserAvailableItems(); mirrorBlock.type = "MirrorBlock"; mirrorBlock.quantity = Convert.ToInt32(inputMirrorBlockNum.text); LaserAvailableItems blackbody = new LaserAvailableItems(); blackbody.type = "Blackbody"; blackbody.quantity = Convert.ToInt32(inputBlackbodyNum.text); newLevel.availableItems = new List <LaserAvailableItems>(); newLevel.availableItems.Add(glass); newLevel.availableItems.Add(mirror); newLevel.availableItems.Add(mirrorBlock); newLevel.availableItems.Add(blackbody); newLevel.gameBoardItems = new List <LaserGameBoardItems>(); string[] searchTypes = new string[7] { "Start", "Goal", "Glass", "Mirror", "MirrorBlock", "Blackbody", "Invalid" }; for (int index = 0; index < searchTypes.Length; index++) { LaserGameBoardItems fixedItem = new LaserGameBoardItems(); fixedItem.type = searchTypes[index]; for (int row = 0; row < gameBoardSize[0]; row++) { for (int col = 0; col < gameBoardSize[1]; col++) { LaserGameBoardGrid targetGrid = GameObject.Find("grid_" + (row + extraRows).ToString() + "_" + (col + extraCols).ToString()).GetComponent <LaserGameBoardGrid>(); string gridType = targetGrid.gameGridType; if (gridType == searchTypes[index]) { LaserGameBoardItemParameters parameter = new LaserGameBoardItemParameters(); parameter.location = (int[])targetGrid.gameGridID.Clone(); switch (searchTypes[index]) { case ("Start"): parameter.direction = targetGrid.startNode[0].Direction; break; case ("Goal"): parameter.direction = targetGrid.goalNode.Direction; break; case ("Mirror"): parameter.direction = targetGrid.mirrorPattern; break; default: break; } fixedItem.parameters.Add(parameter); } } } newLevel.gameBoardItems.Add(fixedItem); } gameConfiguration.SaveGameConfiguration(newLevel); }