Пример #1
0
        /// <summary>
        /// Initializes save/load operation system for specified operation type.
        /// </summary>
        /// <param name="opType">The type of operation to initialize</param>
        private void initializeOperation(eOperationStatus opType)
        {
            savingInProgress        = false;
            loadingLevelInProgress  = false;
            restoringDataInProgress = false;
            returningToMainMenu     = false;
            currentOperationStatus  = opType;

            switch (opType)
            {
            case eOperationStatus.SAVING_GAME:
                savingInProgress = true;
                resetPlayerLook  = false;
                updateStatusMessage("Saving Game...");
                break;

            case eOperationStatus.LOADING_GAME:
                currentLoadGameStatus   = eLoadGameStatus.LOADING_LAST_SCENE;
                loadingLevelInProgress  = true;
                restoringDataInProgress = true;
                resetPlayerLook         = false;
                // We also want to stop all diary playback if loading a saved game
                FPEInteractionManagerScript.Instance.stopAllDiaryPlayback();
                updateStatusMessage("Loading Scene...");
                break;

            case eOperationStatus.CHANGING_SCENE:
                currentChangeSceneStatus = eChangeSceneStatus.SAVING;
                savingInProgress         = true;
                loadingLevelInProgress   = true;
                restoringDataInProgress  = true;
                resetPlayerLook          = true;
                updateStatusMessage("Changing Scene...");
                break;

            case eOperationStatus.CHANGING_SCENE_NOSAVE:
                currentChangeSceneStatus = eChangeSceneStatus.LOADING_NEXT_SCENE;
                loadingLevelInProgress   = true;
                restoringDataInProgress  = true;
                resetPlayerLook          = true;
                updateStatusMessage("Changing Scene...");
                break;

            case eOperationStatus.RETURN_TO_MAIN_MENU:
                currentChangeSceneStatus = eChangeSceneStatus.LOADING_NEXT_SCENE;
                loadingLevelInProgress   = true;
                returningToMainMenu      = true;
                updateStatusMessage("Returning to Main Menu...");
                break;

            default:
                Debug.LogError("Bad operation type '" + opType + "'");
                break;
            }

            progressSpinner.transform.rotation = Quaternion.identity;
            loadingUIParentCanvas.SetActive(true);

            // Lock player in place and suspend interactions
            FPEInteractionManagerScript.Instance.suspendPlayerAndInteraction();
            FPEInteractionManagerScript.Instance.gameObject.SetActive(false);

            operationStartTime = Time.time;
        }
