Ejemplo n.º 1
0
        public override void OnPostTargetMembersGUI()
        {
            var skin = InspectorEditor.Skin;

            var beginWinches = GetTargets <Wire, WireWinch>(wire => wire.BeginWinch).Where(winch => winch != null);
            var endWinches   = GetTargets <Wire, WireWinch>(wire => wire.EndWinch).Where(winch => winch != null);

            if (beginWinches.Count() > 0)
            {
                GUILayout.Label(GUI.MakeLabel("Begin winch", true), skin.Label);
                using (InspectorGUI.IndentScope.Single) {
                    if (beginWinches.Count() != NumTargets)
                    {
                        InspectorGUI.WarningLabel("Not all selected wires has a begin winch.");
                    }
                    InspectorEditor.DrawMembersGUI(beginWinches.ToArray());
                }
            }
            if (endWinches.Count() > 0)
            {
                GUILayout.Label(GUI.MakeLabel("End winch", true), skin.Label);
                using (InspectorGUI.IndentScope.Single) {
                    if (endWinches.Count() != NumTargets)
                    {
                        InspectorGUI.WarningLabel("Not all selected wires has an end winch.");
                    }
                    InspectorEditor.DrawMembersGUI(endWinches.ToArray());
                }
            }
        }
Ejemplo n.º 2
0
        public override void OnPostTargetMembersGUI()
        {
            var skin = InspectorEditor.Skin;

            var beginWinches = GetTargets <Wire, WireWinch>(wire => wire.BeginWinch).Where(winch => winch != null);
            var endWinches   = GetTargets <Wire, WireWinch>(wire => wire.EndWinch).Where(winch => winch != null);

            if (beginWinches.Count() > 0)
            {
                GUI.Separator();
                GUILayout.Label(GUI.MakeLabel("Begin winch", true), skin.label);
                using (new GUI.Indent(12)) {
                    if (beginWinches.Count() != NumTargets)
                    {
                        AGXUnity.Utils.GUI.WarningLabel("Not all selected wires has a begin winch.", skin);
                    }
                    InspectorEditor.DrawMembersGUI(beginWinches.ToArray());
                }
                GUI.Separator();
            }
            if (endWinches.Count() > 0)
            {
                if (beginWinches.Count() == 0)
                {
                    GUI.Separator();
                }

                GUILayout.Label(GUI.MakeLabel("End winch", true), skin.label);
                using (new GUI.Indent(12)) {
                    if (endWinches.Count() != NumTargets)
                    {
                        AGXUnity.Utils.GUI.WarningLabel("Not all selected wires has an end winch.", skin);
                    }
                    InspectorEditor.DrawMembersGUI(endWinches.ToArray());
                }
                GUI.Separator();
            }
        }
Ejemplo n.º 3
0
        private void OnContactMaterialsList()
        {
            var             skin = InspectorEditor.Skin;
            ContactMaterial contactMaterialToAdd    = null;
            ContactMaterial contactMaterialToRemove = null;

            GUILayout.Label(GUI.MakeLabel("Contact Material Manager", 18, true), new GUIStyle(skin.label)
            {
                alignment = TextAnchor.MiddleCenter
            });
            GUILayout.Space(4);
            GUILayout.Label(GUI.MakeLabel("Drag and drop contact materials into the list below to add/enable the contact material in the simulation."),
                            new GUIStyle(skin.textArea)
            {
                alignment = TextAnchor.MiddleCenter
            });
            GUILayout.Space(4);

            GUI.Separator3D();

            GUILayout.BeginVertical();
            {
                if (GUI.Foldout(FoldoutDataEntry, GUI.MakeLabel("Contact Materials [" + Manager.ContactMaterialEntries.Length + "]"), skin))
                {
                    var contactMaterials = Manager.ContactMaterials;
                    using (new GUI.Indent(12)) {
                        foreach (var contactMaterial in contactMaterials)
                        {
                            GUI.Separator();

                            bool foldoutActive = false;

                            GUILayout.BeginHorizontal();
                            {
                                foldoutActive = GUI.Foldout(EditorData.Instance.GetData(Manager,
                                                                                        contactMaterial.name +
                                                                                        "_" +
                                                                                        contactMaterial.GetInstanceID().ToString()),
                                                            GUI.MakeLabel(contactMaterial.name),
                                                            skin);
                                using (GUI.NodeListButtonColor)
                                    if (GUILayout.Button(GUI.MakeLabel(GUI.Symbols.ListEraseElement.ToString(), false, "Erase this element"),
                                                         skin.button,
                                                         new GUILayoutOption[] { GUILayout.Width(20), GUILayout.Height(14) }))
                                    {
                                        contactMaterialToRemove = contactMaterial;
                                    }
                            }
                            GUILayout.EndHorizontal();

                            if (foldoutActive)
                            {
                                using (new GUI.Indent(12))
                                    InspectorEditor.DrawMembersGUI(new Object[] { contactMaterial });
                            }
                        }
                    }
                }
            }
            GUILayout.EndVertical();

            // Note that GetLastRect is used here and it's expecting the begin/end vertical rect.
            GUI.HandleDragDrop <ContactMaterial>(GUILayoutUtility.GetLastRect(),
                                                 Event.current,
                                                 (contactMaterial) =>
            {
                contactMaterialToAdd = contactMaterial;
            });

            GUI.Separator();

            GUILayout.BeginHorizontal();
            {
                GUILayout.Label(GUI.MakeLabel("Add:"), skin.label);
                contactMaterialToAdd = EditorGUILayout.ObjectField(null, typeof(ContactMaterial), false) as ContactMaterial ?? contactMaterialToAdd;
            }
            GUILayout.EndHorizontal();

            GUI.Separator3D();

            if (contactMaterialToAdd != null)
            {
                Manager.Add(contactMaterialToAdd);
                FoldoutDataEntry.Bool = true;
            }

            if (contactMaterialToRemove != null)
            {
                Manager.Remove(contactMaterialToRemove);
            }
        }
