public void SaveGame() { GameSave ??= new GameSaveData(); var savableObjects = FindObjectsOfType <MonoBehaviour>().Where(monoObject => monoObject is ISavable).ToList(); ISavable playerSaveObject = savableObjects.First(monoObject => monoObject is PlayerController) as ISavable; GameSave.PlayerSaveData = (PlayerSaveData)playerSaveObject?.SaveData(); SpawnerSaveDataList spawnerList = new SpawnerSaveDataList(); var spawnerDataList = savableObjects.OfType <ZombieSpawner>(); foreach (ZombieSpawner spawner in spawnerDataList) { ISavable saveObject = spawner.GetComponent <ISavable>(); spawnerList.SpawnerData.Add(saveObject?.SaveData() as SpawnerSaveData); } GameSave.SpawnerSaveDataList = spawnerList; string jsonString = JsonUtility.ToJson(GameSave); PlayerPrefs.SetString(GameManager.Instance.gameSaveName, jsonString); SaveToGameSaveList(); }
public void SaveGame() { GameSave ??= new GameSaveData(); var savableObjects = FindObjectsOfType <MonoBehaviour>().Where(monoObject => monoObject is ISavable).ToList(); ISavable playerSaveObject = savableObjects.First(monoObject => monoObject is PlayerController) as ISavable; GameSave.playerSaveData = (PlayerSaveData)playerSaveObject.SaveData(); string jsonString = JsonUtility.ToJson(GameSave); PlayerPrefs.SetString(GameManager.Instance.SelectedSaveName, jsonString); SaveToGameSaveList(); }