Exemplo n.º 1
0
 public void PlayQueuedAudio(PlayConfig c)
 {
     if (m_QueuedAudio.Count == 0)
     {
         m_QueuedAudio.Enqueue(c);
         StartCoroutine(PlayQueuedClipsCoroutine());
     }
     else
     {
         m_QueuedAudio.Enqueue(c);
     }
 }
Exemplo n.º 2
0
        public AudioClipHandle PlayAudio(PlayConfig c)
        {
            if (c == null)
            {
                return(null);
            }
            AudioClipPlayer p = PlayAudioInternal(c);

            if (p == null)
            {
                return(null);
            }
            return(p.Handle);
        }
Exemplo n.º 3
0
        public AudioClipHandle PlayAudio(HelperPlayConfig config)
        {
            if (config.soundId == -1)
            {
                return(null);
            }

            var playConfig = new PlayConfig()
            {
                SoundID        = _audioManagerHelper.AudioEnumToStringId(config.soundId),
                Volume         = config.volume,
                Delay          = config.delay,
                In3D           = config.In3D,
                Position       = config.position,
                TrackTransform = config.trackTransform
            };

            return(PlayAudio(playConfig));
        }
Exemplo n.º 4
0
        private AudioClipPlayer PlayAudioInternal(PlayConfig c)
        {
            if (c == null || string.IsNullOrEmpty(c.SoundID))
            {
                D.AudioWarning("Null config or sound ID: " + (c != null ? c.SoundID : ""));
                return(null);
            }

            if (!m_Leafs.ContainsKey(c.SoundID))
            {
                PlayMissingSound(c.SoundID);
                return(null);
            }

            AudioClip clipToPlay = GetClip(c.SoundID);

            if (clipToPlay == null)
            {
                D.AudioWarning("Null clipToPlay: " + (c != null ? c.SoundID : ""));
                PlayMissingSound(c.SoundID);
                return(null);
            }


            AudioManagerCategory cat = m_Leafs[c.SoundID];
            var closestOutbus        = cat.GetClosestBus();
            //D.AudioLog("Playing sound: " + c.SoundID + " through mixer: " + closestOutbus.name);
            bool startPaused = c.StartPaused.HasValue ? c.StartPaused.Value : false;

            // Skip processing if only allowing for one sound instance.
            float currentTime = Time.time;

            if (!startPaused)
            {
                if (CheckCooldown(cat, currentTime) == false)
                {
                    D.AudioWarning("Skipping sound '" + c.SoundID + "' as it would be played too soon or because it is blocked by some playing category");
                    return(null);
                }
            }

            Vector3?pos = null;

            if (c.Position.HasValue)
            {
                pos = c.Position.Value;
            }

            AudioClipPlayer player = PrepareClip(clipToPlay,
                                                 cat,
                                                 c.Loop.HasValue ? c.Loop.Value : cat.Loop,
                                                 startPaused,
                                                 closestOutbus,
                                                 c.Volume.HasValue ? c.Volume.Value : cat.Volume,
                                                 c.Delay.HasValue ? c.Delay.Value : 0,
                                                 c.In3D.HasValue ? c.In3D.Value : false,
                                                 pos,
                                                 c.MinDistance.HasValue ? c.MinDistance.Value : 1f,
                                                 c.MaxDistance.HasValue ? c.MaxDistance.Value : 500f,
                                                 c.VolumeRolloffMode.HasValue ? c.VolumeRolloffMode.Value : AudioRolloffMode.Logarithmic,
                                                 c.PitchRandomisation.HasValue ? c.PitchRandomisation.Value : cat.PitchRandomizationValue,
                                                 c.TrackTransform,
                                                 c.ReferenceAudioSource);

            //D.AudioLogFormat("Playing sound {0} with delay {1}", c.SoundID, (c.Delay.HasValue ? c.Delay.Value : 0));

            player.SetFilters(cat);

            if (!startPaused)
            {
                UpdateCooldown(cat, currentTime);
                player.PlayDelayed(c.Delay.HasValue ? c.Delay.Value : 0);
            }

#if NN_OCULUS
            if (m_AudioMode == AudioMode.OCULUS_READY)
            {
                ONSPAudioSource tempOculusSource = audio.gameObject.AddComponent <ONSPAudioSource>();
                tempOculusSource.EnableSpatialization = true;
                tempOculusSource.EnableRfl            = true;
                tempOculusSource.Gain = 10;
                tempOculusSource.Near = 0.25f;
                tempOculusSource.Far  = 20000f;
            }
#endif

            if (m_AudioMode == AudioMode.STEREO_CONTROL)
            {
                AddStereoControl(player.AudioSource, cat.StereoPan);
            }

            if ((m_AudioMode == AudioMode.AUDIO_3D || m_AudioMode == AudioMode.OCULUS_READY) && ((c.In3D.HasValue && c.In3D.Value) || (!c.In3D.HasValue)) &&
                !c.ReferenceAudioSource)
            {
                Add3DData(player.AudioSource, m_Preferences.Default3DSettings);
            }

            return(player);
        }
Exemplo n.º 5
0
 public AudioClipHandle PlayAudio(PlayConfig c)
 {
     return(_gam.PlayAudio(c));
 }