예제 #1
0
        public static Constraint.ECollisionsState ConstraintCollisionsStateGUI(Constraint.ECollisionsState state, GUISkin skin)
        {
            bool guiWasEnabled = UnityEngine.GUI.enabled;

            using (new GUI.Indent(12)) {
                GUILayout.BeginHorizontal();
                {
                    GUILayout.Label(GUI.MakeLabel("Disable collisions: ", true), GUI.Align(skin.label, TextAnchor.MiddleLeft), new GUILayoutOption[] { GUILayout.Width(140), GUILayout.Height(25) });

                    UnityEngine.GUI.enabled = !EditorApplication.isPlaying;
                    if (GUILayout.Button(GUI.MakeLabel("Rb " + GUI.Symbols.Synchronized.ToString() + " Rb", false, "Disable all shapes in rigid body 1 against all shapes in rigid body 2."),
                                         GUI.ConditionalCreateSelectedStyle(state == Constraint.ECollisionsState.DisableRigidBody1VsRigidBody2, skin.button),
                                         new GUILayoutOption[] { GUILayout.Width(76), GUILayout.Height(25) }))
                    {
                        state = state == Constraint.ECollisionsState.DisableRigidBody1VsRigidBody2 ?
                                Constraint.ECollisionsState.KeepExternalState :
                                Constraint.ECollisionsState.DisableRigidBody1VsRigidBody2;
                    }

                    if (GUILayout.Button(GUI.MakeLabel("Ref " + GUI.Symbols.Synchronized.ToString() + " Con", false, "Disable Reference object vs. Connected object."),
                                         GUI.ConditionalCreateSelectedStyle(state == Constraint.ECollisionsState.DisableReferenceVsConnected, skin.button),
                                         new GUILayoutOption[] { GUILayout.Width(76), GUILayout.Height(25) }))
                    {
                        state = state == Constraint.ECollisionsState.DisableReferenceVsConnected ?
                                Constraint.ECollisionsState.KeepExternalState :
                                Constraint.ECollisionsState.DisableReferenceVsConnected;
                    }
                    UnityEngine.GUI.enabled = guiWasEnabled;
                }
                GUILayout.EndHorizontal();
            }

            return(state);
        }
예제 #2
0
        public override void OnPreTargetMembersGUI(GUISkin skin)
        {
            if (AttachmentPair == null)
            {
                PerformRemoveFromParent();
                return;
            }

            bool guiWasEnabled = UnityEngine.GUI.enabled;

            using (new GUI.Indent(12)) {
                Undo.RecordObject(AttachmentPair, "Constraint Tool");

                GUILayout.Label(GUI.MakeLabel("Reference frame", true), skin.label);
                GUI.HandleFrame(AttachmentPair.ReferenceFrame, skin, 4 + 12);
                GUILayout.BeginHorizontal();
                GUILayout.Space(12);
                if (GUILayout.Button(GUI.MakeLabel(GUI.Symbols.Synchronized.ToString(), false, "Synchronized with reference frame"),
                                     GUI.ConditionalCreateSelectedStyle(AttachmentPair.Synchronized, skin.button),
                                     new GUILayoutOption[] { GUILayout.Width(24), GUILayout.Height(14) }))
                {
                    AttachmentPair.Synchronized = !AttachmentPair.Synchronized;
                    if (AttachmentPair.Synchronized)
                    {
                        ConnectedFrameTool.TransformHandleActive = false;
                    }
                }
                GUILayout.Label(GUI.MakeLabel("Connected frame", true), skin.label);
                GUILayout.EndHorizontal();
                UnityEngine.GUI.enabled = !AttachmentPair.Synchronized;
                GUI.HandleFrame(AttachmentPair.ConnectedFrame, skin, 4 + 12);
                UnityEngine.GUI.enabled = guiWasEnabled;
            }
        }
예제 #3
0
        public override void OnPreTargetMembersGUI()
        {
            var isMultiSelect = AttachmentPairs.Length > 1;

            Undo.RecordObjects(AttachmentPairs, "Constraint Attachment");

            var skin          = InspectorEditor.Skin;
            var guiWasEnabled = UnityEngine.GUI.enabled;

            using (new GUI.Indent(12)) {
                var connectedFrameSynchronized = AttachmentPairs.All(ap => ap.Synchronized);

                GUILayout.Label(GUI.MakeLabel("Reference frame", true), skin.label);
                GUI.HandleFrames(AttachmentPairs.Select(ap => ap.ReferenceFrame).ToArray(), 4 + 12);

                using (new GUILayout.HorizontalScope()) {
                    GUILayout.Space(12);
                    if (GUILayout.Button(GUI.MakeLabel(GUI.Symbols.Synchronized.ToString(),
                                                       false,
                                                       "Synchronized with reference frame"),
                                         GUI.ConditionalCreateSelectedStyle(connectedFrameSynchronized, skin.button),
                                         new GUILayoutOption[] { GUILayout.Width(24), GUILayout.Height(14) }))
                    {
                        foreach (var ap in AttachmentPairs)
                        {
                            ap.Synchronized = !connectedFrameSynchronized;
                        }

                        if (!isMultiSelect && AttachmentPairs[0].Synchronized)
                        {
                            ConnectedFrameTool.TransformHandleActive = false;
                        }
                    }
                    GUILayout.Label(GUI.MakeLabel("Connected frame", true), skin.label);
                }

                UnityEngine.GUI.enabled = !connectedFrameSynchronized && !isMultiSelect;
                GUI.HandleFrames(AttachmentPairs.Select(ap => ap.ConnectedFrame).ToArray(), 4 + 12);
                UnityEngine.GUI.enabled = guiWasEnabled;
            }
        }
