using UnityEngine;
public class CSoundControl : MonoBehaviour
{
public UISlider musicSlider;
public UISlider soundSlider;
void Start()
{
UIEventListener.Get(soundSlider.gameObject).onPress += OnSoundReleased;
UIEventListener.Get(musicSlider.gameObject).onPress += OnMusicReleased;
if (musicSlider != null)
{
musicSlider.sliderValue = GenericService.GetMusicVolume();
if(CMusic.instance!=null){
CMusic.instance.Play(MusicType.Game,musicSlider.sliderValue);
}
}
if (soundSlider != null)
{
soundSlider.sliderValue = GenericService.GetSoundVolume();
}
musicSlider.ForceUpdate();
}
void OnMusicVolume() //musicSlider function - event
{
if (CMusic.instance != null && musicSlider != null)
CMusic.instance.SetVolume(musicSlider.sliderValue);
}
void OnSoundVolume() { } //soundSlider function - event
void OnSoundReleased(GameObject go, bool pSet)
{
if (pSet != true)
{
if (CSound.instance != null)
{
CSound.instance.SetVolume(soundSlider.sliderValue);
CSound.instance.Play(soundSlider.sliderValue);
}
GenericService.SetSoundVolume(soundSlider.sliderValue);
}
}
void OnMusicReleased(GameObject go, bool pSet)
{
if( pSet!=true ){
GenericService.SetMusicVolume( musicSlider.sliderValue );
if(CMusic.instance!=null )
if( !CMusic.instance.IsPlayaing() )
CMusic.instance.Play(MusicType.Menu,GenericService.GetMusicVolume() );
}
}
}