Beispiel #1
0
        protected ImpactTagMask?getOtherObjectTagMask(IImpactObject impactObject, Vector3 point, int otherPhysicsMaterialID, bool hasOtherObject)
        {
            if (hasOtherObject)
            {
                IImpactMaterial m = impactObject.GetPrimaryMaterial(point);

                if (m != null)
                {
                    return(m.MaterialTagsMask);
                }
                else if (ImpactManagerInstance.UseMaterialMapping && ImpactManagerInstance.TryGetImpactMaterialFromMapping(otherPhysicsMaterialID, out m))
                {
                    return(m.MaterialTagsMask);
                }
            }
            else
            {
                IImpactMaterial m;
                if (ImpactManagerInstance.UseMaterialMapping && ImpactManagerInstance.TryGetImpactMaterialFromMapping(otherPhysicsMaterialID, out m))
                {
                    return(m.MaterialTagsMask);
                }
            }

            return(null);
        }
 private static void triggerOnHitObject <T>(T interactionData, IImpactObject otherObject, int physicsMaterialId, bool useMaterialComposition) where T : IInteractionData
 {
     if (otherObject != null)
     {
         if (useMaterialComposition)
         {
             int count = otherObject.GetMaterialCompositionNonAlloc(interactionData.Point, ImpactManagerInstance.MaterialCompositionBuffer);
             for (int i = 0; i < count; i++)
             {
                 ImpactMaterialComposition comp = ImpactManagerInstance.MaterialCompositionBuffer[i];
                 if (comp.CompositionValue > 0)
                 {
                     IInteractionData newInteractionData = interactionData.Clone();
                     newInteractionData.CompositionValue = comp.CompositionValue;
                     ImpactManagerInstance.ProcessInteraction(newInteractionData, comp.Material, otherObject);
                 }
             }
         }
         else
         {
             ImpactManagerInstance.ProcessInteraction(interactionData, otherObject);
         }
     }
     else if (ImpactManagerInstance.UseMaterialMapping)
     {
         IImpactMaterial m;
         if (ImpactManagerInstance.TryGetImpactMaterialFromMapping(physicsMaterialId, out m))
         {
             ImpactManagerInstance.ProcessInteraction(interactionData, m, null);
         }
     }
 }
        public void Dispose()
        {
            parent        = null;
            DecalTemplate = null;

            MakeAvailable();
        }
Beispiel #4
0
        /// <summary>
        /// Process interaction data using the given Impact Object. The primary material at the interaction point will be used.
        /// </summary>
        /// <param name="interactionData">The interaction data to process.</param>
        /// <param name="impactObject">The Impact Object that the primary Impact Material will be retrieved from.</param>
        public static void ProcessInteraction <T>(T interactionData, IImpactObject impactObject) where T : IInteractionData
        {
            if (impactObject == null)
            {
                return;
            }

            ProcessInteraction(interactionData, impactObject.GetPrimaryMaterial(interactionData.Point), impactObject);
        }
        /// <summary>
        /// Trigger an interaction from a 2D raycast. Impact Material data will be retrieved from the object that was hit by the raycast. The interaction will be processed using the given IImpactObject.
        /// </summary>
        /// <param name="hit">Raycast 2D hit data. The contact point, normal, and the object that was hit will be retrived from this.</param>
        /// <param name="impactObject">The Impact Object the resulting interaction will be processed on.</param>
        /// <param name="velocity">The velocity of the interaction.</param>
        /// <param name="interactionType">The type of interaction.</param>
        /// <param name="useMaterialComposition">Should this trigger use the material composition of the object it hit by the raycast?</param>
        public static void Trigger2D(IImpactObject impactObject, RaycastHit2D hit, Vector3 velocity, int interactionType, bool useMaterialComposition)
        {
            InteractionData interactionData = new InteractionData();

            interactionData.InteractionType = interactionType;
            interactionData.Velocity        = velocity;
            interactionData.ThisObject      = impactObject.GameObject;

            Trigger2D(interactionData, hit, impactObject, useMaterialComposition);
        }
        /// <summary>
        /// Gets the priority, either from the Interaction Data Priority Override or from the Impact Object.
        /// </summary>
        /// <param name="collisionResult">The collision result to get the priority for.</param>
        /// <param name="obj">The impact object to get the priority from.</param>
        /// <returns>The priority, either from the Interaction Data Priority Override or from the Impact Object.</returns>
        public static int GetPriority(int?priorityOverride, IImpactObject obj)
        {
            if (priorityOverride.HasValue)
            {
                return(priorityOverride.Value);
            }
            else if (obj != null)
            {
                return(obj.Priority);
            }

            return(0);
        }
