private AudioSource FindAudioSource(AudioVoice audioVoice)
        {
            int num = _allocatedList.IndexOf(audioVoice);

            if (num >= 0)
            {
                return(_allocatedList[num]._audioSource);
            }
            return(null);
        }
 public void Free(AudioSource audioSource, bool callStop = false)
 {
     if (audioSource != null)
     {
         AudioVoice audioVoice = FindAudioVoiceFromSource(audioSource);
         if (audioVoice != null && _allocatedList.Remove(audioVoice))
         {
             audioVoice.Stop(_fadeOutTime, callStop);
             _freeingVoicesList.Add(audioVoice);
         }
     }
 }
        public AudioSource Alloc(Component component)
        {
            if (_audioVoicePool == null || _audioVoicePool.Count == 0)
            {
                return(null);
            }
            AudioVoice audioVoice = _audioVoicePool.Dequeue();

            if (audioVoice == null)
            {
                return(null);
            }
            _allocatedList.Add(audioVoice);
            Generic.SetGameObjectActive(audioVoice.gameObject, active: true);
            audioVoice.Set(component, _fadeInTime);
            return(audioVoice._audioSource);
        }
 public void CreateVoicePool(int count)
 {
     for (int i = 0; i < count; i++)
     {
         GameObject gameObject     = null;
         AudioVoice audioVoice     = null;
         bool       addAudioSource = true;
         if (FabricManager.Instance._VRAudioManager != null && FabricManager.Instance._VRAudioManager._vrSolutions.Count > 0)
         {
             gameObject = FabricManager.Instance._VRAudioManager.GetAudioSource();
             if ((bool)gameObject)
             {
                 addAudioSource = false;
             }
             else
             {
                 gameObject = new GameObject();
             }
         }
         else
         {
             gameObject = new GameObject();
         }
         gameObject.name = "AudioVoice_" + i;
         audioVoice      = gameObject.AddComponent <AudioVoice>();
         if (audioVoice == null || gameObject == null)
         {
             DebugLog.Print("Failed to allocate audio source in the pool!", DebugLevel.Error);
             break;
         }
         audioVoice.Init(addAudioSource);
         audioVoice.transform.parent = base.transform;
         Generic.SetGameObjectActive(audioVoice.gameObject, active: false);
         _audioVoicePool.Enqueue(audioVoice);
     }
 }
 public void Update()
 {
     if (_freeingVoicesList != null)
     {
         for (int i = 0; i < _freeingVoicesList.Count; i++)
         {
             AudioVoice audioVoice = _freeingVoicesList[i];
             audioVoice.UpdateInternal();
             if (!audioVoice.IsPlaying())
             {
                 Generic.SetGameObjectActive(audioVoice.gameObject, active: false);
                 _freeingVoicesList.Remove(audioVoice);
                 _audioVoicePool.Enqueue(audioVoice);
             }
         }
     }
     if (_allocatedList != null)
     {
         for (int j = 0; j < _allocatedList.Count; j++)
         {
             _allocatedList[j].UpdateInternal();
         }
     }
 }