public static void SaveData() { //Reference LemonSave lemonSave = new LemonSave(); //Lemonade lemonSave.serializedLemonade = GlobalLemonade.LemonadeCount; LemonSave.lemonade = lemonSave.serializedLemonade; //Pounds lemonSave.serializedPounds = GlobalCash.CashCount; LemonSave.pounds = lemonSave.serializedPounds; //Time lemonSave.serializedDateTime = DateTime.UtcNow. ToString("HH:mm:ss dd MMMM, yyyy"); Debug.Log("Saving Lemonade Value: " + GlobalLemonade.LemonadeCount); Debug.Log("Saving Cash Value: " + GlobalCash.CashCount); string jsonData = JsonUtility.ToJson(lemonSave, true); File.WriteAllText(jsonSavePath, jsonData); Debug.Log(jsonData); }
public static void LoadData() { LemonSave lemonSave = JsonUtility.FromJson <LemonSave>(File.ReadAllText(jsonSavePath)); GlobalLemonade.LemonadeCount = lemonSave.serializedLemonade; GlobalCash.CashCount = lemonSave.serializedPounds; //Debug.Log((TimeSpan)(DateTime.UtcNow - //DateTime.Parse(lemonSave.serializedDateTime))); if (lemonSave.serializedDateTime != null) { TimeSpan dTime = DateTime.UtcNow - DateTime.Parse(lemonSave.serializedDateTime); GlobalLemonade.LemonadeCount += (int)(dTime.TotalSeconds); Debug.Log("Generated " + (int)(dTime.TotalSeconds) + " cups of lemonade!"); } //For testing purposes Debug.Log("Lemonade: " + GlobalLemonade.LemonadeCount); Debug.Log("Pounds: " + GlobalCash.CashCount); LemonSave.loaded = true; }