コード例 #1
0
        public virtual async UniTask <GameStateMap> LoadGameAsync(string slotId)
        {
            if (string.IsNullOrEmpty(slotId) || !GameSlotManager.SaveSlotExists(slotId))
            {
                throw new Exception($"Slot '{slotId}' not found when loading '{typeof(GameStateMap)}' data.");
            }

            var quick = slotId.EqualsFast(LastQuickSaveSlotId);

            OnGameLoadStarted?.Invoke(new GameSaveLoadArgs(slotId, quick));

            if (Configuration.LoadStartDelay > 0)
            {
                await UniTask.Delay(TimeSpan.FromSeconds(Configuration.LoadStartDelay));
            }

            Engine.Reset();
            await Resources.UnloadUnusedAssets();

            var state = await GameSlotManager.LoadAsync(slotId);

            await LoadAllServicesFromStateAsync <IStatefulService <GameStateMap>, GameStateMap>(state);

            // All the serialized snapshots are expected to allow player rollback.
            RollbackStack?.OverrideFromJson(state.RollbackStackJson, s => s.AllowPlayerRollback());

            await PerformOnGameDeserializeTasksAsync(state);

            OnGameLoadFinished?.Invoke(new GameSaveLoadArgs(slotId, quick));

            return(state);
        }
コード例 #2
0
        public virtual async UniTask <GameStateMap> SaveGameAsync(string slotId)
        {
            var quick = slotId.StartsWithFast(Configuration.QuickSaveSlotMask.GetBefore("{"));

            OnGameSaveStarted?.Invoke(new GameSaveLoadArgs(slotId, quick));

            var state = new GameStateMap();
            await scriptPlayer.SynchronizeAndDoAsync(DoSaveAfterSync);

            OnGameSaveFinished?.Invoke(new GameSaveLoadArgs(slotId, quick));

            return(state);

            async UniTask DoSaveAfterSync()
            {
                state.SaveDateTime = DateTime.Now;
                state.Thumbnail    = cameraManager.CaptureThumbnail();

                SaveAllServicesToState <IStatefulService <GameStateMap>, GameStateMap>(state);
                PerformOnGameSerializeTasks(state);
                state.RollbackStackJson = SerializeRollbackStack();

                await GameSlotManager.SaveAsync(slotId, state);

                // Also save global state on every game save.
                await SaveGlobalAsync();
            }
        }
コード例 #3
0
        public virtual async UniTask <GameStateMap> QuickSaveAsync()
        {
            // Free first quick save slot by shifting existing ones by one.
            for (int i = Configuration.QuickSaveSlotLimit; i > 0; i--)
            {
                var curSlotId  = Configuration.IndexToQuickSaveSlotId(i);
                var prevSlotId = Configuration.IndexToQuickSaveSlotId(i + 1);
                GameSlotManager.RenameSaveSlot(curSlotId, prevSlotId);
            }

            // Delete the last slot in case it's out of the limit.
            var outOfLimitSlotId = Configuration.IndexToQuickSaveSlotId(Configuration.QuickSaveSlotLimit + 1);

            if (GameSlotManager.SaveSlotExists(outOfLimitSlotId))
            {
                GameSlotManager.DeleteSaveSlot(outOfLimitSlotId);
            }

            var firstSlotId = string.Format(Configuration.QuickSaveSlotMask, 1);

            return(await SaveGameAsync(firstSlotId));
        }