private void ShowBodyInfoProperties()
 {
     this.m_ShowInfo.target = EditorGUILayout.Foldout(this.m_ShowInfo.target, "Info", true);
     if (EditorGUILayout.BeginFadeGroup(this.m_ShowInfo.faded))
     {
         if (base.targets.Length == 1)
         {
             Rigidbody2D rigidbody2D = base.targets[0] as Rigidbody2D;
             EditorGUI.BeginDisabledGroup(true);
             EditorGUILayout.Vector2Field("Position", rigidbody2D.position, new GUILayoutOption[0]);
             EditorGUILayout.FloatField("Rotation", rigidbody2D.rotation, new GUILayoutOption[0]);
             EditorGUILayout.Vector2Field("Velocity", rigidbody2D.velocity, new GUILayoutOption[0]);
             EditorGUILayout.FloatField("Angular Velocity", rigidbody2D.angularVelocity, new GUILayoutOption[0]);
             EditorGUILayout.FloatField("Inertia", rigidbody2D.inertia, new GUILayoutOption[0]);
             EditorGUILayout.Vector2Field("Local Center of Mass", rigidbody2D.centerOfMass, new GUILayoutOption[0]);
             EditorGUILayout.Vector2Field("World Center of Mass", rigidbody2D.worldCenterOfMass, new GUILayoutOption[0]);
             EditorGUILayout.LabelField("Sleep State", (!rigidbody2D.IsSleeping()) ? "Awake" : "Asleep", new GUILayoutOption[0]);
             EditorGUI.EndDisabledGroup();
             this.ShowContacts(rigidbody2D);
             base.Repaint();
         }
         else
         {
             EditorGUILayout.HelpBox("Cannot show Info properties when multiple bodies are selected.", MessageType.Info);
         }
     }
     Rigidbody2DEditor.FixedEndFadeGroup(this.m_ShowInfo.faded);
 }
