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

            DrawDefaultInspector();

            serializedObject.Update();

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

            if (constraintsFoldout)
            {
                EditorGUI.indentLevel++;

                TSRigidBodyConstraints 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);
            }
        }
        /**
         *  @brief Add a new RigidBody to the world.
         *
         *  @param jRigidBody Instance of a {@link TSRigidBody}.
         **/
        public void AddBody(ICollider iCollider)
        {
            if (!(iCollider is TSCollider))
            {
                Debug.LogError("You have a 2D object but your Physics 2D is disabled.");
                return;
            }

            TSCollider tsCollider = (TSCollider)iCollider;

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

            TSRigidBody            tsRB        = tsCollider.GetComponent <TSRigidBody>();
            TSRigidBodyConstraints constraints = tsRB != null ? tsRB.constraints : TSRigidBodyConstraints.None;

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

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

            tsCollider._body.FreezeConstraints = constraints;
        }
        public void Clone(RigidBody rb)
        {
            this.marker            = rb.marker;
            this.affectedByGravity = rb.affectedByGravity;
            this.boundingBox       = rb.boundingBox;
            this.internalIndex     = rb.internalIndex;
            this.inverseMass       = rb.inverseMass;
            this.isColliderOnly    = rb.isColliderOnly;
            this.isStatic          = rb.isStatic;
            this.isKinematic       = rb.isKinematic;
            this.sweptDirection    = rb.sweptDirection;

            this.position       = rb.Position;
            this.orientation    = rb.Orientation;
            this.linearVelocity = rb.LinearVelocity;
            CBFrame.Utils.Logger.Debug("line401 this.linearVelocity:" + this.linearVelocity);
            this.angularVelocity = rb.AngularVelocity;
            this.inertia         = rb.Inertia;
            this.invInertia      = rb.InverseInertia;
            this.invInertiaWorld = rb.InverseInertiaWorld;
            this.invOrientation  = rb.invOrientation;
            this.force           = rb.Force;
            this.torque          = rb.Torque;

            this.shapeClone = poolGenericShapeClone.GetNew();
            this.shapeClone.Clone(rb.Shape);

            this.connections.Clear();
            for (index = 0, length = rb.connections.Count; index < length; index++)
            {
                this.connections.Add(rb.connections[index]);
            }
            this.constraints.Clear();
            for (index = 0, length = rb.constraints.Count; index < length; index++)
            {
                this.constraints.Add(rb.constraints[index]);
            }

            this.isActive = rb.IsActive;

            this.inactiveTime = rb.inactiveTime;

            this.marker = rb.marker;

            this.disabled = rb.disabled;

            this.freezeConstraint     = rb._freezeConstraints;
            this._freezePosition      = rb._freezePosition;
            this._freezeRotation      = rb._freezeRotation;
            this._freezeRotationQuat  = rb._freezeRotationQuat;
            this.prevKinematicGravity = rb.prevKinematicGravity;
            this.linearDrag           = rb.linearDrag;
            this.angularDrag          = rb.angularDrag;
            this.staticFriction       = rb.staticFriction;
            this.restitution          = rb.restitution;
        }
Example #4
0
 public void Clone(RigidBody rb)
 {
     this.marker            = rb.marker;
     this.affectedByGravity = rb.affectedByGravity;
     this.boundingBox       = rb.boundingBox;
     this.internalIndex     = rb.internalIndex;
     this.inverseMass       = rb.inverseMass;
     this.isColliderOnly    = rb.isColliderOnly;
     this.isStatic          = rb.isStatic;
     this.isKinematic       = rb.isKinematic;
     this.sweptDirection    = rb.sweptDirection;
     this.position          = rb.Position;
     this.orientation       = rb.Orientation;
     this.linearVelocity    = rb.LinearVelocity;
     this.angularVelocity   = rb.AngularVelocity;
     this.inertia           = rb.Inertia;
     this.invInertia        = rb.InverseInertia;
     this.invInertiaWorld   = rb.InverseInertiaWorld;
     this.invOrientation    = rb.invOrientation;
     this.force             = rb.Force;
     this.torque            = rb.Torque;
     this.shapeClone        = RigidBodyClone.poolGenericShapeClone.GetNew();
     this.shapeClone.Clone(rb.Shape);
     this.connections.Clear();
     this.index  = 0;
     this.length = rb.connections.Count;
     while (this.index < this.length)
     {
         this.connections.Add(rb.connections[this.index]);
         this.index++;
     }
     this.constraints.Clear();
     this.index  = 0;
     this.length = rb.constraints.Count;
     while (this.index < this.length)
     {
         this.constraints.Add(rb.constraints[this.index]);
         this.index++;
     }
     this.isActive            = rb.IsActive;
     this.inactiveTime        = rb.inactiveTime;
     this.marker              = rb.marker;
     this.disabled            = rb.disabled;
     this.freezeConstraint    = rb._freezeConstraints;
     this._freezePosition     = rb._freezePosition;
     this._freezeRotation     = rb._freezeRotation;
     this._freezeRotationQuat = rb._freezeRotationQuat;
 }
