internal void Update(GameObject otherGO, Physics2D.Contact c)
        {
            if (this.gameObject == null)
            {
                this.gameObject = otherGO;
                this.collider   = this.gameObject.GetComponent <FPCollider2D>();
                this.rigidbody  = this.gameObject.GetComponent <FPRigidBody2D>();
                this.transform  = this.collider.FPTransform;
            }

            if (c != null)
            {
                if (contacts[0] == null)
                {
                    contacts[0] = new FPContactPoint2D();
                }

                FPVector2 normal;
                Physics2D.FixedArray2 <FPVector2> points;

                c.GetWorldManifold(out normal, out points);

                contacts[0].normal = normal;
                contacts[0].point  = points[0];

                this.relativeVelocity = c.CalculateRelativeVelocity();
            }
        }
        private void CollisionExit(Spax.Physics2D.Contact contact)
        {
            if (contact.FixtureA.IsSensor || contact.FixtureB.IsSensor)
            {
                TriggerExit(contact);
                return;
            }

            CollisionDetected(contact.FixtureA.Body, contact.FixtureB.Body, null, "OnFixedCollisionExit");
        }
        private bool CollisionEnter(Spax.Physics2D.Contact contact)
        {
            if (contact.FixtureA.IsSensor || contact.FixtureB.IsSensor)
            {
                TriggerEnter(contact);

                return(true);
            }

            CollisionDetected(contact.FixtureA.Body, contact.FixtureB.Body, contact, "OnFixedCollisionEnter");
            return(true);
        }
        private void CollisionDetected(Physics2D.Body body1, Physics2D.Body body2, Spax.Physics2D.Contact contact, string callbackName)
        {
            if (!gameObjectMap.ContainsKey(body1) || !gameObjectMap.ContainsKey(body2))
            {
                return;
            }

            GameObject b1 = gameObjectMap[body1];
            GameObject b2 = gameObjectMap[body2];

            if (b1 == null || b2 == null)
            {
                return;
            }

            b1.SendMessage(callbackName, GetCollisionInfo(body1, body2, contact), SendMessageOptions.DontRequireReceiver);
            b2.SendMessage(callbackName, GetCollisionInfo(body2, body1, contact), SendMessageOptions.DontRequireReceiver);

            //FixedPointManager.UpdateCoroutines();
        }
        private FPCollision2D GetCollisionInfo(Physics2D.Body body1, Physics2D.Body body2, Spax.Physics2D.Contact c)
        {
            if (!collisionInfo.ContainsKey(body1))
            {
                collisionInfo.Add(body1, new Dictionary <Physics2D.Body, FPCollision2D>());
            }

            Dictionary <Physics2D.Body, FPCollision2D> collisionInfoBody1 = collisionInfo[body1];

            FPCollision2D result = null;

            if (collisionInfoBody1.ContainsKey(body2))
            {
                result = collisionInfoBody1[body2];
            }
            else
            {
                result = new FPCollision2D();
                collisionInfoBody1.Add(body2, result);
            }

            result.Update(gameObjectMap[body2], c);

            return(result);
        }
 private void TriggerExit(Spax.Physics2D.Contact contact)
 {
     CollisionDetected(contact.FixtureA.Body, contact.FixtureB.Body, null, "OnFixedTriggerExit");
 }
 private void TriggerStay(Spax.Physics2D.Contact contact)
 {
     CollisionDetected(contact.FixtureA.Body, contact.FixtureB.Body, contact, "OnFixedTriggerStay");
 }