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();
            }
        }
        public void AddBody(ICollider iCollider)
        {
            if (!(iCollider is FPCollider2D))
            {
                Debug.LogError("You have a 3D object but your Physics 3D is disabled.");
                return;
            }

            FPCollider2D FPCollider = (FPCollider2D)iCollider;

            if (FPCollider._body != null)
            {
                //already added
                return;
            }

            FPCollider.Initialize(world);
            gameObjectMap[FPCollider._body] = FPCollider.gameObject;



            if (FPCollider.gameObject.transform.parent != null && FPCollider.gameObject.transform.parent.GetComponentInParent <FPCollider2D>() != null)
            {
                FPCollider2D   parentCollider = FPCollider.gameObject.transform.parent.GetComponentInParent <FPCollider2D>();
                Physics2D.Body childBody      = FPCollider._body;

                childBody.bodyConstraints.Add(new ConstraintHierarchy2D(((Physics2D.Body)parentCollider.Body), FPCollider._body, (FPCollider.GetComponent <FPTransform2D>().position + FPCollider.ScaledCenter) - (parentCollider.GetComponent <FPTransform2D>().position + parentCollider.ScaledCenter)));
            }

            world.ProcessAddedBodies();
        }
        /**
         *  @brief Initializes internal properties based on whether there is a {@link FPCollider2D} attached.
         **/
        public void Initialize()
        {
            if (initialized)
            {
                return;
            }

            FPCollider = GetComponent <FPCollider2D>();
            if (transform.parent != null)
            {
                tsParent = transform.parent.GetComponent <FPTransform2D>();
            }

            if (!_serialized)
            {
                UpdateEditMode();
            }

            if (FPCollider != null)
            {
                if (FPCollider.IsBodyInitialized)
                {
                    FPCollider.Body.FPPosition    = _position + scaledCenter;
                    FPCollider.Body.FPOrientation = _rotation * FP.Deg2Rad;
                }
            }
            else
            {
                // StateTracker.AddTracking(this);
            }

            initialized = true;
        }
        private static object OverlapGeneric(Physics2D.Shape shape, FPVector2 position, Physics2D.BodySpecialSensor sensorType, int layerMask)
        {
            Physics2D.World world = (Physics2D.World)Physics2DWorldManager.instance.GetWorld();

            Physics2D.Body body = Physics2D.BodyFactory.CreateBody(world);
            body.CreateFixture(shape);

            body.BodyType     = Physics2D.BodyType.Static;
            body.IsSensor     = true;
            body.CollidesWith = Physics2D.Category.All;

            body.SpecialSensor     = sensorType;
            body.SpecialSensorMask = layerMask;
            body.Position          = position;

            world.RemoveBody(body);
            world.ProcessRemovedBodies();

            if (body._specialSensorResults.Count > 0)
            {
                if (sensorType == Physics2D.BodySpecialSensor.ActiveOnce)
                {
                    return(Physics2DWorldManager.instance.GetGameObject(body._specialSensorResults[0]).GetComponent <FPCollider2D>());
                }
                else
                {
                    FPCollider2D[] result = new FPCollider2D[body._specialSensorResults.Count];
                    for (int i = 0; i < body._specialSensorResults.Count; i++)
                    {
                        result[i] = Physics2DWorldManager.instance.GetGameObject(body._specialSensorResults[i]).GetComponent <FPCollider2D>();
                    }

                    return(result);
                }
            }

            return(null);
        }