public JsonToSave(GameInfoObj gameInfoObj, List <LevelCoinInfo> levelCoins) { this.gameInfoObj = JsonUtility.ToJson(gameInfoObj); this.levelCoins = new List <string>(); for (int i = 0; i < levelCoins.Count; i++) { this.levelCoins.Add(JsonUtility.ToJson(levelCoins[i])); } }
public static void saveGame() { GameInfoObj gameInfoObj; List <LevelCoinInfo> levelCoins; string json; JsonToSave jsonToSave; if (SaveSystem.Load() == null)//1st time save { gameInfoObj = new GameInfoObj(); levelCoins = new List <LevelCoinInfo>(); levelCoins.Add(new LevelCoinInfo()); jsonToSave = new JsonToSave(gameInfoObj, levelCoins); } else//anytimeSave { gameInfoObj = new GameInfoObj(GameInfo.LevelsUnlocked, GameInfo.ItemEquiped, GameInfo.ShopItemsUnlocked, Wallet.instance.coins); levelCoins = GameInfo.Instance.LevelCoins; jsonToSave = new JsonToSave(gameInfoObj, levelCoins); } json = JsonUtility.ToJson(jsonToSave, true); SaveSystem.Save(json); }