public static void playMainMusic(string soundName) { if (self == null) { Debug.LogError("Need Attack [SoundEx] to a gameObject"); return; } if (self.mainAudio.clip != null && self.mainAudio.clip.name == soundName) { if (SoundEx.musicBgSwitch) { if (!self.mainAudio.isPlaying) { self.mainAudio.Play(); } } else { self.mainAudio.Pause(); } return; } if (SoundEx.musicBgSwitch) { CLSoundPool.borrowObjAsyn(soundName, (Callback)onGetMainMusic); } }
//只能同时播一个音乐/音效 public static void playSoundSingleton(string name, float volume) { if (!soundEffectSwitch) { return; } if (self == null) { Debug.LogError("Need Attack [SoundEx] to a gameObject"); return; } if (self.singletonAudio == null) { Debug.LogError("singletonAudio is Null"); return; } try { self.singletonAudio.loop = false; if (self.singletonAudio.clip != null && self.singletonAudio.clip.name == name) { return; } self.singletonAudio.Stop(); if (!string.IsNullOrEmpty(name)) { CLSoundPool.borrowObjAsyn(name, (Callback)onFinishSetAudio4Singleton); } } catch (System.Exception e) { Debug.LogError(e); } }
/// <summary> /// Plaies the sound.播放音效,可指定同时最大播放次数 /// </summary> /// <param name='soundPath'> /// Sound path. /// </param> /// <param name='volume'> /// Volume. /// </param> /// <param name='maxTimes'> /// Max times.同时最大播放次数 /// </param> public static void playSound(string name, float volume, int maxTimes = 1) { if (!soundEffectSwitch) { return; } if (self == null) { Debug.LogError("Need Attack [SoundEx] to a gameObject"); return; } if (!string.IsNullOrEmpty(name)) { CLSoundPool.borrowObjAsyn(name, (Callback)onFinishSetAudio, maxTimes, null); // AudioClip clip = CLSoundPool.borrowObj (name); // if (clip != null) { // doPlaySound (clip, volume, maxTimes); // } else { // CLSoundPool.borrowObjAsyn (name, (Callback)onFinishSetAudio, maxTimes, null); // } } }