Example #1
0
        /// <summary>
        /// Plays audio for an AudioInteractionResult.
        /// </summary>
        /// <param name="interactionResult">The interaction result to use data from.</param>
        /// <param name="point">The world position to play the audio at.</param>
        /// <param name="priority">The priority of the sound. Audio sources with a priority less than this will be "stolen" and used to play this audio.</param>
        /// <returns>The ImpactAudioSource that will be used to play the audio. Will be null if no audio sources are available.</returns>
        public static ImpactAudioSourceBase PlayAudio(AudioInteractionResult interactionResult, Vector3 point, int priority)
        {
            if (interactionResult.AudioSourceTemplate == null)
            {
                return(null);
            }

            ImpactAudioPool pool = poolGroup.GetOrCreatePool(interactionResult.AudioSourceTemplate, interactionResult.AudioSourceTemplate.PoolSize);

            if (pool != null)
            {
                ImpactAudioSourceBase a = pool.GetObject();

                //If all objects are in use, try to get one with a lower priority
                if (a == null)
                {
                    a = pool.GetObject((p) => p.Priority < priority);
                }

                if (a != null)
                {
                    a.PlayAudio(interactionResult, point, priority);
                }

                return(a);
            }

            return(null);
        }
Example #2
0
        /// <summary>
        /// Play audio using our data.
        /// </summary>
        /// <param name="parent">The Impact Object that created this result.</param>
        public void Process(IImpactObject parent)
        {
            this.parent = parent;
            audioSource = ImpactAudioPool.PlayAudio(this, OriginalData.Point, InteractionResultExtensions.GetPriority(OriginalData.PriorityOverride, parent));

            targetVolume = currentVolume = Volume;
            targetPitch  = currentPitch = Pitch;

            //Dispose immediately for Collision interaction types
            if (OriginalData.InteractionType == InteractionData.InteractionTypeCollision)
            {
                Dispose();
            }
        }
Example #3
0
 /// <summary>
 /// Creates an instance of the ImpactAudioPool.
 /// </summary>
 public override void Preload()
 {
     ImpactAudioPool.PreloadPoolForAudioSource(AudioSourceTemplate);
     ImpactManagerInstance.CreateInteractionResultPool <AudioInteractionResult>(interactionResultPoolKey);
 }