예제 #4
0
        private void HandleModeRigidBodyGUI(GUISkin skin)
        {
            GUI.Separator3D();

            using (GUI.AlignBlock.Center) {
                if (m_subMode == SubMode.SelectRigidBody)
                {
                    GUILayout.Label(GUI.MakeLabel("Select rigid body object in scene view.", true), skin.label);
                }
                else
                {
                    GUILayout.Label(GUI.MakeLabel("Select object(s) in scene view.", true), skin.label);
                }
            }

            GUI.Separator();

            bool selectionHasRigidBody         = m_selection.Find(entry => entry.Object.GetComponentInParent <RigidBody>() != null) != null;
            bool createNewRigidBodyPressed     = false;
            bool addToExistingRigidBodyPressed = false;
            bool moveToNewRigidBodyPressed     = false;

            GUILayout.BeginHorizontal();
            {
                GUILayout.Space(12);
                GUILayout.BeginVertical();
                {
                    UnityEngine.GUI.enabled       = m_selection.Count == 0 || !selectionHasRigidBody;
                    createNewRigidBodyPressed     = GUILayout.Button(GUI.MakeLabel("Create new" + (m_selection.Count == 0 ? " (empty)" : ""), false, "Create new rigid body with selected objects"), skin.button, GUILayout.Width(128));
                    UnityEngine.GUI.enabled       = m_selection.Count > 0 && Assembly.GetComponentInChildren <RigidBody>() != null;
                    addToExistingRigidBodyPressed = GUILayout.Button(GUI.MakeLabel("Add to existing", false, "Add selected objects to existing rigid body"), GUI.ConditionalCreateSelectedStyle(m_subMode == SubMode.SelectRigidBody, skin.button), GUILayout.Width(100));
                    UnityEngine.GUI.enabled       = selectionHasRigidBody;
                    moveToNewRigidBodyPressed     = GUILayout.Button(GUI.MakeLabel("Move to new", false, "Move objects that already contains a rigid body to a new rigid body"), skin.button, GUILayout.Width(85));
                    UnityEngine.GUI.enabled       = true;
                }
                GUILayout.EndVertical();
            }
            GUILayout.EndHorizontal();

            GUI.Separator3D();

            // Creates new rigid body and move selected objects to it (as children).
            if (createNewRigidBodyPressed || moveToNewRigidBodyPressed)
            {
                CreateOrMoveToRigidBodyFromSelectionEntries(m_selection);
                m_selection.Clear();
            }
            // Toggle to select a rigid body in scene view to move the current selection to.
            else if (addToExistingRigidBodyPressed)
            {
                // This will toggle if sub-mode already is SelectRigidBody.
                ChangeSubMode(SubMode.SelectRigidBody);
            }

            // The user has chosen a rigid body to move the current selection to.
            if (m_rbSelection != null)
            {
                CreateOrMoveToRigidBodyFromSelectionEntries(m_selection, m_rbSelection.RigidBody.gameObject);
                m_selection.Clear();
                ChangeSubMode(SubMode.None);
            }
        }
예제 #5
0
        public override void OnPreTargetMembersGUI(GUISkin skin)
        {
            // TODO: Improvements.
            //   - "Copy-paste" shape.
            //       1. Select object with primitive shape(s)
            //       2. Select object to copy the shape(s) to
            //   - Move from-to existing bodies or create a new body.
            //   - Mesh object operations.
            //       * Simplify assembly
            //       * Multi-select to create meshes
            //   - Inspect element (hold 'i').

            if (!AGXUnity.Utils.Math.IsUniform(Assembly.transform.lossyScale, 1.0E-3f))
            {
                Debug.LogWarning("Scale of AGXUnity.Assembly transform isn't uniform. If a child rigid body is moving under this transform the (visual) behavior is undefined.", Assembly);
            }

            bool rbButtonPressed         = false;
            bool shapeButtonPressed      = false;
            bool constraintButtonPressed = false;

            GUI.ToolsLabel(skin);
            GUILayout.BeginHorizontal();
            {
                GUILayout.Space(12);
                using (GUI.ToolButtonData.ColorBlock) {
                    rbButtonPressed         = GUILayout.Button(GUI.MakeLabel("RB", true, "Assembly rigid body tool"), GUI.ConditionalCreateSelectedStyle(m_mode == Mode.RigidBody, skin.button), GUILayout.Width(30f), GUI.ToolButtonData.Height);
                    shapeButtonPressed      = GUILayout.Button(GUI.MakeLabel("Shape", true, "Assembly shape tool"), GUI.ConditionalCreateSelectedStyle(m_mode == Mode.Shape, skin.button), GUILayout.Width(54f), GUI.ToolButtonData.Height);
                    constraintButtonPressed = GUILayout.Button(GUI.MakeLabel("Constraint", true, "Assembly constraint tool"), GUI.ConditionalCreateSelectedStyle(m_mode == Mode.Constraint, skin.button), GUILayout.Width(80f), GUI.ToolButtonData.Height);
                }
            }
            GUILayout.EndHorizontal();

            HandleModeGUI(skin);

            if (rbButtonPressed)
            {
                ChangeMode(Mode.RigidBody);
            }
            if (shapeButtonPressed)
            {
                ChangeMode(Mode.Shape);
            }
            if (constraintButtonPressed)
            {
                ChangeMode(Mode.Constraint);
            }
        }