示例#1
0
        public virtual async UniTask ResetStateAsync(Type[] exclude, params Func <UniTask>[] tasks)
        {
            OnResetStarted?.Invoke();

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

            scriptPlayer?.Playlist?.ReleaseResources();

            Engine.Reset(exclude);

            await Resources.UnloadUnusedAssets();

            if (tasks != null)
            {
                foreach (var task in tasks)
                {
                    if (task != null)
                    {
                        await task.Invoke();
                    }
                }
            }

            OnResetFinished?.Invoke();
        }
        public async UniTask ResetStateAsync(string[] exclude = null, params Func <UniTask>[] tasks)
        {
            OnResetStarted?.Invoke();

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

            Engine.GetService <IScriptPlayer>()?.Playlist?.ReleaseResources();

            if (exclude != null && exclude.Length > 0)
            {
                Engine.Reset(exclude.Select(typeName => Type.GetType($"Naninovel.{typeName}", true, true)).ToArray());
            }
            else
            {
                Engine.Reset();
            }

            await Resources.UnloadUnusedAssets();

            if (tasks != null)
            {
                foreach (var task in tasks)
                {
                    await task?.Invoke();
                }
            }

            OnResetFinished?.Invoke();
        }
示例#3
0
        public virtual async UniTask <GameStateMap> LoadGameAsync(string slotId)
        {
            if (string.IsNullOrEmpty(slotId) || !GameStateSlotManager.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 GameStateSlotManager.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());

            for (int i = onGameDeserializeTasks.Count - 1; i >= 0; i--)
            {
                await onGameDeserializeTasks[i](state);
            }

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

            return(state);
        }
示例#4
0
        /// <summary>
        /// Resets all the engine services and unloads unused assets; will basically revert to an empty initial engine state.
        /// The operation will invoke default on-load events, allowing to mask the process with a loading screen.
        /// </summary>
        /// <param name="additionalTasks">Additional tasks to perform during the reset (will be performed in order after the reset).</param>
        public async Task ResetStateAsync(params Func <Task>[] additionalTasks)
        {
            OnResetStarted?.Invoke();

            if (config.LoadStartDelay > 0)
            {
                await new WaitForSeconds(config.LoadStartDelay);
            }

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

            if (additionalTasks != null)
            {
                foreach (var task in additionalTasks)
                {
                    await task?.Invoke();
                }
            }

            OnResetFinished?.Invoke();
        }
示例#5
0
        /// <summary>
        /// Loads game state from the specified save slot.
        /// Will reset the engine services and unload unused assets before load.
        /// </summary>
        public async Task <GameStateMap> LoadGameAsync(string slotId)
        {
            if (string.IsNullOrEmpty(slotId) || !GameStateSlotManager.SaveSlotExists(slotId))
            {
                Debug.LogError($"Slot '{slotId}' not found when loading '{typeof(GameStateMap)}' data.");
                return(null);
            }

            var quick = slotId.EqualsFast(LastQuickSaveSlotId);

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

            if (config.LoadStartDelay > 0)
            {
                await new WaitForSeconds(config.LoadStartDelay);
            }

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

            var state = await GameStateSlotManager.LoadAsync(slotId) as GameStateMap;

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

            if (config.StateRollbackMode == StateRollbackMode.Full && config.SavedRollbackSteps > 0)
            {
                rollbackStateStack.OverrideFromJson(state.RollbackStackJson);
            }

            foreach (var task in onGameDeserializeTasks)
            {
                await task(state);
            }

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

            return(state);
        }