Example #5
0
        /**
         *  @brief Add a new RigidBody to the world.
         *
         *  @param jRigidBody Instance of a {@link TSRigidBody}.
         **/
        public void AddBody(ICollider iCollider)
        {
            if (!(iCollider is TSCollider))
            {
                Debug.LogError("You have a 2D object but your Physics 2D is disabled.");
                return;
            }

            TSCollider tsCollider = (TSCollider)iCollider;

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

            TSRigidBody            tsRB        = tsCollider.tsTransform.rb; // tsCollider.GetComponent<TSRigidBody>();
            TSRigidBodyConstraints constraints = tsRB != null ? tsRB.constraints : TSRigidBodyConstraints.None;

            tsCollider.Initialize();
            world.AddBody(tsCollider._body);
            GameObject gameObject = tsCollider.gameObject;

            gameObjectMap[tsCollider._body] = gameObject;

            HashList <TrueSyncBehaviour> behaviours = new HashList <TrueSyncBehaviour>();

            TrueSyncBehaviour[] behavioursArray = gameObject.GetComponents <TrueSyncBehaviour>();
            for (int i = 0, count = behavioursArray.Length; i < count; i++)
            {
                behaviours.Add(behavioursArray[i]);
            }
            behavioursMap[tsCollider._body] = behaviours;

            transformMap[tsCollider._body] = tsCollider.tsTransform;

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

            tsCollider._body.FreezeConstraints = constraints;
        }
        private static void DrawFreezePanel(ref TSRigidBodyConstraints freezeConstraint, bool position)
        {
            TSRigidBodyConstraints axisX = position ? TSRigidBodyConstraints.FreezePositionX : TSRigidBodyConstraints.FreezeRotationX;
            TSRigidBodyConstraints axisY = position ? TSRigidBodyConstraints.FreezePositionY : TSRigidBodyConstraints.FreezeRotationY;
            TSRigidBodyConstraints axisZ = position ? TSRigidBodyConstraints.FreezePositionZ : TSRigidBodyConstraints.FreezeRotationZ;

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.PrefixLabel(position ? "Freeze Position" : "Freeze Rotation");

            Rect controlRect = GUILayoutUtility.GetLastRect();

            controlRect.width = 30;
            controlRect.x    += EditorGUIUtility.labelWidth;

            bool fX = GUI.Toggle(controlRect, CheckAxis(freezeConstraint, axisX), "X");

            controlRect.x += 30;
            bool fY = GUI.Toggle(controlRect, CheckAxis(freezeConstraint, axisY), "Y");

            controlRect.x += 30;
            bool fZ = GUI.Toggle(controlRect, CheckAxis(freezeConstraint, axisZ), "Z");

            freezeConstraint = TSRigidBodyConstraints.None;

            if (fX)
            {
                freezeConstraint |= axisX;
            }

            if (fY)
            {
                freezeConstraint |= axisY;
            }

            if (fZ)
            {
                freezeConstraint |= axisZ;
            }

            EditorGUILayout.EndHorizontal();
        }
 private static bool CheckAxis(TSRigidBodyConstraints toCheck, TSRigidBodyConstraints axis)
 {
     return((toCheck & axis) == axis);
 }