/// <summary>
        /// Creates a new DecalInteractionResult from the given IInteractionData.
        /// </summary>
        /// <param name="interactionData">The data to use to create the result.</param>
        /// <returns>A new DecalInteractionResult.</returns>
        public override IInteractionResult GetInteractionResult <T>(T interactionData)
        {
            //Immediately break out if intensity is less than the velocity minimum, since any result would be invalid anyways.
            float intensity = ImpactInteractionUtilities.GetCollisionIntensity(interactionData, CollisionNormalInfluence);

            if (intensity < MinimumVelocity)
            {
                return(null);
            }

            long key = 0;

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

            DecalInteractionResult c;

            if (shouldEmit(interactionData.InteractionType) && ImpactManagerInstance.TryGetInteractionResultFromPool(interactionResultPoolKey, out c))
            {
                c.Key           = key;
                c.DecalTemplate = DecalPrefab;
                c.OriginalData  = InteractionDataUtilities.ToInteractionData(interactionData);

                c.CreationInterval     = CreationInterval;
                c.CreationIntervalType = CreationIntervalType;

                return(c);
            }

            return(null);
        }
Пример #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);
        }