コード例 #1
0
    void Start()
    {
        musicPlayer = new MusicPlayer();

        #region Slider
        progressSlider.value = 0f;
        EventTriggerListener.SetEventTrigger(progressSlider.gameObject).OnMouseDown.AddListener((data) => sliderIsDrag = true);
        EventTriggerListener.SetEventTrigger(progressSlider.gameObject).OnMouseUp.AddListener((data) =>
        {
            musicPlayer.Seek(progressSlider.value);
            sliderIsDrag = false;
        });

        //--volume
        //一开始就设置音量调
        volumeSlider.maxValue = 1f;
        volumeSlider.value    = musicPlayer.GetVolume();
        //需要一直监听
        volumeSlider.onValueChanged.AddListener((value) =>
        {
            musicPlayer.SetVolume(value);
        });


        #endregion

        btnPlay.onClick.AddListener(() =>
        {
            musicPlayer.Play();
            btnPlay.gameObject.SetActive(false);
            btnPause.gameObject.SetActive(true);
        });
        btnPause.onClick.AddListener(() =>
        {
            btnPlay.gameObject.SetActive(true);
            btnPause.gameObject.SetActive(false);
            musicPlayer.Pause();
        });

        if (btnStop != null)
        {
            btnStop.onClick.AddListener(musicPlayer.Stop);
        }
    }