예제 #1
0
    // Update is called once per frame
    void FixedUpdate()
    {
        currentDSPTime = (float)AudioSettings.dspTime;

        if (nextBeatDSPTime == 0f)
        {
            //use this to initialize the beat
            nextBeatDSPTime = (float)Clock.Instance.AtNextBeat();
        }
        if (currentDSPTime > nextBeatDSPTime - (float)Clock.Instance.SixteenthLength() &&
            currentDSPTime < nextBeatDSPTime + (float)Clock.Instance.SixteenthLength())
        {
            //check if we're in the window

            withinWindow = true;
        }

        if (withinWindow && currentDSPTime >= nextBeatDSPTime && !nextBeatCued)
        {
            //events to be called immedately after crossing beat
            //this should happen as close to the beat as possible - maybe use
            //clock sync function instead?

            //update the next beat in songManager

            songManager.currentBeat++;
            songManager.CueNextObstacles(nextBeatDSPTime + Clock.Instance.QuarterLength());
            nextBeatCued = true;
        }
        if (withinWindow && currentDSPTime >= nextBeatDSPTime + (float)Clock.Instance.SixteenthLength())
        {
            //At window End
            withinWindow = false;

            //Evaluate our inputs
            EvaluateWindow(playerController.triggersPressedThisWindow, songManager.triggersRequired);

            //reset the beat
            nextBeatDSPTime = (float)Clock.Instance.AtNextBeat();
            nextBeatCued    = false;

            //Clear out input cache
            playerController.triggersPressedThisWindow.Clear();
            songManager.triggersRequired.Clear();

            //clear out current note list
            songManager.currentNotes.Clear();
        }

        //failsafe for resetting next beat

        if (!withinWindow)
        {
            nextBeatDSPTime = (float)Clock.Instance.AtNextBeat();
        }
    }