示例#1
0
    public static IEnumerator StartMetronome()
    {
        Metronome.secondsBetweenBeats = 60.0f / Metronome.beatsPerMinute;
        Metronome.secondsBetweenSteps = Metronome.secondsBetweenBeats / Metronome.stepsPerBeat;

        Metronome.nextBeatTime = AudioSettings.dspTime;

        Metronome.metronomeStarted = true;

        while (true)
        {
            double curTime = AudioSettings.dspTime;
            if (curTime >= nextBeatTime)
            {
                if (Metronome.OnStep != null)
                {
                    Metronome.OnStep();
                }

                Metronome.nextBeatTime += Metronome.secondsBetweenSteps;
            }

            yield return(null);
        }
    }