Ejemplo n.º 4
0
        public override void OnPreTargetMembersGUI()
        {
            var skin = InspectorEditor.Skin;

            bool toggleShapeCreate           = false;
            bool toggleConstraintCreate      = false;
            bool toggleDisableCollisions     = false;
            bool toggleRigidBodyVisualCreate = false;

            if (!IsMultiSelect && ToolsActive)
            {
                InspectorGUI.ToolButtons(InspectorGUI.ToolButtonData.Create(ToolIcon.CreateConstraint,
                                                                            ConstraintCreateTool,
                                                                            "Create new constraint to this rigid body.",
                                                                            () => toggleConstraintCreate = true),
                                         InspectorGUI.ToolButtonData.Create(ToolIcon.DisableCollisions,
                                                                            DisableCollisionsTool,
                                                                            "Disable collisions against other objects.",
                                                                            () => toggleDisableCollisions = true),
                                         InspectorGUI.ToolButtonData.Create(ToolIcon.CreateShapeGivenVisual,
                                                                            ShapeCreateTool,
                                                                            "Create shape from child visual object.",
                                                                            () => toggleShapeCreate = true),
                                         InspectorGUI.ToolButtonData.Create(ToolIcon.CreateVisual,
                                                                            RigidBodyVisualCreateTool,
                                                                            "Create visual representation of each physical shape in this body.",
                                                                            () => toggleRigidBodyVisualCreate = true,
                                                                            Tools.RigidBodyVisualCreateTool.ValidForNewShapeVisuals(RigidBody)));
            }

            if (ConstraintCreateTool)
            {
                GetChild <ConstraintCreateTool>().OnInspectorGUI();
            }
            if (DisableCollisionsTool)
            {
                GetChild <DisableCollisionsTool>().OnInspectorGUI();
            }
            if (ShapeCreateTool)
            {
                GetChild <ShapeCreateTool>().OnInspectorGUI();
            }
            if (RigidBodyVisualCreateTool)
            {
                GetChild <RigidBodyVisualCreateTool>().OnInspectorGUI();
            }

            EditorGUILayout.LabelField(GUI.MakeLabel("Mass properties", true), skin.Label);
            using (InspectorGUI.IndentScope.Single)
                InspectorEditor.DrawMembersGUI(GetTargets <RigidBody>().Select(rb => rb.MassProperties).ToArray());

            if (toggleConstraintCreate)
            {
                ConstraintCreateTool = !ConstraintCreateTool;
            }
            if (toggleDisableCollisions)
            {
                DisableCollisionsTool = !DisableCollisionsTool;
            }
            if (toggleShapeCreate)
            {
                ShapeCreateTool = !ShapeCreateTool;
            }
            if (toggleRigidBodyVisualCreate)
            {
                RigidBodyVisualCreateTool = !RigidBodyVisualCreateTool;
            }
        }
