Пример #1
0
    // Load a game save including all essential positions and parameters.
    public void LoadGame()
    {
        // If the fight has started already.
        if (isCheckpointReached == true)
        {
            // Check for a temporary game save.
            if (File.Exists(Application.persistentDataPath + "/tmp_gamesave.save"))
            {
                // Load the data from file to a game save instance.
                BinaryFormatter bf   = new BinaryFormatter();
                FileStream      file = File.Open(Application.persistentDataPath + "/tmp_gamesave.save", FileMode.Open);
                GameSave        save = (GameSave)bf.Deserialize(file);
                file.Close();

                // Disable the player's controllers.
                cController.enabled = false;
                //fpController.enabled = false;
                fpController.isLoading = false;
                // Load the player's essential positions and parameters.
                playerTrnsfrm.position   = new Vector3(save.playerPos.x, save.playerPos.y, save.playerPos.z);
                playerTrnsfrm.rotation   = new Quaternion(save.playerRot.x, save.playerRot.y, save.playerRot.z, save.playerRot.w);
                playerHeroRef.heroHealth = save.playerHealth;
                // Enable the player's controllers.
                cController.enabled = true;
                //fpController.enabled = true;
                fpController.isLoading = true;

                // Load the spider's essential positions and parameters.
                spiderTrnsfrm.position        = new Vector3(save.spiderPos.x, save.spiderPos.y, save.spiderPos.z);
                spiderTrnsfrm.rotation        = new Quaternion(save.spiderRot.x, save.spiderRot.y, save.spiderRot.z, save.spiderRot.w);
                spiderRef.spiderState         = save.spiderState;
                spiderRef.spiderHealth        = save.spiderHealth;
                spiderRef.isVulnerable        = save.isVulnerable;
                spiderRef.didReachCenter      = save.didReachCenter;
                spiderRef.didHitWall          = save.didHitWall;
                spiderRef.isExitingIdle       = save.isExitingIdle;
                spiderRef.isDeadAnimTriggered = save.isDeadAnimTriggered;

                // Indicate the fight is restarting and init the fight and switch parameters.
                if (FightManager.CREndFightEffects != null)
                {
                    StopCoroutine(FightManager.CREndFightEffects);
                }
                FightManager.isFightRestarting = true;
                FightManager.lastDelayTime     = 0.0f;
                FightManager.isFightEnded      = false;
                FightManager.endFightTimer     = 0.0f;
                FightManager.endFightSM        = FightManager.endFightState.EFFECTS1;
                FightManager.StopEndGameEffects();
                FightManager.isEffects1Called = false;
                FightManager.isEffects2Called = false;
                FightManager.isEffects3Called = false;
                if (switchStartFight.IncreaseLightIntensityCR != null)
                {
                    StopCoroutine(switchStartFight.IncreaseLightIntensityCR);
                }
                if (switchStartFight.SpiderHealthRegenCR != null)
                {
                    StopCoroutine(switchStartFight.SpiderHealthRegenCR);
                }
                if (switchStartFight.AudioSpiderWakeCR != null)
                {
                    StopCoroutine(switchStartFight.AudioSpiderWakeCR);
                }
                switchStartFight.gameObject.SetActive(true);
                switchStartFight.isFightStarted = false;
                switchStartFight.LEDs.gameObject.SetActive(true);
                switchStartFight.spiderLightP1.SetActive(false);
                switchStartFight.distortion.SetActive(false);
                switchStartFight.isFinishedLightingUp  = false;
                switchStartFight.didReachMaxGlow       = false;
                switchStartFight.lightSource.intensity = 0.0f;
                switchStartFight.spiderHUD.SetActive(false);
                switchStartFight.isRegenStarted    = false;
                switchStartFight.redGlow.intensity = 0.0f;
                switchStartFight.hasPlayedWake2    = false;
                switchStartFight.countAudio        = 0;
                switchStartFight.walkAudioTimer    = 1.8f;
                switchDestroySS2.isTriggered       = false;
                if (screenFade.CRFadeIn != null)
                {
                    StopCoroutine(screenFade.CRFadeIn);
                }
                screenFade.SetTransparent();
                screenFade.gameObject.SetActive(false);
                isCreditsOn = false;
                creditsRoll.Stop();
                creditsRoll.outlineSpeed = 0.2f;
                creditsRoll.gameObject.SetActive(false);

                // Play the appropriate background music.
                audioManager.PlayTrack(0);
                audioManager.LoopOn();
                // Increase the game Audio volume.
                audioManager.IncreaseGlobalAudio();
            }
            else
            {
                Debug.Log("No game saved!");
            }
        }
        else
        {
            // Re-load the scene.
            SceneManager.LoadScene(SceneManager.GetActiveScene().name);
        }
    }