コード例 #1
0
    void Update()
    {
        m_PlayState = RadioManager.Instance.PlayState;
        if (m_PlayState == RadioManager.SoundPlayState.Playing || (m_PlayState == RadioManager.SoundPlayState.Pause || m_PlayState == RadioManager.SoundPlayState.Stop && !m_UpdatePlayProgress))
        {
            float totalTime = RadioManager.Instance.TotalTime;
            float curTime   = m_UpdatePlayProgress? RadioManager.Instance.CurTime: Mathf.Clamp01(m_PlayingSlider.sliderValue) * totalTime;

            if (m_UpdatePlayProgress)
            {
                m_PlayingSlider.sliderValue = totalTime <= 0 ? 0 : curTime / totalTime;
            }
            if (totalTime < 3600)
            {
                m_PlayingLb.text = string.Format("{0:D2}:{1:D2}/{2:D2}:{3:D2}", (int)curTime / 60, (int)curTime % 60, (int)totalTime / 60, (int)totalTime % 60);
            }
            else
            {
                m_PlayingLb.text = string.Format("{0:D2}:{1:D2}:{2:D2}/{3:D2}:{4:D2}:{5:D2}", (int)curTime / 3600, (int)curTime / 60, (int)curTime % 60, (int)totalTime / 3600, (int)totalTime / 60, (int)totalTime % 60);
            }
        }

        PlotSpectrum();
    }
コード例 #2
0
    void Init()
    {
        SetGraphShapeType(GraphPlotter.GraphShapeType.Grid);
        m_UpdateSpectrum = false;
        m_PlayState      = RadioManager.SoundPlayState.Stop;
        m_LerpT          = 0f;
        m_StartTime      = Time.realtimeSinceStartup;

        m_Plotter = new GraphPlotter();
        m_Plotter.TextureWidth  = m_SpectrumWidth;
        m_Plotter.TextureHeight = m_SpectrumHeight;

        m_TopNextCol        = m_RandomCols[0];
        m_BottomNextCol     = m_RandomCols[1];
        m_SpectrumTopCol    = m_TopNextCol;
        m_SpectrumBottomCol = m_BottomNextCol;

        m_PlayingSlider.sliderValue = 0f;
        m_VolumeSlider.sliderValue  = 1f;

        m_UpdatePlayProgress = true;

        m_PlayModePL.items.Clear();
        m_PlayModeDic = new Dictionary <string, RadioManager.SoundPlayMode>();
        m_PlayModeDic[PELocalization.GetString(8000972)] = RadioManager.SoundPlayMode.Single;
        m_PlayModeDic[PELocalization.GetString(8000973)] = RadioManager.SoundPlayMode.SingleLoop;
        m_PlayModeDic[PELocalization.GetString(8000974)] = RadioManager.SoundPlayMode.Order;
        m_PlayModeDic[PELocalization.GetString(8000975)] = RadioManager.SoundPlayMode.ListLoop;
        m_PlayModeDic[PELocalization.GetString(8000976)] = RadioManager.SoundPlayMode.Random;

        m_PlayModePL.items.AddRange(m_PlayModeDic.Keys.ToArray());
        m_PlayModePL.selection = PELocalization.GetString(8000975);

        m_PlayModePL.onSelectionChange = (item) =>
        {
            if (m_PlayModeDic.ContainsKey(item))
            {
                RadioManager.Instance.PlayMode = m_PlayModeDic[item];
            }
        };


        string str = PELocalization.GetString(8000970);

        m_Shape0Lb.text = string.Format("{0} 1", str);
        m_Shape1Lb.text = string.Format("{0} 2", str);
        m_Shape2Lb.text = string.Format("{0} 3", str);

        m_ListItemPools = new Queue <UIListItem>();
        m_CurListItems  = new List <UIListItem>();

        if (null != m_UISpectrumTex)
        {
            m_SpectrumTex2d = new Texture2D(m_SpectrumWidth, m_SpectrumHeight, TextureFormat.ARGB32, false);
            m_UISpectrumTex.transform.localScale = new Vector3(m_SpectrumWidth, m_SpectrumHeight, 1);
            m_SpectrumTex2d.wrapMode             = TextureWrapMode.Clamp;
            m_SpectrumTex2d.filterMode           = FilterMode.Point;
            m_SpectrumTex2d.anisoLevel           = 0;
            m_UISpectrumTex.mainTexture          = m_SpectrumTex2d;
            m_SpectrumTexClos = m_SpectrumTex2d.GetPixels32();
        }

        UIEventListener.Get(m_StartOrPauseBtn.gameObject).onClick = (go) =>
        {
            if (null != RadioManager.Instance)
            {
                if (m_PlayState == RadioManager.SoundPlayState.Playing)
                {
                    RadioManager.Instance.PauseCurSound();
                }
                else
                {
                    RadioManager.Instance.ContinueCurSound();
                }
            }
        };

        UIEventListener.Get(m_NextBtn.gameObject).onClick = (go) =>
        {
            if (null != RadioManager.Instance)
            {
                RadioManager.Instance.PlayNextSound();
            }
        };

        UIEventListener.Get(m_PreviousBtn.gameObject).onClick = (go) =>
        {
            if (null != RadioManager.Instance)
            {
                RadioManager.Instance.PlayPreviousSounds();
            }
        };

        m_VolumeSlider.onValueChange += (val) =>
        {
            if (null != RadioManager.Instance)
            {
                RadioManager.Instance.SetVolume(m_VolumeSlider.sliderValue);
            }
            ;
        };

        UIEventListener.Get(m_PlayingSlider.gameObject).onPress += (go, isPress) =>
        {
            if (isPress)
            {
                m_UpdatePlayProgress = false;
            }
            else
            {
                RadioManager.Instance.SetTime(Mathf.Clamp01(m_PlayingSlider.sliderValue) * RadioManager.Instance.TotalTime);
                m_UpdatePlayProgress = true;
            }
        };

        UIEventListener.Get(m_PlayingSlider.thumb.gameObject).onPress += (go, isPress) =>
        {
            if (isPress)
            {
                m_UpdatePlayProgress = false;
            }
            else
            {
                RadioManager.Instance.SetTime(Mathf.Clamp01(m_PlayingSlider.sliderValue) * RadioManager.Instance.TotalTime);
                m_UpdatePlayProgress = true;
            }
        };

        m_OpenBgMusicCK.startsChecked = true;
        m_OpenBgMusicCK.onStateChange = (isCheck) =>
        {
            RadioManager.Instance.SetBgMusicState(isCheck);
        };

        RadioManager.Instance.PlayErrorEvent = null;
    }