예제 #1
0
    private IEnumerator DoPlaySceneSoundEffect(SoundConfig.MusicElement music)
    {
        AudioSource source = BuildAudioObj(music.name, false);

        source.gameObject.name = "S_" + music.name;

        source.volume = music.volume * (GameDefines.Setting_SoundVol / 100.0f);

        if (music.startDelay > 0)
        {
            yield return(new WaitForSeconds(music.startDelay));
        }
        source.Play();

        Destroy(source.gameObject, source.clip.length * 1.01f);         // a little delay

        float delay = source.clip.length;

        if (music.delay.Equals(0.0f))
        {
            delay += 0.2f;
        }
        else
        {
            delay += music.delay;
        }
        yield return(new WaitForSeconds(delay));

        StartCoroutine(DoPlaySceneSoundEffect(music));
    }
예제 #2
0
    public void PlaySceneSound(string sceneName, bool isPlay = true, bool isLoop = true)
    {
        OnAwakeIsPlay = isPlay;
        SoundIsLoop   = isLoop;
        SoundConfig cfg = Globals.Instance.MDataTableManager.GetConfig <SoundConfig>();

        _mSceneMusicElement = cfg.GetSceneMusicElement(sceneName);
        if (null == _mSceneMusicElement)
        {
            Debug.Log("The sceneName " + sceneName + " cann't find the music config.");
            return;
        }

        if (0 == _mSceneMusicElement.usableMusicList.Count)
        {
            Debug.Log("No have the background sound");
            return;
        }

        int index = Random.Range(0, _mSceneMusicElement.usableMusicList.Count);

        SoundConfig.MusicElement music = _mSceneMusicElement.usableMusicList[index];
        if (null == music)
        {
            return;
        }

        if (_mSceneMusic != null && "BGM_" + music.name == _mSceneMusic.name)
        {
            return;
        }


        // Stop all coroutines running on this behaviour
        StopAllCoroutines();

        PlaySceneBGMusic();
        PlaySceneSoundEffect();
    }
예제 #3
0
    private IEnumerator DoPlaySceneBGMusic()
    {
        Debug.Log("[SoundManager]:Begin DoPlaySceneBGMusic");

        // Random.seed = 1000;
        int index = Random.Range(0, _mSceneMusicElement.usableMusicList.Count);

        SoundConfig.MusicElement music = _mSceneMusicElement.usableMusicList[index];
        if (null == music)
        {
            Debug.Log("Cann't find the music " + music.name);
            yield break;
        }

        Debug.Log("[SoundManager]:music.startDelay is " + music.startDelay);

        if (music.startDelay > 0)
        {
            yield return(new WaitForSeconds(music.startDelay));
        }

        AudioSource source = BuildAudioObj(music.name, SoundIsLoop);

        source.gameObject.name = "BGM_" + music.name;

        _mSceneMusic = source.gameObject;
        while (!source.clip.isReadyToPlay)
        {
            Debug.Log("[SoundManager]:Prepare the sound " + music.name);
            yield return(null);
        }

        source.priority = 128;


        source.volume = music.volume * (GameDefines.Setting_MusicVol / 100.0f);
        //source.volume = 0;

        if (OnAwakeIsPlay)
        {
            source.playOnAwake = true;
            source.Play();
        }
        else
        {
            source.playOnAwake = false;
        }


        CurrentPlayingMusicAudio = source;

        // Debug.Log("[SoundManager]:Begin play the sound " + music.name);
        // Debug.Log("[SoundManager]:source.enabled is " + source.enabled.ToString());
        // Debug.Log("[SoundManager]:source.isPlaying is " + source.isPlaying.ToString());
        // Debug.Log("[SoundManager]:source.loop is " + source.loop.ToString());
        // Debug.Log("[SoundManager]:source.volume is " + source.volume.ToString());
        // Debug.Log("[SoundManager]:source.mute is " + source.mute.ToString());
        // Debug.Log("[SoundManager]:source.pan is " + source.pan.ToString());
        // Debug.Log("[SoundManager]:source.panLevel is " + source.panLevel.ToString());
        // Debug.Log("[SoundManager]:source.pitch is " + source.pitch.ToString());
        // Debug.Log("[SoundManager]:source.priority is " + source.priority.ToString());
        // Debug.Log("[SoundManager]:source.playOnAwake is " + source.playOnAwake.ToString());

//		float delay = source.clip.length;
//		if (music.delay.Equals(0.0f))
//			delay += 0.2f;
//		else
//		    delay += music.delay;
//		yield return new WaitForSeconds(delay);
//
//		if (null != _mSceneMusic)
//		{
//			GameObject.DestroyObject(_mSceneMusic);
//			_mSceneMusic = null;
//		}
//
//		PlaySceneBGMusic();
    }