Beispiel #7
0
        /// <summary>
        /// Adds or updates the given continuous interaction result to the active continuous interaction results, if able.
        /// </summary>
        /// <param name="impactObject">The impact object the result is being sent from.</param>
        /// <param name="result">The new continuous interaction result.</param>
        public void AddOrUpdateContinuousInteractionResult(IImpactObject impactObject, IContinuousInteractionResult result)
        {
            IContinuousInteractionResult existing = findContinuousInteractionResult(result.Key);

            if (existing != null)
            {
                existing.KeepAlive(result);
                result.Dispose();
            }
            else
            {
                addContinuousInteractionResult(impactObject, result);
            }
        }
Beispiel #8
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();
            }
        }
        protected override void buildInteractionData(IImpactObject target, TCollision collision, TContact contactPoint,
                                                     VelocityData myVelocityData, VelocityData otherVelocityData, ImpactTagMask?tagMask, float compositionValue)
        {
            Vector3 relativeContactPointVelocity = myVelocityData.TotalPointVelocity - otherVelocityData.TotalPointVelocity;

            if (SlideMode != SlideMode.None)
            {
                InteractionData slideParameters = new InteractionData()
                {
                    TagMask          = tagMask,
                    Point            = contactPoint.Point,
                    Normal           = contactPoint.Normal,
                    Velocity         = relativeContactPointVelocity,
                    InteractionType  = InteractionData.InteractionTypeSlide,
                    ThisObject       = contactPoint.ThisObject,
                    OtherObject      = contactPoint.OtherObject,
                    CompositionValue = compositionValue
                };

                invokeTriggeredEvent(slideParameters, target);

                ImpactManagerInstance.ProcessContinuousInteraction(slideParameters, target);
            }

            if (RollMode != RollMode.None)
            {
                float roll = 1 - Mathf.Clamp01(relativeContactPointVelocity.magnitude * 0.1f);

                if (roll > 0)
                {
                    Vector3 rollVelocity = myVelocityData.TangentialVelocity * roll;

                    InteractionData rollParameters = new InteractionData()
                    {
                        TagMask          = tagMask,
                        Point            = contactPoint.Point,
                        Normal           = contactPoint.Normal,
                        Velocity         = rollVelocity,
                        InteractionType  = InteractionData.InteractionTypeRoll,
                        ThisObject       = contactPoint.ThisObject,
                        OtherObject      = contactPoint.OtherObject,
                        CompositionValue = compositionValue
                    };

                    invokeTriggeredEvent(rollParameters, target);

                    ImpactManagerInstance.ProcessContinuousInteraction(rollParameters, target);
                }
            }
        }