Ejemplo n.º 5
0
        public override void OnPreTargetMembersGUI()
        {
            var skin           = InspectorEditor.Skin;
            var constraints    = GetTargets <Constraint>().ToArray();
            var refConstraint  = constraints[0];
            var differentTypes = false;
            var anyUnknownType = constraints.Any(c => c.Type == ConstraintType.Unknown);

            for (int i = 1; i < constraints.Length; ++i)
            {
                differentTypes = differentTypes || refConstraint.Type != constraints[i].Type;
            }

            // Render AttachmentPair GUI.
            ConstraintAttachmentFrameTool.OnPreTargetMembersGUI();

            Undo.RecordObjects(constraints, "ConstraintTool");

            UnityEngine.GUI.changed = false;

            // The constraint type is Unknown when, e.g., go.AddComponent<Constraint>()
            // or when the constraint has been reset. If any of the selected constraints
            // is of type Unknown, we exit the GUI here.
            if (!ConstraintTypeGUI(constraints, differentTypes))
            {
                return;
            }

            EditorGUI.showMixedValue = constraints.Any(constraint => refConstraint.CollisionsState != constraint.CollisionsState);
            var collisionsState = ConstraintCollisionsStateGUI(refConstraint.CollisionsState);

            EditorGUI.showMixedValue = false;

            if (UnityEngine.GUI.changed)
            {
                foreach (var constraint in constraints)
                {
                    constraint.CollisionsState = collisionsState;
                }
                UnityEngine.GUI.changed = false;
            }

            EditorGUI.showMixedValue = constraints.Any(constraint => refConstraint.SolveType != constraint.SolveType);
            var solveType = ConstraintSolveTypeGUI(refConstraint.SolveType);

            EditorGUI.showMixedValue = false;

            if (UnityEngine.GUI.changed)
            {
                foreach (var constraint in constraints)
                {
                    constraint.SolveType = solveType;
                }
                UnityEngine.GUI.changed = false;
            }

            EditorGUI.showMixedValue = constraints.Any(constraint => refConstraint.ConnectedFrameNativeSyncEnabled != constraint.ConnectedFrameNativeSyncEnabled);
            var frameNativeSync = ConstraintConnectedFrameSyncGUI(refConstraint.ConnectedFrameNativeSyncEnabled);

            EditorGUI.showMixedValue = false;

            if (UnityEngine.GUI.changed)
            {
                foreach (var constraint in constraints)
                {
                    constraint.ConnectedFrameNativeSyncEnabled = frameNativeSync;
                }
                UnityEngine.GUI.changed = false;
            }

            if (differentTypes)
            {
                InspectorGUI.WarningLabel("Constraints are of different types.\nRow data editing not supported.");
                return;
            }

            Func <string, EditorDataEntry> selected = (id) =>
            {
                return(EditorData.Instance.GetData(refConstraint, id, entry => entry.Bool = false));
            };

            var constraintsParser = (from constraint
                                     in constraints
                                     select ConstraintUtils.ConstraintRowParser.Create(constraint)).ToArray();
            var allElementaryConstraints = constraints.SelectMany(constraint => constraint.GetOrdinaryElementaryConstraints()).ToArray();

            Undo.RecordObjects(allElementaryConstraints, "ConstraintTool");

            var ecRowDataWrappers = InvokeWrapper.FindFieldsAndProperties <ElementaryConstraintRowData>();

            foreach (ConstraintUtils.ConstraintRowParser.RowType rowType in Enum.GetValues(typeof(ConstraintUtils.ConstraintRowParser.RowType)))
            {
                if (!InspectorGUI.Foldout(selected("ec_" + rowType.ToString()),
                                          GUI.MakeLabel(rowType.ToString() + " properties", true)))
                {
                    continue;
                }

                using (InspectorGUI.IndentScope.Single) {
                    var refTransOrRotRowData = constraintsParser[0][rowType];
                    foreach (var wrapper in ecRowDataWrappers)
                    {
                        if (!InspectorEditor.ShouldBeShownInInspector(wrapper.Member))
                        {
                            continue;
                        }

                        for (int i = 0; i < 3; ++i)
                        {
                            var rowDataInstances = (from constraintParser
                                                    in constraintsParser
                                                    where constraintParser[rowType][i] != null
                                                    select constraintParser[rowType][i].RowData).ToArray();

                            using (new GUI.EnabledBlock(refTransOrRotRowData[i] != null)) {
                                var labelContent = i == 0 ? InspectorGUI.MakeLabel(wrapper.Member) : null;
                                var fieldContent = GUI.MakeLabel(RowLabels[i], RowColors[i]);
                                if (wrapper.IsType <float>())
                                {
                                    EditorGUI.showMixedValue = !wrapper.AreValuesEqual(rowDataInstances);
                                    var value = InspectorGUI.CustomFloatField(labelContent,
                                                                              fieldContent,
                                                                              wrapper.Get <float>(refTransOrRotRowData[i]?.RowData));
                                    if (UnityEngine.GUI.changed)
                                    {
                                        foreach (var constraintParser in constraintsParser)
                                        {
                                            wrapper.ConditionalSet(constraintParser[rowType][i]?.RowData, value);
                                        }
                                    }
                                }
                                else if (wrapper.IsType <RangeReal>())
                                {
                                    EditorGUI.showMixedValue = rowDataInstances.Any(rowData => !Equals(wrapper.Get <RangeReal>(refTransOrRotRowData[i]?.RowData).Min,
                                                                                                       wrapper.Get <RangeReal>(rowData).Min)) ||
                                                               rowDataInstances.Any(rowData => !Equals(wrapper.Get <RangeReal>(refTransOrRotRowData[i]?.RowData).Max,
                                                                                                       wrapper.Get <RangeReal>(rowData).Max));
                                    var rangeChangeData = InspectorGUI.RangeRealField(labelContent,
                                                                                      wrapper.Get <RangeReal>(refTransOrRotRowData[i]?.RowData),
                                                                                      GUI.MakeLabel(RowLabels[i], RowColors[i]));
                                    if (rangeChangeData.MinChanged || rangeChangeData.MaxChanged)
                                    {
                                        foreach (var constraintParser in constraintsParser)
                                        {
                                            var range = wrapper.Get <RangeReal>(constraintParser[rowType][i].RowData);
                                            if (rangeChangeData.MinChanged)
                                            {
                                                range.Min = rangeChangeData.Min;
                                            }
                                            if (rangeChangeData.MaxChanged)
                                            {
                                                range.Max = rangeChangeData.Max;
                                            }

                                            // Validation of Min > Max has to go somewhere else because if e.g.,
                                            // Min = 50 and the user wants to type Max = 200 we're receiving
                                            // Max = 2 as the user types.

                                            wrapper.ConditionalSet(constraintParser[rowType][i].RowData, range);
                                        }
                                    }
                                }
                            }

                            UnityEngine.GUI.changed  = false;
                            EditorGUI.showMixedValue = false;
                        }
                    } // For type wrappers.
                }     // Indentation.
            }         // For Translational, Rotational.

            var ecControllers = refConstraint.GetElementaryConstraintControllers();

            if (ecControllers.Length > 0 &&
                InspectorGUI.Foldout(selected("controllers"),
                                     GUI.MakeLabel("Controllers", true)))
            {
                using (InspectorGUI.IndentScope.Single) {
                    foreach (var refController in ecControllers)
                    {
                        var controllerType    = refController.GetControllerType();
                        var controllerTypeTag = controllerType.ToString()[0].ToString();
                        var controllerName    = ConstraintUtils.FindName(refController);
                        if (controllerName.EndsWith(" Controller"))
                        {
                            controllerName = controllerName.Remove(controllerName.LastIndexOf(" Controller"));
                        }
                        var controllerLabel = GUI.MakeLabel((controllerType == Constraint.ControllerType.Rotational ?
                                                             GUI.Symbols.CircleArrowAcw.ToString() + " " :
                                                             GUI.Symbols.ArrowRight.ToString() + " ") + controllerName, true);
                        if (!InspectorGUI.Foldout(selected(controllerTypeTag + controllerName),
                                                  controllerLabel))
                        {
                            continue;
                        }

                        var controllers = (from constraint
                                           in constraints
                                           from controller
                                           in constraint.GetElementaryConstraintControllers()
                                           where controller.GetType() == refController.GetType() &&
                                           controller.GetControllerType() == refController.GetControllerType()
                                           select controller).ToArray();
                        using (InspectorGUI.IndentScope.Single) {
                            InspectorEditor.DrawMembersGUI(controllers);
                            InspectorEditor.DrawMembersGUI(controllers, controller => (controller as ElementaryConstraint).RowData[0]);
                        }
                    }
                }
            }
        }
