Example #1
0
        /// <summary>
        /// Sets the slot, but does not save the data in the previous slot. This is useful if you want to
        /// save the active game to a new save slot. Like in older games such as Half-Life.
        /// </summary>
        /// <param name="slot"> Slot to switch towards, and copy the current save to </param>
        /// <param name="saveGame"> Set this if you want to overwrite a specific save file </param>
        public static void SetSlotAndCopyActiveSave(int slot)
        {
            OnSlotChangeBegin.Invoke(slot);

            activeSlot     = slot;
            activeSaveGame = SaveFileUtility.LoadSave(slot, true);

            SyncReset();
            SyncSave();

            OnSlotChangeDone.Invoke(slot);
        }
Example #2
0
        /// <summary>
        /// Set the active save slot. (Do note: If you don't want to auto save on slot switch, you can change this in the save setttings)
        /// </summary>
        /// <param name="slot"> Target save slot </param>
        /// <param name="reloadSaveables"> Send a message to all saveables to load the new save file </param>
        public static void SetSlot(int slot, bool reloadSaveables, SaveGame saveGame = null)
        {
            if (activeSlot == slot && saveGame == null)
            {
                Debug.LogWarning("Already loaded this slot.");
                return;
            }

            // Ensure the current game is saved, and write it to disk, if that is wanted behaviour.
            if (SaveSettings.Get().autoSaveOnSlotSwitch&& activeSaveGame != null)
            {
                WriteActiveSaveToDisk();
            }

            if (SaveSettings.Get().cleanSavedPrefabsOnSlotSwitch)
            {
                ClearActiveSavedPrefabs();
            }

            if (slot < 0 || slot > SaveSettings.Get().maxSaveSlotCount)
            {
                Debug.LogWarning("SaveMaster: Attempted to set illegal slot.");
                return;
            }

            OnSlotChangeBegin.Invoke(slot);

            activeSlot     = slot;
            activeSaveGame = (saveGame == null) ? SaveFileUtility.LoadSave(slot, true) : saveGame;

            if (reloadSaveables)
            {
                SyncLoad();
            }

            SyncReset();

            PlayerPrefs.SetInt("SM-LastUsedSlot", slot);

            OnSlotChangeDone.Invoke(slot);
        }