Beispiel #10
0
        /// <summary>
        /// Process a collision contact to get all material and velocity data.
        /// The material and velocity data will be sent to buildInteractionData, which you can override.
        /// </summary>
        /// <param name="collision">The original collision data.</param>
        /// <param name="contactPoint">The contact point of the collision to use in calculations.</param>
        protected void processCollisionContact(TCollision collision, TContact contactPoint)
        {
            IImpactObject myObject = getImpactObject(contactPoint.ThisObject);

            if (myObject != null)
            {
                IImpactObject otherObject    = contactPoint.OtherObject.GetComponentInParent <IImpactObject>();
                bool          hasOtherObject = otherObject != null;

                //Material composition is enabled
                if (UseMaterialComposition && hasOtherObject)
                {
                    //Get material composition
                    int count = otherObject.GetMaterialCompositionNonAlloc(contactPoint.Point, ImpactManagerInstance.MaterialCompositionBuffer);

                    //Get velocity data
                    VelocityData myVelocityData    = myObject.GetVelocityDataAtPoint(contactPoint.Point);
                    VelocityData otherVelocityData = otherObject.GetVelocityDataAtPoint(contactPoint.Point);

                    //Create interaction for each material
                    for (int i = 0; i < count; i++)
                    {
                        ImpactMaterialComposition comp = ImpactManagerInstance.MaterialCompositionBuffer[i];
                        if (comp.CompositionValue > 0)
                        {
                            buildInteractionData(myObject, collision, contactPoint, myVelocityData, otherVelocityData, comp.Material.MaterialTagsMask, comp.CompositionValue);
                        }
                    }
                }
                //Material composition is not enabled
                else
                {
                    //Get velocity data
                    VelocityData otherVelocityData = hasOtherObject ? otherObject.GetVelocityDataAtPoint(contactPoint.Point) : new VelocityData();
                    VelocityData myVelocityData    = myObject.GetVelocityDataAtPoint(contactPoint.Point);

                    //Get tag mask
                    ImpactTagMask?tagMask = getOtherObjectTagMask(otherObject, contactPoint.Point, contactPoint.OtherPhysicsMaterialID, hasOtherObject);

                    //Create interaction
                    buildInteractionData(myObject, collision, contactPoint, myVelocityData, otherVelocityData, tagMask, 1);
                }
            }
            else
            {
                //Impact object could not be found. MainTarget is not assigned and no Impact Object could be determined from the contact point.
                Debug.LogError("Unable to find Impact Object on GameObject " + gameObject.name);
            }
        }
Beispiel #11
0
        /// <summary>
        /// Stops the audio source associated with this result so it becomes available in the audio source object pool.
        /// </summary>
        public void Dispose()
        {
            if (OriginalData.InteractionType != InteractionData.InteractionTypeCollision && audioSource != null)
            {
                audioSource.StopAudio();
            }

            AudioSourceTemplate = null;
            audioSource         = null;
            AudioClip           = null;
            Interaction         = null;
            parent = null;

            MakeAvailable();
        }
Beispiel #12
0
        /// <summary>
        /// Emit particles using our data.
        /// </summary>
        /// <param name="parent">The Impact Object that created this result.</param>
        public void Process(IImpactObject parent)
        {
            this.parent = parent;

            particlesInstance = ImpactParticlePool.EmitParticles(this, OriginalData.Point, OriginalData.Normal, InteractionResultExtensions.GetPriority(OriginalData.PriorityOverride, parent));
            IsAlive           = true;

            currentEmissionIntervalTarget = EmissionInterval.RandomInRange();

            //Dispose immediately for Collision interaction types
            if (OriginalData.InteractionType == InteractionData.InteractionTypeCollision)
            {
                Dispose();
            }
        }
Beispiel #13
0
        private void addContinuousInteractionResult(IImpactObject impactObject, IContinuousInteractionResult continuousInteractionResult)
        {
            for (int i = 0; i < activeContinuousInteractionResults.Length; i++)
            {
                if (activeContinuousInteractionResults[i] == null)
                {
                    activeContinuousInteractionResults[i] = continuousInteractionResult;
                    currentActiveContinuousInteractionCount++;
                    activeContinuousInteractionKeys.Add(continuousInteractionResult.Key);
                    continuousInteractionResult.Process(impactObject);
                    return;
                }
            }

            continuousInteractionResult.Dispose();
        }
        /// <summary>
        /// Place decals using our data.
        /// </summary>
        /// <param name="parent">The Impact Object that created this result.</param>
        public void Process(IImpactObject parent)
        {
            this.parent = parent;

            ImpactDecalPool.CreateDecal(this, OriginalData.Point, OriginalData.Normal);
            IsAlive = true;

            currentCreationIntervalTarget = CreationInterval.RandomInRange();
            previousCreationPosition      = OriginalData.Point;

            //Dispose immediately for Collision interaction types
            if (OriginalData.InteractionType == InteractionData.InteractionTypeCollision)
            {
                Dispose();
            }
        }
        /// <summary>
        /// Trigger an interaction from a 2D raycast. The interaction will be processed on the object that was hit by the raycast.
        /// </summary>
        /// <param name="hit">Raycast 2D hit data. The contact point, normal, and the object that was hit will be retrived from this.</param>
        /// <param name="interactionData">The original interaction data. Velocity, TagMask, ThisObject, and InteractionType should already be set.</param>
        /// <param name="useMaterialComposition">Should this trigger use the material composition of the object it hit by the raycast?</param>
        public static void Trigger2D <T>(T interactionData, RaycastHit2D hit, bool useMaterialComposition) where T : IInteractionData
        {
            interactionData.OtherObject      = hit.collider.gameObject;
            interactionData.Point            = hit.point;
            interactionData.Normal           = hit.normal;
            interactionData.CompositionValue = 1;

            IImpactObject otherObject       = hit.collider.GetComponentInParent <IImpactObject>();
            int           physicsMaterialId = 0;

            if (ImpactManagerInstance.UseMaterialMapping && hit.collider.sharedMaterial != null)
            {
                physicsMaterialId = hit.collider.sharedMaterial.GetInstanceID();
            }

            triggerOnHitObject(interactionData, otherObject, physicsMaterialId, useMaterialComposition);
        }
