コード例 #1
0
    public virtual void OnCollisionAndTriggerEvents(CollisionAndTriggerInfoBundle collAndTriggerData)
    {
        // send ship max info about collisions
        foreach (KeyValuePair <InteractionController, CollisionAndTriggerInfo> objInteractions in collAndTriggerData.objBasedInteractionsDict)
        {
            float   myMaxCollMomentum = 0.0f;
            Vector2 impactPoint       = new Vector2();

            if (!objInteractions.Key.SupportsInteraction(INTERACTION.COLL_IS_STATIC))
            {
                // iterate over collisions to determine strongest point of impact and collision momentum regarding both objects
                if (objInteractions.Value.collisionEnterData.Count > 0)
                {
                    // both colliders have rbody
                    if (!SupportsInteraction(INTERACTION.COLL_IS_STATIC) && rbodyCollListeners.Count > 0)
                    {
                        float theirMaxCollMomentum       = 0.0f;
                        float maxTotalMomentum           = 0.0f;
                        CollisionEnterData strongestColl = null;
                        foreach (CollisionEnterData collEnterData in objInteractions.Value.collisionEnterData)
                        {
                            if (collEnterData.myEventData.collision.contacts.Length == 0)
                            {
                                continue;
                            }

                            if (collEnterData.myEventData.collMomentum > myMaxCollMomentum)
                            {
                                myMaxCollMomentum = collEnterData.myEventData.collMomentum;
                            }
                            if (collEnterData.theirEventData.collMomentum > theirMaxCollMomentum)
                            {
                                theirMaxCollMomentum = collEnterData.theirEventData.collMomentum;
                            }
                            float totalMomentum = collEnterData.GetTotalMomentum();
                            if (totalMomentum > maxTotalMomentum)
                            {
                                strongestColl    = collEnterData;
                                maxTotalMomentum = totalMomentum;
                                impactPoint      = collEnterData.myEventData.collision.contacts[0].point;
                            }
                        }


                        if (strongestColl != null)
                        {
                            //strongestColl = objInteractions.Value.collisionEnterData[0];
                            //impactPoint = strongestColl.myEventData.collision.contacts[0].point;
                            foreach (IRbodyCollisions rbodyCollListener in rbodyCollListeners)
                            {
                                rbodyCollListener.NonStaticColl(strongestColl, objInteractions.Key, myMaxCollMomentum, theirMaxCollMomentum, impactPoint, collAndTriggerData);
                            }
                        }
                    }
                    else
                    {
                        // im static, they have rbody
                        if (objInteractions.Value.collisionEnterData.Count > 0 && staticCollListeners.Count > 0)
                        {
                            CollisionEnterData strongestColl = null;
                            float theirMaxCollMomentum       = 0.0f;
                            foreach (CollisionEnterData collEnterData in objInteractions.Value.collisionEnterData)
                            {
                                if (collEnterData.myEventData.collision.contacts.Length == 0)
                                {
                                    continue;
                                }
                                if (collEnterData.theirEventData.collMomentum > theirMaxCollMomentum)
                                {
                                    strongestColl        = collEnterData;
                                    theirMaxCollMomentum = collEnterData.theirEventData.collMomentum;
                                    impactPoint          = collEnterData.theirEventData.collision.contacts[0].point;
                                }
                            }

                            if (strongestColl != null)
                            {
                                //strongestColl = objInteractions.Value.collisionEnterData[0];
                                //impactPoint = strongestColl.theirEventData.collision.contacts[0].point;
                                foreach (IStaticCollisions staticCollListener in staticCollListeners)
                                {
                                    staticCollListener.Collision(strongestColl, objInteractions.Key, theirMaxCollMomentum, impactPoint, collAndTriggerData);
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                // their collision is static, so I have rbody
                // iterate over collisions to determine strongest point of impact and collision momentum regarding only your object
                if (objInteractions.Value.collisionEnterData.Count > 0 && rbodyCollListeners.Count > 0)
                {
                    CollisionEnterData strongestColl = null;
                    foreach (CollisionEnterData collEnterData in objInteractions.Value.collisionEnterData)
                    {
                        if (collEnterData.myEventData.collision.contacts.Length == 0)
                        {
                            continue;
                        }
                        if (collEnterData.myEventData.collMomentum > myMaxCollMomentum)
                        {
                            strongestColl     = collEnterData;
                            myMaxCollMomentum = collEnterData.myEventData.collMomentum;
                            impactPoint       = collEnterData.myEventData.collision.contacts[0].point;
                        }
                    }

                    if (strongestColl != null)
                    {
                        //strongestColl = objInteractions.Value.collisionEnterData[0];
                        //impactPoint = strongestColl.myEventData.collision.contacts[0].point;
                        foreach (IRbodyCollisions rbodyCollListener in rbodyCollListeners)
                        {
                            rbodyCollListener.StaticColl(strongestColl, objInteractions.Key, myMaxCollMomentum, impactPoint, collAndTriggerData);
                        }
                    }
                }
            }
        }

        SendAllCollAndTriggerCallbacks(collAndTriggerData);
    }
コード例 #2
0
 private void AddCollisionEnterDataToInfoBundle(CollisionAndTriggerInfo info, CollisionEnterData data)
 {
     info.collisionEnterData.Add(data);
 }