Exemplo n.º 1
0
 private float getVolume(float normalizedIntensity)
 {
     if (ScaleVolumeWithVelocity)
     {
         return(VelocityVolumeScaleCurve.Evaluate(normalizedIntensity) * RandomVolumeRange.RandomInRange());
     }
     else
     {
         return(RandomVolumeRange.RandomInRange());
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a new AudioInteractionResult from the given IInteractionData.
        /// </summary>
        /// <param name="interactionData">The data to use to create the result.</param>
        /// <returns>A new AudioInteractionResult.</returns>
        public override IInteractionResult GetInteractionResult <T>(T interactionData)
        {
            //Immediately break out if intensity is less than the velocity range minimum, since any result would be invalid anyways.
            float intensity = ImpactInteractionUtilities.GetCollisionIntensity(interactionData, CollisionNormalInfluence);

            if (intensity < VelocityRange.Min)
            {
                return(null);
            }

            long key = 0;

            if (!ImpactInteractionUtilities.GetKeyAndValidate(interactionData, this, out key))
            {
                return(null);
            }

            AudioInteractionResult c;

            if (ImpactManagerInstance.TryGetInteractionResultFromPool(interactionResultPoolKey, out c))
            {
                c.OriginalData        = InteractionDataUtilities.ToInteractionData(interactionData);
                c.LoopAudio           = interactionData.InteractionType != InteractionData.InteractionTypeCollision;
                c.Interaction         = this;
                c.AudioSourceTemplate = AudioSourceTemplate;

                if (interactionData.InteractionType == InteractionData.InteractionTypeSimple)
                {
                    c.AudioClip = getAudioClip(interactionData.InteractionType, 0);
                    c.Volume    = RandomVolumeRange.RandomInRange();
                }
                else
                {
                    float normalizedIntensity = VelocityRange.Normalize(intensity);

                    c.AudioClip = getAudioClip(interactionData.InteractionType, normalizedIntensity);
                    c.Volume    = getVolume(normalizedIntensity) * interactionData.CompositionValue;
                    c.Key       = key;
                }

                c.Pitch = RandomPitchRange.RandomInRange();

                return(c);
            }

            return(null);
        }