Ejemplo n.º 6
0
        public override void OnPreTargetMembersGUI()
        {
            var skin           = InspectorEditor.Skin;
            var constraints    = GetTargets <Constraint>().ToArray();
            var refConstraint  = constraints[0];
            var differentTypes = false;

            for (int i = 1; i < constraints.Length; ++i)
            {
                differentTypes = differentTypes || refConstraint.Type != constraints[i].Type;
            }

            GUILayout.Label(GUI.MakeLabel((differentTypes ?
                                           "Constraints" :
                                           refConstraint.Type.ToString() + (IsMultiSelect ? "s" : string.Empty)),
                                          24,
                                          true),
                            GUI.Align(skin.label, TextAnchor.MiddleCenter));

            GUI.Separator();

            // Render AttachmentPair GUI.
            ConstraintAttachmentFrameTool.OnPreTargetMembersGUI();

            Undo.RecordObjects(constraints, "ConstraintTool");

            UnityEngine.GUI.changed = false;

            EditorGUI.showMixedValue = constraints.Any(constraint => refConstraint.CollisionsState != constraint.CollisionsState);
            var collisionsState = ConstraintCollisionsStateGUI(refConstraint.CollisionsState, skin);

            EditorGUI.showMixedValue = false;

            if (UnityEngine.GUI.changed)
            {
                foreach (var constraint in constraints)
                {
                    constraint.CollisionsState = collisionsState;
                }
                UnityEngine.GUI.changed = false;
            }

            EditorGUI.showMixedValue = constraints.Any(constraint => refConstraint.SolveType != constraint.SolveType);
            var solveType = ConstraintSolveTypeGUI(refConstraint.SolveType, skin);

            EditorGUI.showMixedValue = false;

            if (UnityEngine.GUI.changed)
            {
                foreach (var constraint in constraints)
                {
                    constraint.SolveType = solveType;
                }
                UnityEngine.GUI.changed = false;
            }

            GUI.Separator();

            EditorGUI.showMixedValue = constraints.Any(constraint => refConstraint.ConnectedFrameNativeSyncEnabled != constraint.ConnectedFrameNativeSyncEnabled);
            var frameNativeSync = ConstraintConnectedFrameSyncGUI(refConstraint.ConnectedFrameNativeSyncEnabled, skin);

            EditorGUI.showMixedValue = false;

            if (UnityEngine.GUI.changed)
            {
                foreach (var constraint in constraints)
                {
                    constraint.ConnectedFrameNativeSyncEnabled = frameNativeSync;
                }
                UnityEngine.GUI.changed = false;
            }

            if (differentTypes)
            {
                GUI.WarningLabel("Constraints are of different types.\nRow data editing not supported.", skin);
                return;
            }

            Func <string, EditorDataEntry> selected = (id) =>
            {
                return(EditorData.Instance.GetData(refConstraint, id, entry => entry.Bool = false));
            };

            var constraintsParser = (from constraint
                                     in constraints
                                     select ConstraintUtils.ConstraintRowParser.Create(constraint)).ToArray();
            var allElementaryConstraints = constraints.SelectMany(constraint => constraint.GetOrdinaryElementaryConstraints()).ToArray();

            Undo.RecordObjects(allElementaryConstraints, "ConstraintTool");

            var ecRowDataWrappers = InvokeWrapper.FindFieldsAndProperties <ElementaryConstraintRowData>();

            GUI.Separator();
            foreach (ConstraintUtils.ConstraintRowParser.RowType rowType in Enum.GetValues(typeof(ConstraintUtils.ConstraintRowParser.RowType)))
            {
                if (!GUI.Foldout(selected("ec_" + rowType.ToString()),
                                 GUI.MakeLabel(rowType.ToString() + " properties", true),
                                 skin))
                {
                    GUI.Separator();
                    continue;
                }

                using (new GUI.Indent(12)) {
                    var refTransOrRotRowData = constraintsParser[0][rowType];
                    foreach (var wrapper in ecRowDataWrappers)
                    {
                        if (!InspectorEditor.ShouldBeShownInInspector(wrapper.Member))
                        {
                            continue;
                        }
                        using (new GUILayout.HorizontalScope()) {
                            GUILayout.Label(InspectorGUI.MakeLabel(wrapper.Member), skin.label);
                            GUILayout.FlexibleSpace();
                            using (new GUILayout.VerticalScope()) {
                                for (int i = 0; i < 3; ++i)
                                {
                                    var rowDataInstances = (from constraintParser
                                                            in constraintsParser
                                                            where constraintParser[rowType][i] != null
                                                            select constraintParser[rowType][i].RowData).ToArray();
                                    // TODO: This could probably be replaced by using InspectorEditor.HandleType
                                    //       with a tweak. We use wrapper.Get<type>( foo.RowData ) while our
                                    //       drawers uses wrapper.Get<type>().
                                    // UPDATE: Probably not worth it because we have to override all labels
                                    //         written by our default drawers.
                                    // ****************************************************************************
                                    //var objects = ( from constraintParser
                                    //                in constraintsParser
                                    //                where constraintParser[ rowType ][ i ] != null
                                    //                select constraintParser[ rowType ][ i ].RowData ).ToArray();
                                    //using ( new GUILayout.HorizontalScope() )
                                    //using ( new GUI.EnabledBlock( refTransOrRotRowData[ i ] != null ) ) {
                                    //  RowLabel( i, skin );
                                    //  InspectorEditor.HandleType( wrapper, objects );
                                    //}
                                    // ****************************************************************************

                                    using (new GUILayout.HorizontalScope())
                                        using (new GUI.EnabledBlock(refTransOrRotRowData[i] != null)) {
                                            RowLabel(i, skin);

                                            // Handling type float, e.g., compliance and damping.
                                            if (wrapper.IsType <float>())
                                            {
                                                EditorGUI.showMixedValue = !wrapper.AreValuesEqual(rowDataInstances);
                                                var value = EditorGUILayout.FloatField(wrapper.Get <float>(refTransOrRotRowData[i]?.RowData));
                                                if (UnityEngine.GUI.changed)
                                                {
                                                    foreach (var constraintParser in constraintsParser)
                                                    {
                                                        wrapper.ConditionalSet(constraintParser[rowType][i].RowData, value);
                                                    }
                                                    UnityEngine.GUI.changed = false;
                                                }
                                                EditorGUI.showMixedValue = false;
                                            }
                                            // Handling type RangeReal, e.g., force range.
                                            // Note: During multi-selection we don't want to write, e.g., Min from
                                            //       reference row data when value for Max is changed.
                                            else if (wrapper.IsType <RangeReal>())
                                            {
                                                EditorGUI.showMixedValue = rowDataInstances.Any(rowData => !Equals(wrapper.Get <RangeReal>(refTransOrRotRowData[i]?.RowData).Min,
                                                                                                                   wrapper.Get <RangeReal>(rowData).Min));
                                                var forceRangeMin = EditorGUILayout.FloatField(wrapper.Get <RangeReal>(refTransOrRotRowData[i]?.RowData).Min,
                                                                                               GUILayout.MaxWidth(128));
                                                var forceRangeMinChanged = UnityEngine.GUI.changed;
                                                EditorGUI.showMixedValue = false;
                                                UnityEngine.GUI.changed  = false;
                                                EditorGUI.showMixedValue = rowDataInstances.Any(rowData => !Equals(wrapper.Get <RangeReal>(refTransOrRotRowData[i]?.RowData).Max,
                                                                                                                   wrapper.Get <RangeReal>(rowData).Max));
                                                var forceRangeMax = EditorGUILayout.FloatField(wrapper.Get <RangeReal>(refTransOrRotRowData[i]?.RowData).Max,
                                                                                               GUILayout.MaxWidth(128));
                                                if (forceRangeMinChanged || UnityEngine.GUI.changed)
                                                {
                                                    foreach (var constraintParser in constraintsParser)
                                                    {
                                                        var range = wrapper.Get <RangeReal>(constraintParser[rowType][i].RowData);
                                                        if (forceRangeMinChanged)
                                                        {
                                                            range.Min = forceRangeMin;
                                                        }
                                                        if (UnityEngine.GUI.changed)
                                                        {
                                                            range.Max = forceRangeMax;
                                                        }

                                                        // Validation of Min > Max has to go somewhere else because if e.g.,
                                                        // Min = 50 and the user wants to type Max = 200 we're receiving
                                                        // Max = 2 as the user types.

                                                        wrapper.ConditionalSet(constraintParser[rowType][i].RowData, range);
                                                    }
                                                    UnityEngine.GUI.changed  = false;
                                                    EditorGUI.showMixedValue = false;
                                                }
                                            } // IsType RangeReal.
                                        }// Horizontal and GUI Enabled blocks.
                                }             // For U, V, N.
                            }                 // Right align vertical scope.
                        }                     // Horizontal with flexible space for alignment.
                        GUI.Separator();
                    }                         // For type wrappers.
                }                             // Indentation.
                GUI.Separator();
            }                                 // For Translational, Rotational.

            if (GUI.Foldout(selected("controllers"),
                            GUI.MakeLabel("Controllers", true),
                            skin))
            {
                GUI.Separator();
                using (new GUI.Indent(12)) {
                    foreach (var refController in refConstraint.GetElementaryConstraintControllers())
                    {
                        var    controllerType    = refController.GetControllerType();
                        var    controllerTypeTag = controllerType.ToString()[0].ToString();
                        var    controllerName    = ConstraintUtils.FindName(refController);
                        string dimString         = "[" + GUI.AddColorTag(controllerTypeTag,
                                                                         controllerType == Constraint.ControllerType.Rotational ?
                                                                         Color.Lerp(UnityEngine.GUI.color, Color.red, 0.75f) :
                                                                         Color.Lerp(UnityEngine.GUI.color, Color.green, 0.75f)) + "] ";
                        if (!GUI.Foldout(selected(controllerTypeTag + controllerName),
                                         GUI.MakeLabel(dimString + controllerName, true),
                                         skin))
                        {
                            GUI.Separator();
                            continue;
                        }

                        var controllers = (from constraint
                                           in constraints
                                           from controller
                                           in constraint.GetElementaryConstraintControllers()
                                           where controller.GetType() == refController.GetType()
                                           select controller).ToArray();
                        using (new GUI.Indent(12)) {
                            InspectorEditor.DrawMembersGUI(controllers);
                            GUI.Separator();
                            InspectorEditor.DrawMembersGUI(controllers, controller => (controller as ElementaryConstraint).RowData[0]);
                        }

                        GUI.Separator();
                    }
                }
            }
        }