Beispiel #16
0
        protected void processSpeculativeCollision(TCollision collision)
        {
            int collisions = 0;

            //Loop over all contacts of the collision
            for (int i = 0; i < collision.ContactCount; i++)
            {
                TContact      contactPoint = collision.GetContact(i);
                IImpactObject thisObject   = getImpactObject(contactPoint.ThisObject);

                if (thisObject != null)
                {
                    SpeculativeCollisionContact c = new SpeculativeCollisionContact()
                    {
                        RelativeContactPoint = thisObject.GetContactPointRelativePosition(contactPoint.Point),
                        Lifetime             = _contactPointLifetime
                    };

                    //The relative position of the contact point serves as a unique identifier
                    //So we can keep track of contact points between frames
                    //If there is no existing point with the same relative position (within a threshold), then it is a "new" contact point.
                    //We then process the point, basically mimicking an OnCollisionEnter message.
                    int existingIndex = continousCollisionContacts.FindIndex(e => (e.RelativeContactPoint - c.RelativeContactPoint).sqrMagnitude < _contactPointComparisonThreshold);
                    if (existingIndex == -1)
                    {
                        continousCollisionContacts.Add(c);

                        if (collisions < MaxCollisionsPerFrame)
                        {
                            processCollisionContact(collision, contactPoint);
                            collisions++;
                        }
                    }
                    else
                    {
                        SpeculativeCollisionContact existingContact = continousCollisionContacts[existingIndex];
                        existingContact.Lifetime = _contactPointLifetime;
                        continousCollisionContacts[existingIndex] = existingContact;
                    }
                }
            }
        }
        private static void triggerOnRaycastingObject <T>(T interactionData, IImpactObject impactObject, IImpactObject otherObject, int physicsMaterialId, bool useMaterialComposition) where T : IInteractionData
        {
            if (otherObject != null)
            {
                if (useMaterialComposition)
                {
                    int count = otherObject.GetMaterialCompositionNonAlloc(interactionData.Point, ImpactManagerInstance.MaterialCompositionBuffer);
                    for (int i = 0; i < count; i++)
                    {
                        ImpactMaterialComposition comp = ImpactManagerInstance.MaterialCompositionBuffer[i];
                        if (comp.CompositionValue > 0)
                        {
                            IInteractionData newInteractionData = interactionData.Clone();
                            newInteractionData.CompositionValue = comp.CompositionValue;
                            newInteractionData.TagMask          = comp.Material.MaterialTagsMask;
                            ImpactManagerInstance.ProcessInteraction(newInteractionData, impactObject);
                        }
                    }
                }
                else
                {
                    IImpactMaterial material = otherObject.GetPrimaryMaterial(interactionData.Point);
                    if (material != null || (ImpactManagerInstance.UseMaterialMapping && ImpactManagerInstance.TryGetImpactMaterialFromMapping(physicsMaterialId, out material)))
                    {
                        interactionData.TagMask = material.MaterialTagsMask;
                    }

                    ImpactManagerInstance.ProcessInteraction(interactionData, impactObject);
                }
            }
            else if (ImpactManagerInstance.UseMaterialMapping)
            {
                IImpactMaterial material;
                if (ImpactManagerInstance.TryGetImpactMaterialFromMapping(physicsMaterialId, out material))
                {
                    interactionData.TagMask = material.MaterialTagsMask;
                }

                ImpactManagerInstance.ProcessInteraction(interactionData, impactObject);
            }
        }
        protected override void buildInteractionData(IImpactObject target, TCollision collision, TContact contactPoint,
                                                     VelocityData myVelocityData, VelocityData otherVelocityData, ImpactTagMask?tagMask, float CompositionValue)
        {
            Vector3 relativeContactPointVelocity = myVelocityData.TotalPointVelocity - otherVelocityData.TotalPointVelocity;

            InteractionData interactionData = new InteractionData()
            {
                TagMask          = tagMask,
                Point            = contactPoint.Point,
                Normal           = contactPoint.Normal,
                Velocity         = relativeContactPointVelocity,
                InteractionType  = InteractionData.InteractionTypeCollision,
                ThisObject       = contactPoint.ThisObject,
                OtherObject      = contactPoint.OtherObject,
                CompositionValue = CompositionValue
            };

            invokeTriggeredEvent(interactionData, target);

            ImpactManagerInstance.ProcessInteraction(interactionData, target);
        }
        protected override void buildInteractionData(IImpactObject target, ImpactCollisionWrapper collision, ImpactContactPoint contactPoint,
                                                     VelocityData myVelocityData, VelocityData otherVelocityData, ImpactTagMask?tagMask, float CompositionValue)
        {
            VelocityData currentVelocityData = rigidbodyWrapper.GetCurrentVelocityData(contactPoint.Point);

            Vector3 velocityChange = myVelocityData.TotalPointVelocity - currentVelocityData.TotalPointVelocity;
            Vector3 relativeContactPointVelocity = myVelocityData.TotalPointVelocity - otherVelocityData.TotalPointVelocity;

            InteractionData interactionData = new InteractionData()
            {
                TagMask          = tagMask,
                Point            = contactPoint.Point,
                Normal           = contactPoint.Normal,
                Velocity         = Vector3.Lerp(relativeContactPointVelocity, velocityChange, _velocityChangeInfluence),
                InteractionType  = InteractionData.InteractionTypeCollision,
                ThisObject       = contactPoint.ThisObject,
                OtherObject      = contactPoint.OtherObject,
                CompositionValue = CompositionValue
            };

            invokeTriggeredEvent(interactionData, target);

            ImpactManagerInstance.ProcessInteraction(interactionData, target);
        }
