Exemple #1
0
 private void OnUpdate(float delta)
 {
     for (int i = mFadingList.Count - 1; i >= 0; i--)
     {
         SfxPlayingData data = mFadingList[i];
         if (data.fadingStatus == eFadingStatus.None)
         {
             mFadingList.RemoveAt(i);
             continue;
         }
         if (data.UpdateFade(delta))
         {
             mFadingList.RemoveAt(i);
         }
     }
     if (!float.IsNaN(mVolumeMusicLimitTimer))
     {
         mVolumeMusicLimitTimer += delta;
         float t = mVolumeMusicLimitTimer * mVolumeMusicLimitDuration;
         if (t >= 1f)
         {
             mVolumeMusicLimitTimer = float.NaN;
         }
         t = Mathf.Sin(Mathf.PI * (Mathf.Clamp01(t) - 0.5f)) * 0.5f + 0.5f;
         mVolumeMusicLimit = Mathf.LerpUnclamped(mVolumeMusicLimitFrom, mVolumeMusicLimitTo, t);
         ApplyMusicVolume(mVolumeMusic);
     }
 }
Exemple #2
0
 private void CacheAudioData(SfxPlayingData data)
 {
     /*if (mCacheList.Contains(data)) {
      *      Log.errt("SoundManager", "SoundManager.CacheAudioSource can't cache again.");
      *      return;
      * }*/
     data.Clear();
     mCacheList.Enqueue(data);
     data.source.gameObject.SetActive(false);
 }
Exemple #3
0
 private void StopAudio(SfxPlayingData data, bool manuallyStop)
 {
     data.StopAudio(manuallyStop);
     if (data.voice && mVoiceList.Remove(data))
     {
         if (mVoiceList.Count <= 0)
         {
             mVolumeMusicLimitFrom     = mVolumeMusicLimit;
             mVolumeMusicLimitTo       = 1f;
             mVolumeMusicLimitDuration = 1f / 0.5f;
             mVolumeMusicLimitTimer    = 0f;
         }
     }
     CacheAudioData(data);
 }
Exemple #4
0
 private bool OnAudioLoaded(SfxPlayingData data, AudioClip clip)
 {
     if (!mLoadingList.Remove(data.id))
     {
         return(false);
     }
     if (clip == null)
     {
         Debug.LogErrorFormat("[SoundManager] Fail to load sfx '{0}{1}' !", data.folder, data.sfx);
         StopAudio(data, true);
         return(false);
     }
     mPlayingList.Add(data.id, data);
     return(true);
 }
Exemple #5
0
        private int PlaySoundInternal(SfxData sfx, bool is3D, Vector3 pos, bool isVoice, AudioMixerGroup group, Action <int> callback)
        {
            if (string.IsNullOrEmpty(sfx.sfx))
            {
                return(-1);
            }
            //Log.dtf("zw", "Play Sound sfxId '{0}' name '{1}' !", sfxId, sfx.sfx);
            SfxPlayingData data = GetAudioData();
            int            id   = ++mIdGen;

            data.Init(id, sfx.folder, sfx.sfx, sfx.volume, isVoice, sfx.fadein, Time.unscaledTime + sfx.delay, callback);
            data.source.transform.position = pos;
            data.source.spatialBlend       = is3D ? 1f : 0f;
            data.source.volume             = sfx.volume;
            data.source.loop = sfx.loop;
            data.source.outputAudioMixerGroup = group;
            if (is3D)
            {
                if (m3DSettings != null)
                {
                    data.source.minDistance = m3DSettings.MinDistance;
                    data.source.maxDistance = m3DSettings.MaxDistance;
                    data.source.SetCustomCurve(AudioSourceCurveType.CustomRolloff, m3DSettings.RollOffCurve);
                    data.source.rolloffMode = AudioRolloffMode.Custom;
                }
                else
                {
                    data.source.minDistance = 1f;
                    data.source.maxDistance = 1000f;
                    data.source.rolloffMode = AudioRolloffMode.Logarithmic;
                }
            }
            if (isVoice)
            {
                mVoiceList.Add(data);
                if (mVoiceList.Count == 1)
                {
                    mVolumeMusicLimitFrom     = mVolumeMusicLimit;
                    mVolumeMusicLimitTo       = 0.2f;
                    mVolumeMusicLimitDuration = 1f / 0.5f;
                    mVolumeMusicLimitTimer    = 0f;
                }
            }
            mLoadingList.Add(data.id, data);
            data.Load();
            return(data.id);
        }
Exemple #6
0
 private SfxPlayingData GetAudioData()
 {
     if (mCacheList.Count > 0)
     {
         SfxPlayingData data = mCacheList.Dequeue();
         data.source.gameObject.SetActive(true);
         return(data);
     }
     else
     {
         GameObject o = new GameObject();
         o.name             = "Audio";
         o.transform.parent = mSoundRoot.transform;
         SfxPlayingData data = new SfxPlayingData(o.AddComponent <AudioSource>());
         data.source.playOnAwake = true;
         data.source.loop        = false;
         data.source.rolloffMode = AudioRolloffMode.Logarithmic;
         data.source.minDistance = 1f;
         data.source.maxDistance = 500f;
         if (mOnAudioLoaded == null)
         {
             mOnAudioLoaded = OnAudioLoaded;
         }
         data.onLoaded = mOnAudioLoaded;
         if (mOnBeginFading == null)
         {
             mOnBeginFading = OnBeginFading;
         }
         data.onBeginFading = mOnBeginFading;
         if (mOnAudioFinished == null)
         {
             mOnAudioFinished = OnAudioFinished;
         }
         data.onAudioFinished = OnAudioFinished;
         return(data);
     }
 }
Exemple #7
0
 private void OnAudioFinished(SfxPlayingData data, bool manuallyStop)
 {
     mPlayingList.Remove(data.id);
     StopAudio(data, manuallyStop);
 }
Exemple #8
0
 private void OnBeginFading(SfxPlayingData data)
 {
     mFadingList.Add(data);
 }