Пример #1
0
 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);
     }
 }
Пример #2
0
 //只能同时播一个音乐/音效
 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);
     }
 }
Пример #3
0
        static IEnumerator DelayedCallback(AudioClip clip, float time, object callback)
        {
            string cName = "";

            if (clip != null)
            {
                cName = clip.name;
            }
            yield return(new WaitForSeconds(time));

            CLSoundPool.returnObj(cName);
            if (clip != null)
            {
                Utl.doCallback(callback, clip);
            }
        }
Пример #4
0
 public static void stopMainMusic()
 {
     if (self == null)
     {
         Debug.LogError("Need Attack [SoundEx] to a gameObject");
         return;
     }
     if (self.mainAudio.isPlaying)
     {
         self.mainAudio.Pause();
     }
     if (self.mainAudio.clip != null)
     {
         CLSoundPool.returnObj(self.mainAudio.clip.name);
         self.mainAudio.clip = null;
     }
 }
Пример #5
0
 public static void doPlaySound(AudioClip clip, float volume, int maxTimes = 1)
 {
     if (clip == null)
     {
         return;
     }
     try {
         if (playSoundCount [clip.name] == null || (int)(playSoundCount [clip.name]) < maxTimes)
         {
             playSoundCount [clip.name] = (playSoundCount [clip.name] == null ? 1 : (int)(playSoundCount [clip.name]) + 1);
             Callback cb = finishPlaySound;
             PlaySoundWithCallback(clip, volume, cb);
         }
         else
         {
             CLSoundPool.returnObj(clip.name);
         }
     } catch (System.Exception e) {
         Debug.LogError(e);
     }
 }
Пример #6
0
        /// <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);
//				}
            }
        }
Пример #7
0
 public static void doPlayMainMusic(AudioClip clip)
 {
     try {
         if (self.mainAudio.clip != clip)
         {
             if (self.mainAudio.clip != null)
             {
                 CLSoundPool.returnObj(self.mainAudio.clip.name);
             }
             self.mainAudio.Stop();
             self.mainAudio.clip = clip;
             self.mainAudio.Play();
         }
         else
         {
             if (!self.mainAudio.isPlaying)
             {
                 self.mainAudio.Play();
             }
         }
     } catch (System.Exception e) {
         Debug.LogError(e);
     }
 }