Beispiel #20
0
        /// <summary>
        /// Process a continuous interaction using the interaction data and the given Impact Object. The primary material at the interaction point will be used.
        /// </summary>
        /// <param name="interactionData">The interaction data to process.</param>
        /// <param name="impactObject">The Impact Object that an Impact Material will be retrieved from.</param>
        public static void ProcessContinuousInteraction <T>(T interactionData, IImpactObject impactObject) where T : IInteractionData
        {
            ImpactManager instance = GetInstance();

            instance.ProcessContinuousInteraction(interactionData, impactObject.GetPrimaryMaterial(interactionData.Point), impactObject);
        }
Beispiel #21
0
        /// <summary>
        /// Process a continuous interaction using the interaction data, an Impact Material, and an optional Impact Object that the interaction originated from.
        /// </summary>
        /// <param name="interactionData">The interaction data to process.</param>
        /// <param name="impactMaterial">The Impact Material to get interaction results from.</param>
        /// <param name="impactObject">An optional Impact Object that the interaction originated from.</param>
        public static void ProcessContinuousInteraction <T>(T interactionData, IImpactMaterial material, IImpactObject impactObject) where T : IInteractionData
        {
            ImpactManager instance = GetInstance();

            instance.ProcessContinuousInteraction(interactionData, material, impactObject);
        }
Beispiel #22
0
        /// <summary>
        /// Adds or updates the given continuous interaction result to the active continuous interaction results, if able.
        /// </summary>
        /// <param name="impactObject">The impact object the result is being sent from.</param>
        /// <param name="result">The new continuous interaction result.</param>
        public static void AddOrUpdateContinuousInteractionResult(IImpactObject impactObject, IContinuousInteractionResult result)
        {
            ImpactManager instance = GetInstance();

            instance.AddOrUpdateContinuousInteractionResult(impactObject, result);
        }
