Esempio n. 1
0
        /// <summary>
        /// Stops an AudioEvent.
        /// </summary>
        /// <param name="eventName">The name associated with the AudioEvent.</param>
        /// <param name="emitter">The GameObject on which the AudioEvent will stopped.</param>
        /// <param name="fadeTimeOverride">The amount of time in seconds to completely fade out the sound. If not null, this will override the fade-out time specified in the event.</param>
        public void StopEvent(string eventName, GameObject emitter, float?fadeTimeOverride)
        {
            emitter = ApplyAudioEmitterTransform(emitter);
            if (emitter == null)
            {
                return;
            }

            for (int i = activeEvents.Count - 1; i >= 0; i--)
            {
                ActiveEvent activeEvent = activeEvents[i];
                if (activeEvent.audioEvent.name == eventName && activeEvent.AudioEmitter == emitter)
                {
                    // A fadeTimeOverride of 0 will fall through to the else.
                    if ((fadeTimeOverride.HasValue && fadeTimeOverride > 0.0f) || (!fadeTimeOverride.HasValue && activeEvent.audioEvent.fadeOutTime > 0.0f))
                    {
                        // If a fadeTime value was provided, then override the fade-out time from the event.
                        float fadeTimeValue = fadeTimeOverride.HasValue ? fadeTimeOverride.Value : activeEvent.audioEvent.fadeOutTime;
                        activeEvent.StopEvent(fadeTimeValue);
                    }
                    else
                    {
                        StopEvent(activeEvent);
                    }
                }
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Stop audio sources in an event, and clean up instance references.
 /// </summary>
 /// <param name="activeEvent">The persistent reference to the event as long as it is playing.</param>
 protected void StopEvent(ActiveEvent activeEvent)
 {
     activeEvent.StopEvent();
     RemoveEventInstance(activeEvent);
 }