public void SaveGame() { //gameSaveData ??= new GameSaveData(); List <ISaveable> saveableObjects = FindObjectsOfType <MonoBehaviour>().OfType <ISaveable>().ToList(); ISaveable playerSaveData = saveableObjects.First(monoObject => monoObject is PlayerController); gameSaveData.playerSaveData = playerSaveData?.SaveData() as PlayerSaveData; string saveDataString = JsonUtility.ToJson(gameSaveData); PlayerPrefs.SetString(GameManager.Instance.GameSaveName, saveDataString); SaveToFileList(); }
public void SaveGame() { // not equal to null if (GameSave == null) { GameSave = new GameSaveData(); } var saveableObjects = FindObjectsOfType <MonoBehaviour>() .Where((MonoBehaviour monoObject) => monoObject is ISaveable).ToList(); ISaveable playerSaveObject = saveableObjects.First((MonoBehaviour monoObject) => monoObject is PlayerController) as ISaveable; GameSave.PlayerSaveData = (PlayerSaveData)playerSaveObject?.SaveData(); string jsonString = JsonUtility.ToJson(GameSave); PlayerPrefs.SetString(GameManager.Instance.SelectedSaveName, jsonString); SaveToGameSaveList(); }