Beispiel #23
0
 protected void invokeTriggeredEvent(InteractionData interactionData, IImpactObject impactObject)
 {
     OnTriggered?.Invoke(interactionData, impactObject);
 }
Beispiel #24
0
 /// <summary>
 /// Called by the process methods to build IInteractionData.
 /// Override this if your custom triggers are using any of the process methods.
 /// </summary>
 /// <param name="target">The target IImpactObject to send data to. You do not necessarily have to send data to this object.</param>
 /// <param name="collision">The collision being processed.</param>
 /// <param name="contactPoint">The collision contact point.</param>
 /// <param name="myVelocityData">The velocity data of this object.</param>
 /// <param name="otherVelocityData">The velocity data of the object being collided with.</param>
 /// <param name="tagMask">The tag mask obtained from the other object. Can be null.</param>
 /// <param name="compositionValue">The material composition value.</param>
 protected virtual void buildInteractionData(IImpactObject target, TCollision collision, TContact contactPoint, VelocityData myVelocityData, VelocityData otherVelocityData, ImpactTagMask?tagMask, float compositionValue)
 {
 }
        private void processParticleCollision(ParticleCollisionEvent particleCollisionEvent, GameObject onParticleCollisionObject, bool isParticleSystem)
        {
            IImpactObject myObject;

            //Particle system always uses the main target
            if (isParticleSystem)
            {
                myObject = MainTarget;
            }
            //Non-particle system gets the object from the particle collision event's collider
            else
            {
                myObject = getImpactObject(particleCollisionEvent.colliderComponent.gameObject);
            }

            if (myObject != null)
            {
                IImpactObject otherObject = null;

                //Get other object based on whether or not this object is a particle system
                if (isParticleSystem)
                {
                    otherObject = particleCollisionEvent.colliderComponent.GetComponentInParent <IImpactObject>();
                }
                else
                {
                    otherObject = onParticleCollisionObject.GetComponentInParent <IImpactObject>();
                }

                bool hasOtherObject = otherObject != null;

                if (UseMaterialComposition && hasOtherObject)
                {
                    int count = otherObject.GetMaterialCompositionNonAlloc(particleCollisionEvent.intersection, ImpactManagerInstance.MaterialCompositionBuffer);

                    //Velocity data is dependent on if this is a particle system or a not
                    VelocityData myVelocityData;
                    VelocityData otherVelocityData;
                    if (isParticleSystem)
                    {
                        myVelocityData    = new VelocityData(particleCollisionEvent.velocity, Vector3.zero);
                        otherVelocityData = otherObject.GetVelocityDataAtPoint(particleCollisionEvent.intersection);
                    }
                    else
                    {
                        myVelocityData    = myObject.GetVelocityDataAtPoint(particleCollisionEvent.intersection);
                        otherVelocityData = new VelocityData(particleCollisionEvent.velocity, Vector3.zero);
                    }

                    Vector3 relativeContactPointVelocity = myVelocityData.TotalPointVelocity - otherVelocityData.TotalPointVelocity;

                    for (int i = 0; i < count; i++)
                    {
                        ImpactMaterialComposition comp = ImpactManagerInstance.MaterialCompositionBuffer[i];

                        if (comp.CompositionValue > 0)
                        {
                            InteractionData interactionData = new InteractionData()
                            {
                                TagMask          = comp.Material.MaterialTagsMask,
                                Point            = particleCollisionEvent.intersection,
                                Normal           = particleCollisionEvent.normal,
                                Velocity         = relativeContactPointVelocity,
                                InteractionType  = InteractionData.InteractionTypeCollision,
                                ThisObject       = this.gameObject,
                                OtherObject      = otherObject.GameObject,
                                CompositionValue = 1f
                            };

                            invokeTriggeredEvent(interactionData, myObject);

                            ImpactManagerInstance.ProcessInteraction(interactionData, myObject);
                        }
                    }
                }
                else
                {
                    //Velocity data is dependent on if this is a particle system or a not
                    VelocityData myVelocityData;
                    VelocityData otherVelocityData;
                    if (isParticleSystem)
                    {
                        myVelocityData    = new VelocityData(particleCollisionEvent.velocity, Vector3.zero);
                        otherVelocityData = hasOtherObject ? otherObject.GetVelocityDataAtPoint(particleCollisionEvent.intersection) : new VelocityData();
                    }
                    else
                    {
                        myVelocityData    = myObject.GetVelocityDataAtPoint(particleCollisionEvent.intersection);
                        otherVelocityData = new VelocityData(particleCollisionEvent.velocity, Vector3.zero);
                    }

                    Vector3 relativeContactPointVelocity = myVelocityData.TotalPointVelocity - otherVelocityData.TotalPointVelocity;

                    //Get physics material ID for material mapping, but only if this object is a particle system.
                    //Particles don't have a collider so no need to try and get the physics material if this is not a particle system
                    int           otherPhysicsMaterialID = isParticleSystem ? getPhysicsMaterialID(particleCollisionEvent.colliderComponent) : 0;
                    ImpactTagMask?tagMask = getOtherObjectTagMask(otherObject, particleCollisionEvent.intersection, otherPhysicsMaterialID, hasOtherObject);

                    InteractionData interactionData = new InteractionData()
                    {
                        TagMask          = tagMask,
                        Point            = particleCollisionEvent.intersection,
                        Normal           = particleCollisionEvent.normal,
                        Velocity         = relativeContactPointVelocity,
                        InteractionType  = InteractionData.InteractionTypeCollision,
                        ThisObject       = this.gameObject,
                        OtherObject      = particleCollisionEvent.colliderComponent.gameObject,
                        CompositionValue = 1f
                    };

                    invokeTriggeredEvent(interactionData, myObject);

                    ImpactManagerInstance.ProcessInteraction(interactionData, myObject);
                }
            }
            else
            {
                Debug.LogError("Unable to find Impact Object on GameObject " + gameObject.name);
            }
        }
