Exemplo n.º 1
0
    public void ChangeStage(RoundManager.RoundStage stage)
    {
        if (changeStyle == ChangeStyle.CROSS_FADE)
        {
            oldVolume = audio.volume;
            timer     = 0;
        }

        targetVolume = baseVolume;
        foreach (RoundVolume roundVolume in roundVolumes)
        {
            if (roundVolume.round == stage)
            {
                targetVolume = roundVolume.volume * baseVolume;
            }
        }
    }
Exemplo n.º 2
0
    void Update()
    {
        if (!init)
        {
            init = true;
            ChangeStage(RoundManager.instance.stage);
        }

        int lastBreak = breakIndex;

        for (int i = 0; i < breakingPoints.Length; ++i)
        {
            if (audio.time > breakingPoints[i].timeIndex)
            {
                breakIndex = i;
            }
        }

        if (lastBreak != breakIndex)
        {
            if (changeStyle == ChangeStyle.WAIT_FOR_END)
            {
                float earlyTime = 0;
                foreach (EarlyTrigger early in breakingPoints[breakIndex].earlyTriggers)
                {
                    if (RoundManager.instance.stage == early.round)
                    {
                        earlyTime = early.earlyTime;
                        break;
                    }
                }
                RoundManager.RoundStage stagePreempt = RoundManager.instance.GetFutureStage(earlyTime);
                ChangeStage(stagePreempt);
            }

            if (changeStyle == ChangeStyle.WAIT_FOR_END)
            {
                audio.volume = targetVolume;
            }

            changeStyle  = breakingPoints[breakIndex].changeStyle;
            fadeDuration = breakingPoints[breakIndex].fadeDuration;
            oldVolume    = audio.volume;
            timer        = 0;
        }

        if (changeStyle == ChangeStyle.CROSS_FADE)
        {
            if (timer < fadeDuration)
            {
                timer += Time.deltaTime;
                if (timer >= fadeDuration)
                {
                    audio.volume = targetVolume;
                }
                else
                {
                    float t = timer / fadeDuration;
                    audio.volume = (1 - t) * oldVolume + t * targetVolume;
                }
            }
        }
    }