Пример #2
0
        void Update()
        {
            #region EDITOR_DEBUG_KEYS

#if UNITY_EDITOR
            if (editorDebugKeys)
            {
                // Debug Keys - to simulate menu button actions, etc. //
                if (Input.GetKeyDown(KeyCode.Alpha1))
                {
                    Debug.Log("Debug Key: Save");
                    SaveGame();
                }
                if (Input.GetKeyDown(KeyCode.Alpha2))
                {
                    if (SavedGameExists())
                    {
                        Debug.Log("Debug Key: Load");
                        LoadGame();
                    }
                    else
                    {
                        Debug.Log("Debug Key: Can't do Load, no saved game file was found");
                    }
                }

                if (Input.GetKeyDown(KeyCode.Alpha4))
                {
                    Debug.Log("Debug Key: Start a New Game");
                    StartANewGame();
                }
            }
#endif
            #endregion

            // If any operation is happening, we keep spinning the progress spinner and keep processing until that operation is complete.
            if (currentOperationStatus != eOperationStatus.IDLE)
            {
                // Animate spinner
                progressSpinner.transform.Rotate(new Vector3(0f, 0f, -spinnerRotationRate * Time.deltaTime));

                // Process current state
                if (currentOperationStatus == eOperationStatus.SAVING_GAME)
                {
                    if (savingInProgress == false)
                    {
                        currentOperationStatus = eOperationStatus.UX_WAIT;
                    }
                }

                else if (currentOperationStatus == eOperationStatus.LOADING_GAME)
                {
                    if (currentLoadGameStatus == eLoadGameStatus.LOADING_LAST_SCENE)
                    {
                        if (loadingLevelInProgress == false)
                        {
                            currentLoadGameStatus = eLoadGameStatus.RESTORING_SCENE_DATA;
                            updateStatusMessage("Restoring saved game data...");
                            StartCoroutine(restoreDataForCurrentScene(true));
                        }
                    }

                    else if (currentLoadGameStatus == eLoadGameStatus.RESTORING_SCENE_DATA)
                    {
                        if (restoringDataInProgress == false)
                        {
                            currentLoadGameStatus  = eLoadGameStatus.IDLE;
                            currentOperationStatus = eOperationStatus.UX_WAIT;
                        }
                    }
                }

                else if (currentOperationStatus == eOperationStatus.CHANGING_SCENE)
                {
                    if (currentChangeSceneStatus == eChangeSceneStatus.SAVING)
                    {
                        if (savingInProgress == false)
                        {
                            // When visiting a level for the first time, there won't be any auto-save data
                            // to restore once we load the new scene. As a result, we won't do the usual
                            // data restoration, which includes an operation to clean up lingering pickups
                            // and inventory items. So, if changing scene and auto-saving, we want to
                            // destroy any left over objects in the DontDestoryOnLoad scene.
                            mySaveLoadLogic.removeAllInventoryInWorld(false);
                            mySaveLoadLogic.removeAllPickupsInWorld(false);

                            currentChangeSceneStatus = eChangeSceneStatus.LOADING_NEXT_SCENE;
                            updateStatusMessage("Loading Scene " + destinationSceneIndex + "...");
                            StartCoroutine(loadNewScene(destinationSceneIndex));
                        }
                    }
                    else if (currentChangeSceneStatus == eChangeSceneStatus.LOADING_NEXT_SCENE)
                    {
                        if (loadingLevelInProgress == false)
                        {
                            currentChangeSceneStatus = eChangeSceneStatus.RESTORING_SCENE_DATA;
                            updateStatusMessage("Restoring Data...");
                            StartCoroutine(restoreDataForCurrentScene(false));
                        }
                    }
                    else if (currentChangeSceneStatus == eChangeSceneStatus.RESTORING_SCENE_DATA)
                    {
                        if (restoringDataInProgress == false)
                        {
                            movePlayerToSuitableEntranceOrStartPosition();
                            currentOperationStatus = eOperationStatus.UX_WAIT;
                        }
                    }
                }
                else if (currentOperationStatus == eOperationStatus.CHANGING_SCENE_NOSAVE)
                {
                    if (currentChangeSceneStatus == eChangeSceneStatus.LOADING_NEXT_SCENE)
                    {
                        if (loadingLevelInProgress == false)
                        {
                            currentChangeSceneStatus = eChangeSceneStatus.RESTORING_SCENE_DATA;
                            updateStatusMessage("Restoring Data...");
                            StartCoroutine(restoreDataForCurrentScene(false));
                        }
                    }
                    else if (currentChangeSceneStatus == eChangeSceneStatus.RESTORING_SCENE_DATA)
                    {
                        if (restoringDataInProgress == false)
                        {
                            movePlayerToSuitableEntranceOrStartPosition();
                            currentOperationStatus = eOperationStatus.UX_WAIT;
                        }
                    }
                }
                else if (currentOperationStatus == eOperationStatus.RETURN_TO_MAIN_MENU)
                {
                    if (currentChangeSceneStatus == eChangeSceneStatus.LOADING_NEXT_SCENE)
                    {
                        if (loadingLevelInProgress == false)
                        {
                            currentOperationStatus = eOperationStatus.UX_WAIT;
                        }
                    }
                }
                else if (currentOperationStatus == eOperationStatus.UX_WAIT)
                {
                    if ((Time.time - operationStartTime) > minimumUIDisplayTime)
                    {
                        endOperation();
                    }
                }
            }
        }