Ejemplo n.º 7
0
        private void MeshOptionsGUI()
        {
            InspectorGUI.Separator();

            using (new GUI.EnabledBlock(!EditorApplication.isPlayingOrWillChangePlaymode)) {
                if (InspectorGUI.Foldout(GetEditorData(Mesh), GUI.MakeLabel("Options")))
                {
                    using (InspectorGUI.IndentScope.Single) {
                        InspectorEditor.DrawMembersGUI(Targets, t => (t as AGXUnity.Collide.Mesh).Options);
                        var applyResetResult = InspectorGUI.PositiveNegativeButtons(UnityEngine.GUI.enabled,
                                                                                    "Apply",
                                                                                    "Apply the changes",
                                                                                    "Reset",
                                                                                    "Delete collision meshes and reset mesh options values to default.");
                        if (applyResetResult == InspectorGUI.PositiveNegativeResult.Positive)
                        {
                            var meshes = GetTargets <AGXUnity.Collide.Mesh>().ToArray();
                            var collisionMeshGenerator = new AGXUnity.Collide.CollisionMeshGenerator();
                            var generatorStartTime     = EditorApplication.timeSinceStartup;
                            collisionMeshGenerator.GenerateAsync(meshes);
                            var isCanceled = false;
                            while (!isCanceled && collisionMeshGenerator.IsRunning)
                            {
                                var progressBarTitle = $"Generating collision meshes: {(int)( EditorApplication.timeSinceStartup - generatorStartTime )} s";
                                var progressBarInfo  = string.Empty;
                                var progress         = collisionMeshGenerator.Progress;
                                isCanceled = EditorUtility.DisplayCancelableProgressBar(progressBarTitle, progressBarInfo, progress);
                                if (!isCanceled)
                                {
                                    System.Threading.Thread.Sleep(50);
                                }
                            }

                            EditorUtility.ClearProgressBar();

                            if (isCanceled)
                            {
                                CanceledAsyncCollisionMeshGeneretors.RegisterCanceled(collisionMeshGenerator);
                            }
                            else
                            {
                                var results = collisionMeshGenerator.CollectResults();
                                using (new Utils.UndoCollapseBlock("Apply collision mesh data")) {
                                    foreach (var result in results)
                                    {
                                        Undo.RecordObject(result.Mesh, "Collision Meshes");
                                        result.Mesh.Options = result.Options;
                                        result.Mesh.PrecomputedCollisionMeshes = result.CollisionMeshes;
                                    }
                                }

                                var hasPrefabAssetBeenChanged = results.Any(result =>
                                                                            PrefabUtility.GetCorrespondingObjectFromOriginalSource(result.Mesh.gameObject) == null &&
                                                                            PrefabUtility.GetPrefabInstanceHandle(result.Mesh.gameObject) == null);
                                // Trying to dirty gizmos rendering of all affected prefab instances.
                                // We don't have to dirty them all but it's hard to determine where
                                // the instance is located in the hierarchy.
                                if (hasPrefabAssetBeenChanged)
                                {
                                    var allMeshes = Object.FindObjectsOfType <AGXUnity.Collide.Mesh>();
                                    foreach (var m in allMeshes)
                                    {
                                        m.OnPrecomputedCollisionMeshDataDirty();
                                    }
                                }
                            }

                            collisionMeshGenerator = null;

                            GUIUtility.ExitGUI();
                        }
                        else if (applyResetResult == InspectorGUI.PositiveNegativeResult.Negative &&
                                 EditorUtility.DisplayDialog("Reset collision meshes to default",
                                                             "Destroy collision meshes and reset mesh options to default?",
                                                             "Yes", "Cancel"))
                        {
                            var meshes = GetTargets <AGXUnity.Collide.Mesh>().ToArray();
                            using (new Utils.UndoCollapseBlock("Reset collision mesh data")) {
                                for (int i = 0; i < meshes.Length; ++i)
                                {
                                    var mesh = meshes[i];
                                    Undo.RecordObject(mesh, "Resetting collision mesh data");
                                    mesh.DestroyCollisionMeshes();
                                    if (mesh.Options != null)
                                    {
                                        Undo.RecordObject(mesh, "Resetting mesh options to default");
                                        mesh.Options.ResetToDesfault();
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 8
0
        public override void OnPreTargetMembersGUI()
        {
            var skin = InspectorEditor.Skin;

            bool toggleFindTransformGivenPoint = false;
            bool toggleFindTransformGivenEdge  = false;
            bool toggleShapeCreate             = false;
            bool toggleConstraintCreate        = false;
            bool toggleDisableCollisions       = false;
            bool toggleRigidBodyVisualCreate   = false;

            if (!IsMultiSelect && ToolsActive)
            {
                using (new GUILayout.HorizontalScope()) {
                    GUI.ToolsLabel(skin);
                    using (GUI.ToolButtonData.ColorBlock) {
                        toggleFindTransformGivenPoint = GUI.ToolButton(GUI.Symbols.SelectPointTool,
                                                                       FindTransformGivenPointTool,
                                                                       "Find rigid body transform given point on object.",
                                                                       skin);
                        toggleFindTransformGivenEdge = GUI.ToolButton(GUI.Symbols.SelectEdgeTool,
                                                                      FindTransformGivenEdgeTool,
                                                                      "Find rigid body transform given edge on object.",
                                                                      skin);
                        toggleShapeCreate = GUI.ToolButton(GUI.Symbols.ShapeCreateTool,
                                                           ShapeCreateTool,
                                                           "Create shape from visual objects",
                                                           skin);
                        toggleConstraintCreate = GUI.ToolButton(GUI.Symbols.ConstraintCreateTool,
                                                                ConstraintCreateTool,
                                                                "Create constraint to this rigid body",
                                                                skin);
                        toggleDisableCollisions = GUI.ToolButton(GUI.Symbols.DisableCollisionsTool,
                                                                 DisableCollisionsTool,
                                                                 "Disable collisions against other objects",
                                                                 skin);
                        using (new EditorGUI.DisabledGroupScope(!Tools.RigidBodyVisualCreateTool.ValidForNewShapeVisuals(RigidBody)))
                            toggleRigidBodyVisualCreate = GUI.ToolButton(GUI.Symbols.ShapeVisualCreateTool,
                                                                         RigidBodyVisualCreateTool,
                                                                         "Create visual representation of each physical shape in this body",
                                                                         skin,
                                                                         14);
                    }
                }
            }

            if (ShapeCreateTool)
            {
                GUI.Separator();

                GetChild <ShapeCreateTool>().OnInspectorGUI();
            }
            if (ConstraintCreateTool)
            {
                GUI.Separator();

                GetChild <ConstraintCreateTool>().OnInspectorGUI();
            }
            if (DisableCollisionsTool)
            {
                GUI.Separator();

                GetChild <DisableCollisionsTool>().OnInspectorGUI();
            }
            if (RigidBodyVisualCreateTool)
            {
                GUI.Separator();

                GetChild <RigidBodyVisualCreateTool>().OnInspectorGUI();
            }

            GUI.Separator();

            GUILayout.Label(GUI.MakeLabel("Mass properties", true), skin.label);
            using (new GUI.Indent(12))
                InspectorEditor.DrawMembersGUI(GetTargets <RigidBody>().Select(rb => rb.MassProperties).ToArray());

            GUI.Separator();

            if (toggleFindTransformGivenPoint)
            {
                FindTransformGivenPointTool = !FindTransformGivenPointTool;
            }
            if (toggleFindTransformGivenEdge)
            {
                FindTransformGivenEdgeTool = !FindTransformGivenEdgeTool;
            }
            if (toggleShapeCreate)
            {
                ShapeCreateTool = !ShapeCreateTool;
            }
            if (toggleConstraintCreate)
            {
                ConstraintCreateTool = !ConstraintCreateTool;
            }
            if (toggleDisableCollisions)
            {
                DisableCollisionsTool = !DisableCollisionsTool;
            }
            if (toggleRigidBodyVisualCreate)
            {
                RigidBodyVisualCreateTool = !RigidBodyVisualCreateTool;
            }
        }