void InitializeContinue() { if (Prefs.Exist(Prefs.LOAD_SAVE_NAME)) { lastSave = Prefs.Game_SaveName(); if (fi != null && fi.Length > 0 && fi.Any(x => x.Name == lastSave)) { continueButton.interactable = true; isSaveGame = true; } else { if (File.Exists(JsonManager.GetFilePath(FilePath.GameDataPath) + lastSave)) { continueButton.interactable = true; } else { continueButton.interactable = false; } isSaveGame = false; } } }
public void NewGame(string scene) { Prefs.Game_LoadState(0); Prefs.Game_SaveName(string.Empty); Prefs.Game_LevelName(scene); SceneManager.LoadScene(1); }
public void Load() { Prefs.Game_LoadState(1); Prefs.Game_SaveName(selectedSave.save); Prefs.Game_LevelName(selectedSave.scene); SceneManager.LoadScene(1); }
void Start() { inventory = GetComponent <Inventory>(); objectives = GetComponent <ObjectiveManager>(); player = GetComponent <HFPS_GameManager>().Player; switcher = player.GetComponentInChildren <ScriptManager>().GetScript <ItemSwitcher>(); JsonManager.Settings(SaveLoadSettings, true); if (saveableDataPairs.Any(pair => pair.Instance == null)) { Debug.LogError("[SaveGameHandler] Some of Saveable Instances are missing or it's destroyed. Please select Setup SaveGame again from the Tools menu!"); return; } if (Prefs.Exist(Prefs.LOAD_STATE)) { int loadstate = Prefs.Game_LoadState(); if (loadstate == 0) { DeleteNextLvlData(); } else if (loadstate == 1 && Prefs.Exist(Prefs.LOAD_SAVE_NAME)) { string filename = Prefs.Game_SaveName(); if (File.Exists(JsonManager.GetFilePath(FilePath.GameSavesPath) + filename)) { JsonManager.DeserializeData(filename); string loadScene = (string)JsonManager.Json()["scene"]; lastSave = filename; if (UnityEngine.SceneManagement.SceneManager.GetActiveScene().name == loadScene) { LoadSavedSceneData(true); } } else { Debug.Log("<color=yellow>[SaveGameHandler]</color> Could not find load file: " + filename); Prefs.Game_LoadState(0); } } else if (loadstate == 2 && Prefs.Exist(Prefs.LOAD_SAVE_NAME) && dataBetweenScenes) { JsonManager.ClearArray(); Prefs.Game_SaveName("_NextSceneData.sav"); if (File.Exists(JsonManager.GetFilePath(FilePath.GameDataPath) + "_NextSceneData.sav")) { JsonManager.DeserializeData(FilePath.GameDataPath, "_NextSceneData.sav"); LoadSavedSceneData(false); } } } }
private IEnumerator LoadScene(string scene, int loadstate) { yield return(new WaitUntil(() => !saveHandler.fadeControl.isFading)); Prefs.Game_SaveName(saveHandler.lastSave); Prefs.Game_LoadState(loadstate); Prefs.Game_LevelName(scene); SceneManager.LoadScene(m_sceneLoader); }
public void Continue() { if (isSaveGame) { SavedGame saved = saveCache.Select(x => x.GetComponent <SavedGame>()).Where(x => x.save == lastSave).SingleOrDefault(); Prefs.Game_LoadState(1); Prefs.Game_SaveName(saved.save); Prefs.Game_LevelName(saved.scene); } else { Prefs.Game_LoadState(2); Prefs.Game_SaveName(lastSave); } SceneManager.LoadScene(1); }
async void SerializeSaveData(bool betweenScenes) { string filepath = JsonManager.GetFilePath(FilePath.GameSavesPath); GetComponent <HFPS_GameManager>().ShowSaveNotification(); if (!betweenScenes) { if (Directory.Exists(filepath)) { DirectoryInfo di = new DirectoryInfo(filepath); FileInfo[] fi = di.GetFiles("Save?.sav"); if (fi.Length > 0) { string SaveName = "Save" + fi.Length; lastSave = SaveName + ".sav"; FileStream file = new FileStream(JsonManager.GetCurrentPath() + SaveName + ".sav", FileMode.OpenOrCreate); await Task.Run(() => JsonManager.SerializeJsonDataAsync(file)); } else { lastSave = "Save0.sav"; FileStream file = new FileStream(JsonManager.GetCurrentPath() + "Save0.sav", FileMode.OpenOrCreate); await Task.Run(() => JsonManager.SerializeJsonDataAsync(file)); } } else { Directory.CreateDirectory(JsonManager.GetCurrentPath()); lastSave = "Save0.sav"; FileStream file = new FileStream(JsonManager.GetCurrentPath() + "Save0.sav", FileMode.OpenOrCreate); await Task.Run(() => JsonManager.SerializeJsonDataAsync(file)); } Prefs.Game_SaveName(lastSave); DeleteNextLvlData(); } else { DeleteNextLvlData(); FileStream file = new FileStream(JsonManager.GetFilePath(FilePath.GameDataPath) + "_NextSceneData.sav", FileMode.OpenOrCreate); await Task.Run(() => JsonManager.SerializeJsonDataAsync(file, true)); } }