Beispiel #26
0
        /// <summary>
        /// Process interaction data using the Impact Material and an optional Impact Object that the interaction originated from.
        /// </summary>
        /// <param name="interactionData">The interaction data to process.</param>
        /// <param name="impactMaterial">The Impact Material to get interaction results from.</param>
        /// <param name="impactObject">An optional Impact Object that the interaction originated from.</param>
        public void ProcessInteraction <T>(T interactionData, IImpactMaterial impactMaterial, IImpactObject impactObject) where T : IInteractionData
        {
            int count = impactMaterial.GetInteractionResultsNonAlloc(interactionData, InteractionResultBuffer);

            for (int i = 0; i < count; i++)
            {
                InteractionResultBuffer[i].Process(impactObject);
            }
        }
Beispiel #27
0
 /// <summary>
 /// Process a continuous interaction using the interaction data and the given Impact Object. The primary material at the interaction point will be used.
 /// </summary>
 /// <param name="interactionData">The interaction data to process.</param>
 /// <param name="impactObject">The Impact Object that an Impact Material will be retrieved from.</param>
 public void ProcessContinuousInteraction <T>(T interactionData, IImpactObject impactObject) where T : IInteractionData
 {
     ProcessContinuousInteraction(interactionData, impactObject.GetPrimaryMaterial(interactionData.Point), impactObject);
 }
Beispiel #28
0
        /// <summary>
        /// Process a continuous interaction using the interaction data, an Impact Material, and an optional Impact Object that the interaction originated from.
        /// </summary>
        /// <param name="interactionData">The interaction data to process.</param>
        /// <param name="impactMaterial">The Impact Material to get interaction results from.</param>
        /// <param name="impactObject">An optional Impact Object that the interaction originated from.</param>
        public void ProcessContinuousInteraction <T>(T interactionData, IImpactMaterial material, IImpactObject impactObject) where T : IInteractionData
        {
            int resultCount = material.GetInteractionResultsNonAlloc(interactionData, InteractionResultBuffer);

            for (int i = 0; i < resultCount; i++)
            {
                IContinuousInteractionResult result = InteractionResultBuffer[i] as IContinuousInteractionResult;

                //result is not a continuous interaction, so simply Process it.
                if (result == null)
                {
                    InteractionResultBuffer[i].Process(impactObject);
                }
                //Otherwise update an existing continuous interaction or add a new one.
                else
                {
                    AddOrUpdateContinuousInteractionResult(impactObject, result);
                }
            }
        }