Пример #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);
        }
Пример #2
0
        /// <summary>
        /// Plays audio for the given audio interaction result.
        /// </summary>
        /// <param name="interactionResult">The result to get the audio clip, volume, and pitch from.</param>
        /// <param name="point">The point to play the audio at.</param>
        /// <param name="priority">The priority of the interaction.</param>
        public override void PlayAudio(AudioInteractionResult interactionResult, Vector3 point, int priority)
        {
            transform.position = point;

            _audioSource.loop   = interactionResult.LoopAudio;
            _audioSource.clip   = interactionResult.AudioClip;
            _audioSource.volume = baseVolume * interactionResult.Volume;
            _audioSource.pitch  = basePitch * interactionResult.Pitch;

            _audioSource.Play();

            this.priority = priority;
        }
Пример #3
0
        /// <summary>
        /// Updates this result to adjust the volume and pitch and updates the audio source position.
        /// </summary>
        /// <param name="newResult">The new result that will be used to get the new volume and pitch.</param>
        public void KeepAlive(IInteractionResult newResult)
        {
            if (audioSource == null)
            {
                return;
            }

            AudioInteractionResult audioInteractionResult = newResult as AudioInteractionResult;

            targetVolume = audioInteractionResult.Volume;
            targetPitch  = Interaction.UpdatePitch(Pitch, audioInteractionResult.OriginalData.Velocity);

            audioSource.transform.position = audioInteractionResult.OriginalData.Point;
        }
 /// <summary>
 /// Plays audio for the given audio interaction result.
 /// </summary>
 /// <param name="interactionResult">The result to get the audio clip, volume, and pitch from.</param>
 /// <param name="point">The point to play the audio at.</param>
 /// <param name="priority">The priority of the interaction.</param>
 public abstract void PlayAudio(AudioInteractionResult interactionResult, Vector3 point, int priority);