Ejemplo n.º 1
0
        /// <summary>
        /// Stop playing the sound
        /// </summary>
        public void Stop()
        {
            if (!_isPlaying)
            {
                return;
            }
            _isPaused  = false;
            _isPlaying = false;
            if (_update != null)
            {
                StopCoroutine(_update);
                _update = null;
            }

            MainMultiAudioListener.OnVirtualAudioListenerAdded   -= VirtualAudioListenerAdded;
            MainMultiAudioListener.OnVirtualAudioListenerRemoved -= VirtualAudioListenerRemoved;

            //Remove all old subAudio
            foreach (var subAudioSource in _subAudioSources)
            {
                if (subAudioSource.Value != null)
                {
                    MainMultiAudioListener.EnquequeAudioSourceInPool(subAudioSource.Value);
                }
            }
            _subAudioSources.Clear();

            if (_safetyAudioSource != null)
            {
                _safetyAudioSource.Stop();
            }
        }
Ejemplo n.º 2
0
        private void VirtualAudioListenerRemoved(VirtualMultiAudioListener virtualAudioListener)
        {
            var audioSource = _subAudioSources[virtualAudioListener];

            _subAudioSources.Remove(virtualAudioListener);

            if (audioSource != null)
            {
                MainMultiAudioListener.EnquequeAudioSourceInPool(audioSource);
            }
        }
Ejemplo n.º 3
0
 private void Start()
 {
     if (!_createdByManager)
     {
         //If manually placed in the scene. Remove the manager spawned one
         if (_main != null)
         {
             Destroy(_main.gameObject);
         }
         _main = this;
     }
 }
Ejemplo n.º 4
0
        private static void CreateMainMultiAudioListener()
        {
            GameObject mainMultiAudioListener = new GameObject("MainMultiAudioListener");

            _main = mainMultiAudioListener.AddComponent <MainMultiAudioListener>();
    #if !ShowMultiAudioListenerInHierachy
            //We hide the sub audio source in hierarchy so that it doesn't flood it
            _main.gameObject.hideFlags = HideFlags.HideInHierarchy;
    #endif

            _main._createdByManager = true;
        }
Ejemplo n.º 5
0
        private void OnDestroy()
        {
            //Stop all sounds and destroy the safety audio source
            if (_isPlaying)
            {
                Stop();
            }

            if (_safetyAudioSource != null)
            {
                MainMultiAudioListener.EnquequeAudioSourceInPool(_safetyAudioSource);
            }
        }
Ejemplo n.º 6
0
        private AudioSource CreateAudioSource(int timeSamples, string nameSubAudioSource, ref bool hardwareChannelsLeft)
        {
            AudioSource audioSource = MainMultiAudioListener.GetAudioSourceFromPool();

            //If no audiosource was given by pool, make a new one
            if (audioSource == null)
            {
                var subAudioSourceGameObject = new GameObject(nameSubAudioSource);
                audioSource = subAudioSourceGameObject.AddComponent <AudioSource>();
            }
            else
            {
                audioSource.gameObject.name = nameSubAudioSource;
            }
#if !ShowSubAudioSourcesInHierachy
            //We hide the sub audio source in hierarchy so that it doesn't flood it
            audioSource.gameObject.hideFlags = HideFlags.HideInHierarchy;
#endif

            SetAllValuesAudioSource(audioSource);

            if (_isPlaying && hardwareChannelsLeft)
            {
                audioSource.Play();
                //If this sound gets culled all following will be too
                if (!audioSource.isPlaying)
                {
                    hardwareChannelsLeft = false;
                }
            }
            if (_isPaused)
            {
                audioSource.Pause();
            }
            audioSource.timeSamples = timeSamples;

            //All audio should be fully 3d
            audioSource.spatialBlend = 1.0f;
            return(audioSource);
        }
Ejemplo n.º 7
0
 private void OnDisable()
 {
     MainMultiAudioListener.RemoveVirtualAudioListener(this);
 }
Ejemplo n.º 8
0
 private void OnEnable()
 {
     MainMultiAudioListener.AddVirtualAudioListener(this);
 }