Example #2
0
        public override void OnInspectorGUI()
        {
            Rigidbody2D rigidbody2D = base.target as Rigidbody2D;

            base.serializedObject.Update();
            EditorGUILayout.PropertyField(this.m_BodyType, new GUILayoutOption[0]);
            EditorGUILayout.PropertyField(this.m_Material, new GUILayoutOption[0]);
            EditorGUILayout.PropertyField(this.m_Simulated, new GUILayoutOption[0]);
            if (this.m_BodyType.hasMultipleDifferentValues)
            {
                EditorGUILayout.HelpBox("Cannot edit properties that are body type specific when the selection contains different body types.", MessageType.Info);
            }
            else
            {
                this.m_ShowIsStatic.target = (rigidbody2D.bodyType != RigidbodyType2D.Static);
                if (EditorGUILayout.BeginFadeGroup(this.m_ShowIsStatic.faded))
                {
                    this.m_ShowIsKinematic.target = (rigidbody2D.bodyType != RigidbodyType2D.Kinematic);
                    if (EditorGUILayout.BeginFadeGroup(this.m_ShowIsKinematic.faded))
                    {
                        EditorGUILayout.PropertyField(this.m_UseAutoMass, new GUILayoutOption[0]);
                        EditorGUI.BeginDisabledGroup(rigidbody2D.useAutoMass);
                        EditorGUILayout.PropertyField(this.m_Mass, new GUILayoutOption[0]);
                        EditorGUI.EndDisabledGroup();
                        EditorGUILayout.PropertyField(this.m_LinearDrag, new GUILayoutOption[0]);
                        EditorGUILayout.PropertyField(this.m_AngularDrag, new GUILayoutOption[0]);
                        EditorGUILayout.PropertyField(this.m_GravityScale, new GUILayoutOption[0]);
                    }
                    Rigidbody2DEditor.FixedEndFadeGroup(this.m_ShowIsKinematic.faded);
                    if (!this.m_ShowIsKinematic.target)
                    {
                        EditorGUILayout.PropertyField(this.m_UseFullKinematicContacts, new GUILayoutOption[0]);
                    }
                    EditorGUILayout.PropertyField(this.m_CollisionDetection, new GUILayoutOption[0]);
                    EditorGUILayout.PropertyField(this.m_SleepingMode, new GUILayoutOption[0]);
                    EditorGUILayout.PropertyField(this.m_Interpolate, new GUILayoutOption[0]);
                    GUILayout.BeginHorizontal(new GUILayoutOption[0]);
                    this.m_Constraints.isExpanded = EditorGUILayout.Foldout(this.m_Constraints.isExpanded, "Constraints", true);
                    GUILayout.EndHorizontal();
                    RigidbodyConstraints2D intValue = (RigidbodyConstraints2D)this.m_Constraints.intValue;
                    if (this.m_Constraints.isExpanded)
                    {
                        EditorGUI.indentLevel++;
                        this.ToggleFreezePosition(intValue, Rigidbody2DEditor.m_FreezePositionLabel, 0, 1);
                        this.ToggleFreezeRotation(intValue, Rigidbody2DEditor.m_FreezeRotationLabel, 2);
                        EditorGUI.indentLevel--;
                    }
                    if (intValue == RigidbodyConstraints2D.FreezeAll)
                    {
                        EditorGUILayout.HelpBox("Rather than turning on all constraints, you may want to consider removing the Rigidbody2D component which makes any colliders static.  This gives far better performance overall.", MessageType.Info);
                    }
                }
                Rigidbody2DEditor.FixedEndFadeGroup(this.m_ShowIsStatic.faded);
            }
            base.serializedObject.ApplyModifiedProperties();
            this.ShowBodyInfoProperties();
        }
 private void ShowContacts(Rigidbody2D body)
 {
     EditorGUI.indentLevel++;
     this.m_ShowContacts.target = EditorGUILayout.Foldout(this.m_ShowContacts.target, "Contacts");
     if (EditorGUILayout.BeginFadeGroup(this.m_ShowContacts.faded))
     {
         int contacts = body.GetContacts(Rigidbody2DEditor.m_Contacts);
         if (contacts > 0)
         {
             this.m_ContactScrollPosition = EditorGUILayout.BeginScrollView(this.m_ContactScrollPosition, new GUILayoutOption[]
             {
                 GUILayout.Height(180f)
             });
             EditorGUI.BeginDisabledGroup(true);
             for (int i = 0; i < contacts; i++)
             {
                 ContactPoint2D contactPoint2D = Rigidbody2DEditor.m_Contacts[i];
                 EditorGUILayout.HelpBox(string.Format("Contact#{0}", i), MessageType.None);
                 EditorGUI.indentLevel++;
                 EditorGUILayout.Vector2Field("Point", contactPoint2D.point, new GUILayoutOption[0]);
                 EditorGUILayout.Vector2Field("Normal", contactPoint2D.normal, new GUILayoutOption[0]);
                 EditorGUILayout.Vector2Field("Relative Velocity", contactPoint2D.relativeVelocity, new GUILayoutOption[0]);
                 EditorGUILayout.FloatField("Normal Impulse", contactPoint2D.normalImpulse, new GUILayoutOption[0]);
                 EditorGUILayout.FloatField("Tangent Impulse", contactPoint2D.tangentImpulse, new GUILayoutOption[0]);
                 EditorGUILayout.ObjectField("Collider", contactPoint2D.collider, typeof(Collider2D), true, new GUILayoutOption[0]);
                 EditorGUILayout.ObjectField("Rigidbody", contactPoint2D.rigidbody, typeof(Rigidbody2D), false, new GUILayoutOption[0]);
                 EditorGUILayout.ObjectField("OtherCollider", contactPoint2D.otherCollider, typeof(Collider2D), false, new GUILayoutOption[0]);
                 EditorGUI.indentLevel--;
                 EditorGUILayout.Space();
             }
             EditorGUI.EndDisabledGroup();
             EditorGUILayout.EndScrollView();
         }
         else
         {
             EditorGUILayout.HelpBox("No Contacts", MessageType.Info);
         }
     }
     Rigidbody2DEditor.FixedEndFadeGroup(this.m_ShowContacts.faded);
     EditorGUI.indentLevel--;
 }
        public override void OnInspectorGUI()
        {
            Rigidbody2D rigidbody2D = base.target as Rigidbody2D;

            base.serializedObject.Update();
            EditorGUILayout.PropertyField(this.m_BodyType, new GUILayoutOption[0]);
            EditorGUILayout.PropertyField(this.m_Material, new GUILayoutOption[0]);
            EditorGUILayout.PropertyField(this.m_Simulated, new GUILayoutOption[0]);
            if (!this.m_Simulated.boolValue && !this.m_Simulated.hasMultipleDifferentValues)
            {
                EditorGUILayout.HelpBox("The body has now been taken out of the simulation along with any attached colliders, joints or effectors.", MessageType.Info);
            }
            if (this.m_BodyType.hasMultipleDifferentValues)
            {
                EditorGUILayout.HelpBox("Cannot edit properties that are body type specific when the selection contains different body types.", MessageType.Info);
            }
            else
            {
                this.m_ShowIsStatic.target = (rigidbody2D.bodyType != RigidbodyType2D.Static);
                if (EditorGUILayout.BeginFadeGroup(this.m_ShowIsStatic.faded))
                {
                    this.m_ShowIsKinematic.target = (rigidbody2D.bodyType != RigidbodyType2D.Kinematic);
                    if (EditorGUILayout.BeginFadeGroup(this.m_ShowIsKinematic.faded))
                    {
                        EditorGUILayout.PropertyField(this.m_UseAutoMass, new GUILayoutOption[0]);
                        if (!this.m_UseAutoMass.hasMultipleDifferentValues)
                        {
                            if (this.m_UseAutoMass.boolValue)
                            {
                                if (base.targets.Any((UnityEngine.Object x) => PrefabUtility.GetPrefabType(x) == PrefabType.Prefab || !(x as Rigidbody2D).gameObject.activeInHierarchy))
                                {
                                    EditorGUILayout.HelpBox("The auto mass value cannot be displayed for a prefab or if the object is not active.  The value will be calculated for a prefab instance and when the object is active.", MessageType.Info);
                                    goto IL_18C;
                                }
                            }
                            EditorGUI.BeginDisabledGroup(rigidbody2D.useAutoMass);
                            EditorGUILayout.PropertyField(this.m_Mass, new GUILayoutOption[0]);
                            EditorGUI.EndDisabledGroup();
                            IL_18C :;
                        }
                        EditorGUILayout.PropertyField(this.m_LinearDrag, new GUILayoutOption[0]);
                        EditorGUILayout.PropertyField(this.m_AngularDrag, new GUILayoutOption[0]);
                        EditorGUILayout.PropertyField(this.m_GravityScale, new GUILayoutOption[0]);
                    }
                    Rigidbody2DEditor.FixedEndFadeGroup(this.m_ShowIsKinematic.faded);
                    if (!this.m_ShowIsKinematic.target)
                    {
                        EditorGUILayout.PropertyField(this.m_UseFullKinematicContacts, new GUILayoutOption[0]);
                    }
                    EditorGUILayout.PropertyField(this.m_CollisionDetection, new GUILayoutOption[0]);
                    EditorGUILayout.PropertyField(this.m_SleepingMode, new GUILayoutOption[0]);
                    EditorGUILayout.PropertyField(this.m_Interpolate, new GUILayoutOption[0]);
                    GUILayout.BeginHorizontal(new GUILayoutOption[0]);
                    this.m_Constraints.isExpanded = EditorGUILayout.Foldout(this.m_Constraints.isExpanded, "Constraints", true);
                    GUILayout.EndHorizontal();
                    RigidbodyConstraints2D intValue = (RigidbodyConstraints2D)this.m_Constraints.intValue;
                    if (this.m_Constraints.isExpanded)
                    {
                        EditorGUI.indentLevel++;
                        this.ToggleFreezePosition(intValue, Rigidbody2DEditor.m_FreezePositionLabel, 0, 1);
                        this.ToggleFreezeRotation(intValue, Rigidbody2DEditor.m_FreezeRotationLabel, 2);
                        EditorGUI.indentLevel--;
                    }
                    if (intValue == RigidbodyConstraints2D.FreezeAll)
                    {
                        EditorGUILayout.HelpBox("Rather than turning on all constraints, you may want to consider removing the Rigidbody2D component which makes any colliders static.  This gives far better performance overall.", MessageType.Info);
                    }
                }
                Rigidbody2DEditor.FixedEndFadeGroup(this.m_ShowIsStatic.faded);
            }
            base.serializedObject.ApplyModifiedProperties();
            this.ShowBodyInfoProperties();
        }