コード例 #1
0
    IEnumerator FadePopupMusic(bool inOut)
    {
        if (!initialized)
        {
            Debug.LogError(debugableInterface.debugLabel + "Not initialized !");
            yield break;
        }

        PanelMusic panel = panelMusics.Find(item => { return(item.phase == GetActualGamePhase()); });
        PopupMusic popup = popupMusics.Find(item => { return(item.popup == GetGamePopup()); });

        if (panel == null || !panel.IsValid())
        {
            Debug.LogError(debugableInterface.debugLabel + "There is no audio source for panel " + GetActualGamePhase());
            yield break;
        }

        FadeMusicOut();

        if (popup == null)
        {
            Debug.LogError(debugableInterface.debugLabel + "There is no PopuMusic for popup " + GetGamePopup());
            yield break;
        }

        float step = inOut ? popup.maxVolume / transitionDuration : -popup.maxVolume / transitionDuration;

        while (inOut?popup.source.volume < popup.maxVolume : popup.source.volume > 0)
        {
            popup.SetVolume(popup.GetVolume() + step);

            yield return(null);
        }

        if (inOut)
        {
            popup.SetVolume(popup.maxVolume);
        }
        else
        {
            popup.Init();
        }

        yield break;
    }
コード例 #2
0
    IEnumerator FadePanelMusic(bool inOut, int layer)
    {
        if (!initialized)
        {
            Debug.LogError(debugableInterface.debugLabel + "Not initialized !");
            yield break;
        }

        GamePhase current = inOut? GetNextGamePhase() : GetActualGamePhase();

        PanelMusic panel = panelMusics.Find(item => { return(item.phase == current); });

        if (panel == null || !panel.IsValid())
        {
            Debug.LogError(debugableInterface.debugLabel + "There is no audio source for panel " + current);
            yield break;
        }

        PanelMusic.Layer selectedLayer = panel.layers.Find(item => { return(item.layerIndex == layer); });

        panel.Play(layer);

        float step = inOut ? selectedLayer.maxVolume / transitionDuration : -selectedLayer.maxVolume / transitionDuration;

        while (inOut?selectedLayer.source.volume < selectedLayer.maxVolume : selectedLayer.source.volume > 0)
        {
            selectedLayer.source.volume += step * Time.deltaTime;

            yield return(null);
        }

        if (inOut)
        {
            selectedLayer.source.volume = selectedLayer.maxVolume;
        }
        else
        {
            selectedLayer.source.Stop();
        }

        yield break;
    }