コード例 #1
0
ファイル: StageDirector.cs プロジェクト: brandonbeamer/ascend
    private IEnumerator DoLevelTransitionCR()
    {
        Animator levelNumAnim = lntm.GetComponent <Animator>();
        Animator quoteAnim    = qtm.GetComponent <Animator>();
        Animator gpmAnim      = gpm.GetComponent <Animator>();

        bool wait = false; // will be used for nexted coroutines

        // pick up the pace
        SimulatedCameraVelocity = new Vector3(0, 50, 0);
        bgn.volume = 1f;

        // ask any sparkles to leave
        foreach (SparkleMotion s in FindObjectsOfType <SparkleMotion>())
        {
            s.Leave();
        }

        if (GameManager.Instance.PlayerLevel != 1)
        {
            escapePanel.SetActive(true);
        }

        // either fade in or chill for a moment
        if (sceneIntroFlag)
        {
            //sceneIntroFlag = false;
            curtainAnimator.SetTrigger("FadeIn");
            float masterlevel;
            if (!mixer.GetFloat("MasterLevel", out masterlevel))
            {
                Debug.LogError("Couldn't get master sound level.");
            }

            AnimationCurve volCurve = new AnimationCurve();
            volCurve.AddKey(new Keyframe(0, -80f));
            volCurve.AddKey(new Keyframe(1, 0f));
            float volCurveStart = Time.time;

            while (Time.time - volCurveStart < 1f)
            {
                mixer.SetFloat("MasterLevel", volCurve.Evaluate(Time.time - volCurveStart));
                yield return(null);
            }
        }
        else
        {
            yield return(new WaitForSeconds(2f));
        }

        // once the curtains are up (fade in complete)
        while (!curtainAnimator.GetCurrentAnimatorStateInfo(0).IsName("Up"))
        {
            yield return(null);
        }

        // show the level number text
        levelNumAnim.SetTrigger("FadeIn");     // Text fades in
        //quoteAnim.SetTrigger("FadeIn");

        yield return(null);                      // wait a frame so the keydown bullshit doesn't happen

        // wait or keypress
        waitForAnyKeyFlag = true;                               // Player must press a key to start gameplay
        //butNotEsc = true;                                       // Don't treat Esc as an "any key"
        escapeToLeave = true;                                   // allow player to leave by pressing escape
        while (waitForAnyKeyFlag)
        {
            yield return(null);
        }

        waitForAnyKeyFlag = false;
        escapeToLeave     = false;

        // turn off the escape to leave notification
        escapePanel.SetActive(false);

        // fade out
        levelNumAnim.SetTrigger("FadeOut");     // Text fades out
        //quoteAnim.SetTrigger("FadeOut");


        while (!levelNumAnim.GetCurrentAnimatorStateInfo(0).IsName("Ready")) // Wait for fade out to complete
        {
            yield return(null);
        }


        // after fade, branch depending on whether player decided to leave
        if (!playerLeaving)
        {
            // if not leaving, start a new level
            lm.StartNewLevel();                                              // the game panel watches for play states on its own

            while (!gpmAnim.GetCurrentAnimatorStateInfo(0).IsName("Active")) // wait for game panel to be fully on screen
            {
                yield return(null);
            }

            // slow down camera when gameplay starts
            SimulatedCameraVelocity = new Vector3(0, 1, 0);                 // slow down the camera for the next level
            bgn.volume = 0.5f;
        }
        else
        {
            // if player is leaving
            // fade out
            curtainAnimator.SetTrigger("FadeOut");
            yield return(null);                                                    // wait for animator to start

            while (!curtainAnimator.GetCurrentAnimatorStateInfo(0).IsName("Down")) // wait for fadeout to complete
            {
                yield return(null);
            }

            // after fade, go to menu
            SceneManager.LoadScene(0); // main menu
            yield break;
        }


        // Do tutorial
        if (sceneIntroFlag && GameManager.Instance.ShowTutorial)
        {
            wait = true;
            StartCoroutine(DoTutorial(x => wait = !x));
            while (wait)
            {
                yield return(null);
            }
        }

        sceneIntroFlag = false;
    }