Esempio n. 1
0
        public virtual async UniTask <SettingsStateMap> SaveSettingsAsync()
        {
            SaveAllServicesToState <IStatefulService <SettingsStateMap>, SettingsStateMap>(SettingsState);
            await SettingsSlotManager.SaveAsync(Configuration.DefaultSettingsSlotId, SettingsState);

            return(SettingsState);
        }
Esempio n. 2
0
        private async UniTask <SettingsStateMap> LoadSettingsAsync()
        {
            var settingsData = await SettingsSlotManager.LoadOrDefaultAsync(Configuration.DefaultSettingsSlotId);

            await LoadAllServicesFromStateAsync <IStatefulService <SettingsStateMap>, SettingsStateMap>(settingsData);

            return(settingsData);
        }
Esempio n. 3
0
        public StateManager(StateConfiguration config, EngineConfiguration engineConfig, InputManager inputManager)
        {
            this.config       = config;
            this.inputManager = inputManager;

            var allowUserRollback = config.StateRollbackMode == StateRollbackMode.Full || (config.StateRollbackMode == StateRollbackMode.Debug && Debug.isDebugBuild);
            var rollbackCapacity  = allowUserRollback ? Mathf.Max(1, config.StateRollbackSteps) : 1; // One step is reserved for game save operations.

            rollbackStateStack = new StateRollbackStack(rollbackCapacity);

            var savesFolderPath = PathUtils.Combine(engineConfig.GeneratedDataPath, config.SaveFolderName);

            GameStateSlotManager   = new GameStateSlotManager(savesFolderPath, config.SaveSlotMask, config.QuickSaveSlotMask, config.SaveSlotLimit, config.QuickSaveSlotLimit, config.BinarySaveFiles);
            GlobalStateSlotManager = new GlobalStateSlotManager(savesFolderPath, config.DefaultGlobalSlotId, config.BinarySaveFiles);
            SettingsSlotManager    = new SettingsSlotManager(engineConfig.GeneratedDataPath, config.DefaultSettingsSlotId, false);
        }
Esempio n. 4
0
        private async UniTask PerformPostEngineInitializationTasks()
        {
            await LoadSettingsAsync();

            if (!Engine.Initializing)
            {
                return;
            }
            await LoadGlobalAsync();

            if (!Engine.Initializing)
            {
                return;
            }

            if (Configuration.EnableStateRollback)
            {
                InitializeRollback();
            }

            async UniTask LoadSettingsAsync()
            {
                SettingsState = await SettingsSlotManager.LoadOrDefaultAsync(Configuration.DefaultSettingsSlotId);
                await LoadAllServicesFromStateAsync <IStatefulService <SettingsStateMap>, SettingsStateMap>(SettingsState);
            }

            async UniTask LoadGlobalAsync()
            {
                GlobalState = await GlobalSlotManager.LoadOrDefaultAsync(Configuration.DefaultGlobalSlotId);
                await LoadAllServicesFromStateAsync <IStatefulService <GlobalStateMap>, GlobalStateMap>(GlobalState);
            }

            void InitializeRollback()
            {
                scriptPlayer.AddPreExecutionTask(HandleCommandPreExecution);

                rollbackInput = Engine.GetService <IInputManager>().GetRollback();
                if (rollbackInput != null)
                {
                    rollbackInput.OnStart += HandleRollbackInputStart;
                }
            }
        }