public void ImportSaveGame(int saveID) { string allData = ""; foreach (SaveFile saveFile in foundImportFiles) { if (saveFile.ID == saveID) { allData = Serializer.LoadSaveFile (saveFile.fileName, true); } } if (allData.ToString () != "") { string mainData; int divider = allData.IndexOf ("||"); mainData = allData.Substring (0, divider); if (SaveSystem.GetSaveMethod () == SaveMethod.XML) { saveData = (SaveData) Serializer.DeserializeObjectXML <SaveData> (mainData); } else { saveData = Serializer.DeserializeObjectBinary <SaveData> (mainData); } // Stop any current-running ActionLists, dialogs and interactions KillActionLists (); SaveSystem.AssignVariables (saveData.mainData.runtimeVariablesData); } }
public void LoadSaveGame(int saveID) { string allData = Serializer.LoadSaveFile (GetSaveFileName (saveID), true); if (allData.ToString () != "") { string mainData; string roomData; int divider = allData.IndexOf ("||"); mainData = allData.Substring (0, divider); roomData = allData.Substring (divider + 2); if (SaveSystem.GetSaveMethod () == SaveMethod.XML) { saveData = (SaveData) Serializer.DeserializeObjectXML <SaveData> (mainData); KickStarter.levelStorage.allLevelData = (List<SingleLevelData>) Serializer.DeserializeObjectXML <List<SingleLevelData>> (roomData); } else { saveData = Serializer.DeserializeObjectBinary <SaveData> (mainData); KickStarter.levelStorage.allLevelData = Serializer.DeserializeRoom (roomData); } // Stop any current-running ActionLists, dialogs and interactions KillActionLists (); // If player has changed, destroy the old one and load in the new one if (KickStarter.settingsManager.playerSwitching == PlayerSwitching.Allow) { if ((KickStarter.player == null && saveData.mainData.currentPlayerID != KickStarter.settingsManager.GetEmptyPlayerID ()) || (KickStarter.player != null && KickStarter.player.ID != saveData.mainData.currentPlayerID)) { KickStarter.ResetPlayer (GetPlayerByID (saveData.mainData.currentPlayerID), saveData.mainData.currentPlayerID, true, Quaternion.identity); } } int newScene = GetPlayerScene (saveData.mainData.currentPlayerID, saveData.playerData); // Load correct scene if (newScene != Application.loadedLevel) { loadingGame = LoadingGame.InNewScene; KickStarter.sceneChanger.ChangeScene ("", newScene, false); } else { loadingGame = LoadingGame.InSameScene; // Already in the scene Sound[] sounds = FindObjectsOfType (typeof (Sound)) as Sound[]; foreach (Sound sound in sounds) { if (sound.GetComponent <AudioSource>()) { if (sound.soundType != SoundType.Music && !sound.GetComponent <AudioSource>().loop) { sound.Stop (); } } } OnLevelWasLoaded (); } } }
private bool DoImportCheck(string filename, int boolID) { string allData = Serializer.LoadSaveFile (filename, false); if (allData.ToString () != "") { int divider = allData.IndexOf ("||"); string mainData = allData.Substring (0, divider); SaveData tempSaveData = new SaveData (); if (SaveSystem.GetSaveMethod () == SaveMethod.XML) { tempSaveData = (SaveData) Serializer.DeserializeObjectXML <SaveData> (mainData); } else { tempSaveData = Serializer.DeserializeObjectBinary <SaveData> (mainData); } string varData = tempSaveData.mainData.runtimeVariablesData; if (varData.Length > 0) { string[] varsArray = varData.Split ("|"[0]); foreach (string chunk in varsArray) { string[] chunkData = chunk.Split (":"[0]); int _id = 0; int.TryParse (chunkData[0], out _id); if (_id == boolID) { int _value = 0; int.TryParse (chunkData[1], out _value); if (_value == 1) { return true; } return false; } } } } return false; }
public void ClearAllData() { saveData = new SaveData (); }
public bool SaveSaveGame(int saveID, bool overwriteLabel = true, string newLabel = "") { if (GetNumSaves () >= KickStarter.settingsManager.maxSaves && !DoesSaveExist (saveID)) { Debug.LogWarning ("Cannot save - maximum number of save files has already been reached."); return false; } CustomSaveHook (); KickStarter.levelStorage.StoreCurrentLevelData (); Player player = KickStarter.player; if (KickStarter.playerInput && KickStarter.runtimeInventory && KickStarter.sceneChanger && KickStarter.settingsManager && KickStarter.stateHandler) { if (saveData != null && saveData.playerData != null && saveData.playerData.Count > 0) { foreach (PlayerData _data in saveData.playerData) { if (player != null && _data.playerID == player.ID) { saveData.playerData.Remove (_data); break; } } } else { saveData = new SaveData (); saveData.mainData = new MainData (); saveData.playerData = new List<PlayerData>(); } PlayerData playerData = SavePlayerData (player); saveData.playerData.Add (playerData); // Main data saveData.mainData.cursorIsOff = KickStarter.stateHandler.cursorIsOff; saveData.mainData.inputIsOff = KickStarter.stateHandler.inputIsOff; saveData.mainData.interactionIsOff = KickStarter.stateHandler.interactionIsOff; saveData.mainData.menuIsOff = KickStarter.stateHandler.menuIsOff; saveData.mainData.movementIsOff = KickStarter.stateHandler.movementIsOff; saveData.mainData.cameraIsOff = KickStarter.stateHandler.cameraIsOff; saveData.mainData.triggerIsOff = KickStarter.stateHandler.triggerIsOff; saveData.mainData.playerIsOff = KickStarter.stateHandler.playerIsOff; saveData.mainData.movementMethod = (int) KickStarter.settingsManager.movementMethod; if (player != null) { saveData.mainData.currentPlayerID = player.ID; } else { saveData.mainData.currentPlayerID = KickStarter.settingsManager.GetEmptyPlayerID (); } saveData.mainData.timeScale = KickStarter.playerInput.timeScale; if (KickStarter.playerInput.activeArrows) { saveData.mainData.activeArrows = Serializer.GetConstantID (KickStarter.playerInput.activeArrows.gameObject); } if (KickStarter.playerInput.activeConversation) { saveData.mainData.activeConversation = Serializer.GetConstantID (KickStarter.playerInput.activeConversation.gameObject); } if (KickStarter.runtimeInventory.selectedItem != null) { saveData.mainData.selectedInventoryID = KickStarter.runtimeInventory.selectedItem.id; saveData.mainData.isGivingItem = KickStarter.runtimeInventory.IsGivingItem (); } else { saveData.mainData.selectedInventoryID = -1; } RuntimeVariables.DownloadAll (); saveData.mainData.runtimeVariablesData = SaveSystem.CreateVariablesData (RuntimeVariables.GetAllVars (), false, VariableLocation.Global); saveData.mainData.menuLockData = CreateMenuLockData (PlayerMenus.GetMenus ()); saveData.mainData.menuVisibilityData = CreateMenuVisibilityData (PlayerMenus.GetMenus ()); saveData.mainData.menuElementVisibilityData = CreateMenuElementVisibilityData (PlayerMenus.GetMenus ()); saveData.mainData.menuJournalData = CreateMenuJournalData (PlayerMenus.GetMenus ()); string mainData = ""; string levelData = ""; if (SaveSystem.GetSaveMethod () == SaveMethod.XML) { mainData = Serializer.SerializeObjectXML <SaveData> (saveData); levelData = Serializer.SerializeObjectXML <List<SingleLevelData>> (KickStarter.levelStorage.allLevelData); } else { mainData = Serializer.SerializeObjectBinary (saveData); levelData = Serializer.SerializeObjectBinary (KickStarter.levelStorage.allLevelData); } string allData = mainData + "||" + levelData; Serializer.CreateSaveFile (GetSaveFileName (saveID), allData); // Update label if (overwriteLabel) { GatherSaveFiles (); for (int i=0; i<Mathf.Min (50, foundSaveFiles.Count); i++) { if (foundSaveFiles[i].ID == saveID) { SaveFile newSaveFile = new SaveFile (foundSaveFiles [i]); if (newLabel.Length > 0) { newSaveFile.SetLabel (newLabel); } else { newSaveFile.SetLabel (GetDefaultSaveLabel (saveID)); } foundSaveFiles[i] = newSaveFile; break; } } } // Update PlayerPrefs Options.optionsData.lastSaveID = saveID; Options.UpdateSaveLabels (foundSaveFiles.ToArray ()); #if !UNITY_WEBPLAYER && !UNITY_WINRT && !UNITY_WII if (KickStarter.settingsManager.takeSaveScreenshots) { StartCoroutine ("TakeScreenshot", GetSaveScreenshotName (saveID)); } else { GatherSaveFiles (); } #else GatherSaveFiles (); #endif } else { if (KickStarter.playerInput == null) { Debug.LogWarning ("Save failed - no PlayerInput found."); } if (KickStarter.runtimeInventory == null) { Debug.LogWarning ("Save failed - no RuntimeInventory found."); } if (KickStarter.sceneChanger == null) { Debug.LogWarning ("Save failed - no SceneChanger found."); } if (KickStarter.settingsManager == null) { Debug.LogWarning ("Save failed - no Settings Manager found."); } } return true; }
public void SaveCurrentPlayerData() { if (saveData != null && saveData.playerData != null && saveData.playerData.Count > 0) { foreach (PlayerData _data in saveData.playerData) { if ((KickStarter.player != null && _data.playerID == KickStarter.player.ID) || (KickStarter.player == null && _data.playerID == KickStarter.settingsManager.GetEmptyPlayerID ())) { saveData.playerData.Remove (_data); break; } } } else { saveData = new SaveData (); saveData.mainData = new MainData (); saveData.playerData = new List<PlayerData>(); } PlayerData playerData = SavePlayerData (KickStarter.player); saveData.playerData.Add (playerData); }
/** * <summary>Saves the game, once found to exist.</summary> * <param name = "saveID">The save ID to save</param> * <param name = "overwriteLabel">True if the label should be updated</param> * <param name = "newLabel">The new label, if it can be set. If blank, a default label will be generated.</param> * <returns>True if the save was successful</returns> */ public bool SaveSaveGame(int saveID, bool overwriteLabel = true, string newLabel = "") { if (GetNumSaves () >= KickStarter.settingsManager.maxSaves && !DoesSaveExist (saveID)) { ACDebug.LogWarning ("Cannot save - maximum number of save files has already been reached."); return false; } CustomSaveHook (); KickStarter.levelStorage.StoreCurrentLevelData (); Player player = KickStarter.player; if (KickStarter.playerInput && KickStarter.runtimeInventory && KickStarter.sceneChanger && KickStarter.settingsManager && KickStarter.stateHandler) { if (saveData != null && saveData.playerData != null && saveData.playerData.Count > 0) { foreach (PlayerData _data in saveData.playerData) { if (player != null && _data.playerID == player.ID) { saveData.playerData.Remove (_data); break; } } } else { saveData = new SaveData (); saveData.mainData = new MainData (); saveData.playerData = new List<PlayerData>(); } PlayerData playerData = SavePlayerData (player); saveData.playerData.Add (playerData); // Main data saveData.mainData = KickStarter.stateHandler.SaveMainData (saveData.mainData); saveData.mainData.movementMethod = (int) KickStarter.settingsManager.movementMethod; if (player != null) { saveData.mainData.currentPlayerID = player.ID; } else { saveData.mainData.currentPlayerID = KickStarter.settingsManager.GetEmptyPlayerID (); } saveData.mainData = KickStarter.playerInput.SaveMainData (saveData.mainData); saveData.mainData = KickStarter.runtimeInventory.SaveMainData (saveData.mainData); saveData.mainData = KickStarter.runtimeVariables.SaveMainData (saveData.mainData); saveData.mainData = KickStarter.playerMenus.SaveMainData (saveData.mainData); string mainData = Serializer.SerializeObject <SaveData> (saveData, true); string levelData = Serializer.SerializeAllRoomData (KickStarter.levelStorage.allLevelData); string allData = mainData + "||" + levelData; Serializer.CreateSaveFile (GetSaveFileName (saveID), allData); // Update label if (overwriteLabel) { GatherSaveFiles (); for (int i=0; i<Mathf.Min (50, foundSaveFiles.Count); i++) { if (foundSaveFiles[i].ID == saveID) { SaveFile newSaveFile = new SaveFile (foundSaveFiles [i]); if (newLabel.Length > 0) { newSaveFile.SetLabel (newLabel); } else { newSaveFile.SetLabel (GetDefaultSaveLabel (saveID)); } foundSaveFiles[i] = newSaveFile; break; } } } // Update PlayerPrefs Options.optionsData.lastSaveID = saveID; Options.UpdateSaveLabels (foundSaveFiles.ToArray ()); #if !UNITY_WEBPLAYER && !UNITY_WINRT && !UNITY_WII if (KickStarter.settingsManager.takeSaveScreenshots) { StartCoroutine ("TakeScreenshot", GetSaveScreenshotName (saveID)); } else { GatherSaveFiles (); } #else GatherSaveFiles (); #endif } else { if (KickStarter.playerInput == null) { ACDebug.LogWarning ("Save failed - no PlayerInput found."); } if (KickStarter.runtimeInventory == null) { ACDebug.LogWarning ("Save failed - no RuntimeInventory found."); } if (KickStarter.sceneChanger == null) { ACDebug.LogWarning ("Save failed - no SceneChanger found."); } if (KickStarter.settingsManager == null) { ACDebug.LogWarning ("Save failed - no Settings Manager found."); } } return true; }
public void SaveCurrentPlayerData () { if (saveData != null && saveData.playerData != null && saveData.playerData.Count > 0) { foreach (PlayerData _data in saveData.playerData) { if (_data.playerID == KickStarter.player.ID) { saveData.playerData.Remove (_data); break; } } } else { saveData = new SaveData (); saveData.mainData = new MainData (); saveData.playerData = new List<PlayerData>(); } PlayerData playerData = SavePlayerData (KickStarter.player); saveData.playerData.Add (playerData); }
public void SaveSaveGame (int saveID) { levelStorage.StoreCurrentLevelData (); Player player = KickStarter.player; PlayerInput playerInput = GameObject.FindWithTag (Tags.gameEngine).GetComponent <PlayerInput>(); RuntimeInventory runtimeInventory = this.GetComponent <RuntimeInventory>(); SceneChanger sceneChanger = this.GetComponent <SceneChanger>(); SettingsManager settingsManager = AdvGame.GetReferences ().settingsManager; StateHandler stateHandler = this.GetComponent <StateHandler>(); if (playerInput && runtimeInventory && sceneChanger && settingsManager && stateHandler) { if (saveData != null && saveData.playerData != null && saveData.playerData.Count > 0) { foreach (PlayerData _data in saveData.playerData) { if (_data.playerID == player.ID) { saveData.playerData.Remove (_data); break; } } } else { saveData = new SaveData (); saveData.mainData = new MainData (); saveData.playerData = new List<PlayerData>(); } PlayerData playerData = SavePlayerData (player); saveData.playerData.Add (playerData); // Main data saveData.mainData.cursorIsOff = stateHandler.cursorIsOff; saveData.mainData.inputIsOff = stateHandler.inputIsOff; saveData.mainData.interactionIsOff = stateHandler.interactionIsOff; saveData.mainData.menuIsOff = stateHandler.menuIsOff; saveData.mainData.movementIsOff = stateHandler.movementIsOff; saveData.mainData.cameraIsOff = stateHandler.cameraIsOff; saveData.mainData.triggerIsOff = stateHandler.triggerIsOff; saveData.mainData.playerIsOff = stateHandler.playerIsOff; if (player != null) { saveData.mainData.currentPlayerID = player.ID; } else { saveData.mainData.currentPlayerID = 0; } saveData.mainData.timeScale = playerInput.timeScale; if (playerInput.activeArrows) { saveData.mainData.activeArrows = Serializer.GetConstantID (playerInput.activeArrows.gameObject); } if (playerInput.activeConversation) { saveData.mainData.activeConversation = Serializer.GetConstantID (playerInput.activeConversation.gameObject); } if (runtimeInventory.selectedItem != null) { saveData.mainData.selectedInventoryID = runtimeInventory.selectedItem.id; } else { saveData.mainData.selectedInventoryID = -1; } RuntimeVariables.DownloadAll (); saveData.mainData.runtimeVariablesData = SaveSystem.CreateVariablesData (RuntimeVariables.GetAllVars (), false, VariableLocation.Global); saveData.mainData.menuLockData = CreateMenuLockData (PlayerMenus.GetMenus ()); saveData.mainData.menuElementVisibilityData = CreateMenuElementVisibilityData (PlayerMenus.GetMenus ()); saveData.mainData.menuJournalData = CreateMenuJournalData (PlayerMenus.GetMenus ()); string mainData = ""; string levelData = ""; if (SaveSystem.GetSaveMethod () == SaveMethod.XML) { mainData = Serializer.SerializeObjectXML <SaveData> (saveData); levelData = Serializer.SerializeObjectXML <List<SingleLevelData>> (levelStorage.allLevelData); } else { mainData = Serializer.SerializeObjectBinary (saveData); levelData = Serializer.SerializeObjectBinary (levelStorage.allLevelData); } string allData = mainData + "||" + levelData; Serializer.CreateSaveFile (GetSaveFileName (saveID), allData); #if !UNITY_WEBPLAYER if (settingsManager.takeSaveScreenshots) { StartCoroutine ("TakeScreenshot", GetSaveScreenshotName (saveID)); } else { GatherSaveFiles (); } #else GatherSaveFiles (); #endif } else { if (playerInput == null) { Debug.LogWarning ("Save failed - no PlayerInput found."); } if (runtimeInventory == null) { Debug.LogWarning ("Save failed - no RuntimeInventory found."); } if (sceneChanger == null) { Debug.LogWarning ("Save failed - no SceneChanger found."); } if (settingsManager == null) { Debug.LogWarning ("Save failed - no Settings Manager found."); } } }