void SaveSettings() { TraininglobalSettings save = CreateTrainingSaveFile(); string jsonStr = JsonUtility.ToJson(save, true); JsonFileUtility.WriteJsonToFile(SAVEFILENAME, jsonStr, JSONSTATE.PERSISTENT_DATA_PATH); Debug.Log("Saving as JSON " + jsonStr); }
TraininglobalSettings CreateTrainingSaveFile() { TraininglobalSettings saveTraininglobalSettings = new TraininglobalSettings { //trainingStarted = TrinaxGlobal.Instance.traininglobalSettings.trainingStarted, infiniteLife = traininglobalSettings.infiniteLife, minSpawnTime = traininglobalSettings.minSpawnTime, maxSpawnTime = traininglobalSettings.maxSpawnTime, difficulty = traininglobalSettings.difficulty, }; return(saveTraininglobalSettings); }
void LoadSettings() { string jsonStr = JsonFileUtility.LoadJsonFromFile(SAVEFILENAME, JSONSTATE.PERSISTENT_DATA_PATH); TraininglobalSettings loadObj = JsonUtility.FromJson <TraininglobalSettings>(jsonStr); if (loadObj != null) { traininglobalSettings.infiniteLife = loadObj.infiniteLife; traininglobalSettings.minSpawnTime = loadObj.minSpawnTime; traininglobalSettings.maxSpawnTime = loadObj.maxSpawnTime; } else { Debug.Log("Json file is empty! Creating a new training save file..."); loadObj = CreateTrainingSaveFile(); } }