public override void OnInspectorGUI()
        {
            FPRigidBody tsRB = (target as FPRigidBody);

            DrawDefaultInspector();

            serializedObject.Update();

            constraintsFoldout = EditorGUILayout.Foldout(constraintsFoldout, "Constraints");

            if (constraintsFoldout)
            {
                EditorGUI.indentLevel++;

                FPRigidBodyConstraints freezeConstraintPos = tsRB.constraints, freezeConstraintRot = tsRB.constraints;

                DrawFreezePanel(ref freezeConstraintPos, true);
                DrawFreezePanel(ref freezeConstraintRot, false);

                tsRB.constraints = (freezeConstraintPos | freezeConstraintRot);

                EditorGUI.indentLevel--;
            }

            serializedObject.ApplyModifiedProperties();

            if (GUI.changed)
            {
                EditorUtility.SetDirty(target);
            }
        }
Esempio n. 2
0
        public FPRaycastHit Raycast(FPRay ray, FP maxDistance, RaycastCallback callback = null)
        {
            IBody    hitBody;
            FPVector hitNormal;
            FP       hitFraction;

            FPVector origin    = ray.origin;
            FPVector direction = ray.direction;

            if (Raycast(origin, direction, callback, out hitBody, out hitNormal, out hitFraction))
            {
                if (hitFraction <= maxDistance)
                {
                    GameObject  other              = PhysicsManager.instance.GetGameObject(hitBody);
                    FPRigidBody bodyComponent      = other.GetComponent <FPRigidBody>();
                    FPCollider  colliderComponent  = other.GetComponent <FPCollider>();
                    FPTransform transformComponent = other.GetComponent <FPTransform>();
                    return(new FPRaycastHit(bodyComponent, colliderComponent, transformComponent, hitNormal, ray.origin, ray.direction, hitFraction));
                }
            }
            else
            {
                direction *= maxDistance;
                if (Raycast(origin, direction, callback, out hitBody, out hitNormal, out hitFraction))
                {
                    GameObject  other              = PhysicsManager.instance.GetGameObject(hitBody);
                    FPRigidBody bodyComponent      = other.GetComponent <FPRigidBody>();
                    FPCollider  colliderComponent  = other.GetComponent <FPCollider>();
                    FPTransform transformComponent = other.GetComponent <FPTransform>();
                    return(new FPRaycastHit(bodyComponent, colliderComponent, transformComponent, hitNormal, ray.origin, direction, hitFraction));
                }
            }
            return(null);
        }
Esempio n. 3
0
        /**
         *  @brief Add a new RigidBody to the world.
         *
         *  @param jRigidBody Instance of a {@link FPRigidBody}.
         **/
        public void AddBody(ICollider iCollider)
        {
            if (!(iCollider is FPCollider))
            {
                Debug.LogError("You have a 2D object but your Physics 2D is disabled.");
                return;
            }

            FPCollider FPCollider = (FPCollider)iCollider;

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

            FPRigidBody            tsRB        = FPCollider.GetComponent <FPRigidBody>();
            FPRigidBodyConstraints constraints = tsRB != null ? tsRB.constraints : FPRigidBodyConstraints.None;

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

            if (FPCollider.gameObject.transform.parent != null && FPCollider.gameObject.transform.parent.GetComponentInParent <FPCollider>() != null)
            {
                FPCollider parentCollider = FPCollider.gameObject.transform.parent.GetComponentInParent <FPCollider>();
                world.AddConstraint(new ConstraintHierarchy(parentCollider.Body, FPCollider._body, (FPCollider.GetComponent <FPTransform>().position + FPCollider.ScaledCenter) - (parentCollider.GetComponent <FPTransform>().position + parentCollider.ScaledCenter)));
            }

            FPCollider._body.FreezeConstraints = constraints;
        }
Esempio n. 4
0
 public FPRaycastHit(FPRigidBody rigidbody, FPCollider collider, FPTransform transform, FPVector normal, FPVector origin, FPVector direction, FP fraction)
 {
     this.rigidbody = rigidbody;
     this.collider  = collider;
     this.transform = transform;
     this.normal    = normal;
     this.point     = origin + direction * fraction;
     this.distance  = fraction * direction.magnitude;
 }
        protected override void OnStart()
        {
            if (!Application.isPlaying)
            {
                return;
            }

            Initialize();
            rb = GetComponent <FPRigidBody>();
        }
Esempio n. 6
0
        /**
         *  @brief Creates a new {@link FPRigidBody} when there is no one attached to this GameObject.
         **/
        public void Awake()
        {
            FPTransform = this.GetComponent <FPTransform>();
            FPRigidBody = this.GetComponent <FPRigidBody>();

            if (lossyScale == FPVector.one)
            {
                lossyScale = FPVector.Abs(transform.localScale.ToFPVector());
            }
        }
Esempio n. 7
0
        internal void Update(GameObject otherGO, Contact c)
        {
            if (this.gameObject == null)
            {
                this.gameObject = otherGO;
                this.collider   = this.gameObject.GetComponent <FPCollider>();
                this.rigidbody  = this.gameObject.GetComponent <FPRigidBody>();
                this.transform  = this.collider.FPTransform;
            }

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

                this.relativeVelocity = c.CalculateRelativeVelocity();

                contacts[0].normal = c.Normal;
                contacts[0].point  = c.p1;
            }
        }