private void LoadGameData() { string filePath = Application.dataPath + choicesDataProjectFilePath; if (File.Exists(filePath)) { string dataAsJson = File.ReadAllText(filePath); m_ChoicesGameData = JsonUtility.FromJson <ChoicesGameData>(dataAsJson); } else { m_ChoicesGameData = new ChoicesGameData(); } }
private void LoadGameData() { // Path.Combine combines strings into a file path // Application.DataPath points to the "Assets" folder in the Editor string filePath = Path.Combine(Application.dataPath, gameDataFileName); if (File.Exists(filePath)) { // Read the json from the file into a string string dataAsJson = File.ReadAllText(filePath); // Pass the json to JsonUtility, and tell it to create a ChoicesGameData object from it ChoicesGameData loadedData = JsonUtility.FromJson <ChoicesGameData>(dataAsJson); // Retrieve the allChoicesData property of loadedData allChoicesData = loadedData.allChoicesData; } else { Debug.LogError("Cannot load game data at: " + filePath); } }