Example #1
0
        public void PlaySound(string _soundName, bool _continueOld = false,
                              float _volume = 1.0f, float _dopplerScale = 1.0f)
        {
            // check if the sound is playing
            if (_continueOld)
            {
                if (m_playingSoundEffectInstance.ContainsKey(_soundName) &&
                    m_playingSoundEffectInstance[_soundName].Count() > 0)
                {
                    return;
                }
            }
            // check if the sound is in free queue
            SoundEffectPack soundEffectPack =
                GetFromFreeQueue(_soundName);

            // not in free queue, create new
            if (soundEffectPack == null)
            {
                soundEffectPack = new SoundEffectPack(_soundName,
                                                      _volume, _dopplerScale);
            }
            UpdateSoundEffectPack(soundEffectPack);
            AddToPlayingQueue(_soundName, soundEffectPack);
            soundEffectPack.m_soundEffectInstance.Play();
        }
Example #2
0
 private void AddToFreeQueue(string _soundName, SoundEffectPack _pack)
 {
     if (!m_freeSoundEffectInstances.ContainsKey(_soundName))
     {
         m_freeSoundEffectInstances.Add(_soundName, new Queue <SoundEffectPack>());
     }
     m_freeSoundEffectInstances[_soundName].Enqueue(_pack);
 }
Example #3
0
 private void AddToPlayingQueue(string _soundName, SoundEffectPack _pack)
 {
     if (!m_playingSoundEffectInstance.ContainsKey(_soundName))
     {
         m_playingSoundEffectInstance.Add(_soundName, new List <SoundEffectPack>());
     }
     m_playingSoundEffectInstance[_soundName].Add(_pack);
 }
Example #4
0
 private SoundEffectPack GetFromFreeQueue(string _soundName)
 {
     if (m_freeSoundEffectInstances.ContainsKey(_soundName) &&
         m_freeSoundEffectInstances[_soundName].Count > 0)
     {
         // fetch the free instance
         SoundEffectPack soundEffectPack =
             m_freeSoundEffectInstances[_soundName].Dequeue();
         if (m_freeSoundEffectInstances[_soundName].Count == 0)
         {
             m_freeSoundEffectInstances.Remove(_soundName);
         }
         return(soundEffectPack);
     }
     else
     {
         return(null);
     }
 }
Example #5
0
        private void UpdateSoundEffectPack(SoundEffectPack _pack)
        {
            AudioEmitter emitter = _pack.m_audioEmiiter;

            emitter.Position = m_gameObject.AbsPosition + Offset;
            VelocityEstimator velocityEstimator =
                m_gameObject.GetComponent(typeof(VelocityEstimator).ToString())
                as VelocityEstimator;

            if (velocityEstimator != null)
            {
                emitter.Velocity = velocityEstimator.Velocity;
            }

            Camera camera = Mgr <Camera> .Singleton;

            _pack.UpdateListener(camera.CameraPosition, camera.Forward,
                                 camera.Up, camera.Velocity);
            _pack.ApplyUpdate();
        }