Пример #1
0
 public void StopAndRelease()
 {
     if (m_Player != null)
     {
         m_Player.ReleaseClip();
         m_Player = null;
     }
 }
Пример #2
0
        public AudioClipHandle PlayAudio(PlayConfig c)
        {
            if (c == null)
            {
                return(null);
            }
            AudioClipPlayer p = PlayAudioInternal(c);

            if (p == null)
            {
                return(null);
            }
            return(p.Handle);
        }
Пример #3
0
        public void SetAudioGroupsPaused(bool paused, List <AudioMixerGroup> includeGroups, List <AudioMixerGroup> excludeGroups)
        {
            foreach (GameObject go in m_AudioClipPlayerPool.RentedObjects)
            {
                if (go == null)
                {
                    continue;
                }

                AudioClipPlayer p = go.GetComponent <AudioClipPlayer>();
                if (p == null)
                {
                    continue;
                }

                AudioClipHandle handle = p.Handle;
                if (handle == null)
                {
                    continue;
                }

                bool shouldAffect = (excludeGroups == null || !excludeGroups.Contains(handle.MixerGroup));
                shouldAffect &= (includeGroups == null || includeGroups.Contains(handle.MixerGroup));

                if (shouldAffect)
                {
                    if (paused)
                    {
                        handle.Pause();
                    }
                    else
                    {
                        handle.UnPause();
                    }
                }
            }
        }
Пример #4
0
 public AudioClipHandle(AudioClipPlayer player)
 {
     m_Player = player;
 }
Пример #5
0
 public void Clear()
 {
     m_Player = null;
 }
Пример #6
0
 public WaitUntilAudioClipStarted(AudioClipPlayer player)
 {
     m_Wait = player != null;
 }
Пример #7
0
 public void ClipPlayerFinishedPlaying(AudioClipPlayer p)
 {
     FreeCooldown(p.Category);
 }
Пример #8
0
        AudioClipPlayer PrepareClip(AudioClip clip, AudioManagerCategory trigger, bool loop = false, bool startPaused = false, AudioMixerGroup outBus = null, float volume = 1.0f, float delay = 0.0f, bool in3D = false, Vector3?position = null, float minDistance = 1f, float maxDistance = 500f, AudioRolloffMode volumeRolloffMode = AudioRolloffMode.Logarithmic, float pitchRandomisation = 0.0f, Transform trackTrans = null, AudioSource referenceAudioSource = null)
        {
            AudioClipPlayer go = m_AudioClipPlayerPool.RentObject().GetComponent <AudioClipPlayer>();

            go.Setup(m_AudioClipPlayerPool, this, signalBus);
            go.Category = trigger;

            if (go.IsEmpty == false)
            {
                D.LogError("Rented AudioClipPlayer is not empty! Used for " + go.ClipID);
            }

            go.transform.parent        = transform;
            go.transform.localPosition = Vector3.zero;

            var audioSource = go.AudioSource;

            if (outBus != null)
            {
                audioSource.outputAudioMixerGroup = outBus;
            }

            audioSource.pitch        = referenceAudioSource ? referenceAudioSource.pitch : 1;
            audioSource.loop         = loop;
            audioSource.clip         = clip;
            audioSource.volume       = volume;
            audioSource.spatialBlend = referenceAudioSource ? referenceAudioSource.spatialBlend : (in3D) ? 1.0f : 0.0f;
            if (in3D || m_AudioMode == AudioMode.AUDIO_3D)
            {
                audioSource.minDistance = referenceAudioSource ? referenceAudioSource.minDistance : minDistance;
                audioSource.maxDistance = referenceAudioSource ? referenceAudioSource.maxDistance : maxDistance;
                audioSource.rolloffMode = referenceAudioSource ? referenceAudioSource.rolloffMode : volumeRolloffMode;
                if (position != null)
                {
                    go.transform.position = position.Value;
                }

                if (audioSource.rolloffMode == AudioRolloffMode.Custom && referenceAudioSource)
                {
                    foreach (AudioSourceCurveType audioCurve in (AudioSourceCurveType[])Enum.GetValues(typeof(AudioSourceCurveType)))
                    {
                        audioSource.SetCustomCurve(audioCurve, referenceAudioSource.GetCustomCurve(audioCurve));
                    }
                }
                audioSource.dopplerLevel          = referenceAudioSource ? referenceAudioSource.dopplerLevel : audioSource.dopplerLevel;
                audioSource.spread                = referenceAudioSource ? referenceAudioSource.spread : audioSource.spread;
                audioSource.spatialize            = referenceAudioSource ? referenceAudioSource.spatialize : audioSource.spatialize;
                audioSource.spatializePostEffects = referenceAudioSource ? referenceAudioSource.spatializePostEffects : audioSource.spatializePostEffects;
            }

            if (pitchRandomisation != 0.0f)
            {
                pitchRandomisation = Mathf.Abs(pitchRandomisation);
                float defaultPitch = referenceAudioSource ? referenceAudioSource.pitch : 1.0f;
                audioSource.pitch = defaultPitch + UnityEngine.Random.Range(-pitchRandomisation, pitchRandomisation);
            }

            float releaseDelayGameTime = 0;
            float releaseDelayRealTime = 0;

            if (!loop && !startPaused)
            {
                // Return to pool after the clip is played
                releaseDelayGameTime = delay;
                releaseDelayRealTime = clip.length + 0.1f;
            }

            go.SetClip(clip, trackTrans, releaseDelayGameTime, releaseDelayRealTime, trigger.ID);

            return(go);
        }
Пример #9
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);
        }
Пример #10
0
 public WaitUntilAudioClipFinished(AudioClipPlayer player)
 {
     m_Wait = player != null;
 }