Exemple #1
0
        private Tuple <PropertyWrapper, CableProperties.Direction, object> OnPropertyGUI(CableProperties.Direction dir,
                                                                                         CableProperties properties,
                                                                                         GUISkin skin)
        {
            Tuple <PropertyWrapper, CableProperties.Direction, object> changed = null;
            var data = EditorData.Instance.GetData(properties, "CableProperty" + dir.ToString());

            if (GUI.Foldout(data, GUI.MakeLabel(dir.ToString()), skin))
            {
                using (new GUI.Indent(12)) {
                    GUI.Separator();

                    var wrappers = PropertyWrapper.FindProperties <CableProperty>(System.Reflection.BindingFlags.Instance |
                                                                                  System.Reflection.BindingFlags.Public);
                    foreach (var wrapper in wrappers)
                    {
                        if (wrapper.GetContainingType() == typeof(float) && InspectorEditor.ShouldBeShownInInspector(wrapper.Member))
                        {
                            var value = EditorGUILayout.FloatField(InspectorGUI.MakeLabel(wrapper.Member),
                                                                   wrapper.Get <float>(properties[dir]));
                            if (UnityEngine.GUI.changed)
                            {
                                changed = new Tuple <PropertyWrapper, CableProperties.Direction, object>(wrapper, dir, value);
                                UnityEngine.GUI.changed = false;
                            }
                        }
                    }
                }
            }
            return(changed);
        }
Exemple #2
0
        public void ConstraintRowsGUI(GUISkin skin)
        {
            try {
                ConstraintUtils.ConstraintRowParser constraintRowParser = ConstraintUtils.ConstraintRowParser.Create(Constraint);

                InvokeWrapper[] memberWrappers = InvokeWrapper.FindFieldsAndProperties(null, typeof(ElementaryConstraintRowData));
                if (constraintRowParser.HasTranslationalRows)
                {
                    if (GUI.Foldout(Selected(SelectedFoldout.OrdinaryElementaryTranslational), GUI.MakeLabel("Translational properties </b>(along constraint axis)<b>", true), skin, OnFoldoutStateChange))
                    {
                        using (new GUI.Indent(12))
                            HandleConstraintRowsGUI(constraintRowParser.TranslationalRows, memberWrappers, skin);
                    }
                }

                if (constraintRowParser.HasRotationalRows)
                {
                    GUI.Separator();

                    if (GUI.Foldout(Selected(SelectedFoldout.OrdinaryElementaryRotational), GUI.MakeLabel("Rotational properties </b>(about constraint axis)<b>", true), skin, OnFoldoutStateChange))
                    {
                        using (new GUI.Indent(12))
                            HandleConstraintRowsGUI(constraintRowParser.RotationalRows, memberWrappers, skin);
                    }
                }

                ElementaryConstraintController[] controllers = Constraint.GetElementaryConstraintControllers();
                if (controllers.Length > 0)
                {
                    if (!constraintRowParser.Empty)
                    {
                        GUI.Separator();
                    }

                    if (GUI.Foldout(Selected(SelectedFoldout.Controllers), GUI.MakeLabel("Controllers", true), skin, OnFoldoutStateChange))
                    {
                        using (new GUI.Indent(12)) {
                            GUI.Separator();
                            foreach (var controller in controllers)
                            {
                                HandleConstraintControllerGUI(controller, skin);

                                GUI.Separator();
                            }
                        }
                    }
                }
            }
            catch (AGXUnity.Exception e) {
                GUILayout.Label(GUI.MakeLabel("Unable to parse constraint rows", true), skin.label);
                GUILayout.Label(GUI.MakeLabel("  - " + e.Message, Color.red), skin.label);
            }
        }
Exemple #3
0
        private void OnPropertyGUI(CableProperties.Direction dir, CableProperties properties, GUISkin skin)
        {
            var data = EditorData.Instance.GetData(properties, "CableProperty" + dir.ToString());

            if (GUI.Foldout(data, GUI.MakeLabel(dir.ToString()), skin))
            {
                using (new GUI.Indent(12)) {
                    GUI.Separator();

                    properties[dir].YoungsModulus = Mathf.Clamp(EditorGUILayout.FloatField(GUI.MakeLabel("Young's modulus"), properties[dir].YoungsModulus), 1.0E-6f, float.PositiveInfinity);
                    properties[dir].YieldPoint    = Mathf.Clamp(EditorGUILayout.FloatField(GUI.MakeLabel("Yield point"), properties[dir].YieldPoint), 0.0f, float.PositiveInfinity);
                    properties[dir].Damping       = Mathf.Clamp(EditorGUILayout.FloatField(GUI.MakeLabel("Spook damping"), properties[dir].Damping), 0.0f, float.PositiveInfinity);
                }
            }
        }
        private void OnShapeListGUI(GUISkin skin)
        {
            if (!GUI.Foldout(EditorData.Instance.GetData(RigidBody, "Shapes"), GUI.MakeLabel("Shapes", true), skin))
            {
                return;
            }

            Shape[] shapes = RigidBody.GetComponentsInChildren <Shape>();
            if (shapes.Length == 0)
            {
                using (new GUI.Indent(12))
                    GUILayout.Label(GUI.MakeLabel("Empty", true), skin.label);
                return;
            }

            using (new GUI.Indent(12)) {
                foreach (var shape in shapes)
                {
                    GUI.Separator();
                    if (!GUI.Foldout(EditorData.Instance.GetData(RigidBody,
                                                                 shape.GetInstanceID().ToString()),
                                     GUI.MakeLabel("[" + GUI.AddColorTag(shape.GetType().Name, Color.Lerp(Color.green, Color.black, 0.4f)) + "] " + shape.name),
                                     skin))
                    {
                        continue;
                    }

                    GUI.Separator();
                    using (new GUI.Indent(12)) {
                        Undo.RecordObjects(shape.GetUndoCollection(), "Shape");

                        shape.enabled = GUI.Toggle(GUI.MakeLabel("Enable"), shape.enabled, skin.button, skin.label);
                        if (shape is AGXUnity.Collide.Mesh)
                        {
                            GUI.Separator();

                            var newMeshSource = GUI.ShapeMeshSourceGUI((shape as AGXUnity.Collide.Mesh).SourceObjects.FirstOrDefault(), skin);
                            if (newMeshSource != null)
                            {
                                (shape as AGXUnity.Collide.Mesh).SetSourceObject(newMeshSource);
                            }
                        }
                        GUI.Separator();
                        BaseEditor <Shape> .Update(shape, shape, skin);
                    }
                }
            }
        }
Exemple #5
0
        private void HandleConstraintControllerGUI(ElementaryConstraintController controller, GUISkin skin)
        {
            var    controllerType    = controller.GetControllerType();
            var    controllerTypeTag = controllerType.ToString().Substring(0, 1);
            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(SelectedFoldout.Controller,
                                     controllerTypeTag + ConstraintUtils.FindName(controller)),
                            GUI.MakeLabel(dimString + ConstraintUtils.FindName(controller), true),
                            skin,
                            OnFoldoutStateChange))
            {
                using (new GUI.Indent(12)) {
                    controller.Enable = GUI.Toggle(GUI.MakeLabel("Enable", controller.Enable), controller.Enable, skin.button, skin.label);
                    BaseEditor <ElementaryConstraint> .Update(controller, controller, skin);
                }
            }
        }
Exemple #6
0
        public static void OnRigidBodyListGUI(RigidBody[] rigidBodies, CustomTargetTool context)
        {
            var skin = InspectorEditor.Skin;

            if (!GUI.Foldout(EditorData.Instance.GetData(context.Targets[0], "Rigid Bodies"),
                             GUI.MakeLabel("Rigid Bodies", true), skin))
            {
                context.RemoveEditors(rigidBodies);
                return;
            }

            if (rigidBodies.Length == 0)
            {
                using (new GUI.Indent(12))
                    GUILayout.Label(GUI.MakeLabel("Empty", true), skin.label);
                return;
            }

            using (new GUI.Indent(12)) {
                foreach (var rb in rigidBodies)
                {
                    GUI.Separator();

                    if (!GUI.Foldout(EditorData.Instance.GetData(context.Targets[0], rb.GetInstanceID().ToString()),
                                     GUI.MakeLabel("[" + GUI.AddColorTag("RigidBody", Color.Lerp(Color.blue, Color.white, 0.35f)) + "] " + rb.name),
                                     skin))
                    {
                        context.RemoveEditor(rb);
                        continue;
                    }

                    GUI.Separator();

                    using (new GUI.Indent(12)) {
                        var editor = context.GetOrCreateEditor(rb);
                        editor.OnInspectorGUI();
                    }
                }
            }
        }
Exemple #7
0
        public static void OnShapeListGUI(Shape[] shapes, CustomTargetTool context)
        {
            var skin = InspectorEditor.Skin;

            if (!GUI.Foldout(EditorData.Instance.GetData(context.Targets[0], "Shapes"), GUI.MakeLabel("Shapes", true), skin))
            {
                context.RemoveEditors(shapes);
                return;
            }

            if (shapes.Length == 0)
            {
                using (new GUI.Indent(12))
                    GUILayout.Label(GUI.MakeLabel("Empty", true), skin.label);
                return;
            }

            using (new GUI.Indent(12)) {
                foreach (var shape in shapes)
                {
                    GUI.Separator();
                    if (!GUI.Foldout(EditorData.Instance.GetData(context.Targets[0],
                                                                 shape.GetInstanceID().ToString()),
                                     GUI.MakeLabel("[" + GUI.AddColorTag(shape.GetType().Name, Color.Lerp(Color.green, Color.black, 0.4f)) + "] " + shape.name),
                                     skin))
                    {
                        context.RemoveEditor(shape);
                        continue;
                    }

                    GUI.Separator();
                    using (new GUI.Indent(12)) {
                        var editor = context.GetOrCreateEditor(shape);
                        using (new GUILayout.VerticalScope())
                            editor.OnInspectorGUI();
                    }
                }
            }
        }
        public static void OnRigidBodyListGUI(RigidBody[] rigidBodies, UnityEngine.Object context, GUISkin skin)
        {
            if (!GUI.Foldout(EditorData.Instance.GetData(context, "Rigid Bodies"), GUI.MakeLabel("Rigid Bodies", true), skin))
            {
                return;
            }

            if (rigidBodies.Length == 0)
            {
                using (new GUI.Indent(12))
                    GUILayout.Label(GUI.MakeLabel("Empty", true), skin.label);
                return;
            }

            using (new GUI.Indent(12)) {
                foreach (var rb in rigidBodies)
                {
                    GUI.Separator();

                    if (!GUI.Foldout(EditorData.Instance.GetData(context, rb.GetInstanceID().ToString()),
                                     GUI.MakeLabel("[" + GUI.AddColorTag("RigidBody", Color.Lerp(Color.blue, Color.white, 0.35f)) + "] " + rb.name),
                                     skin))
                    {
                        continue;
                    }

                    GUI.Separator();
                    var rbTool = new RigidBodyTool(rb)
                    {
                        ToolsActive = false
                    };
                    using (new GUI.Indent(12)) {
                        rbTool.OnPreTargetMembersGUI(skin);
                        BaseEditor <RigidBody> .Update(rb, rb, skin);
                    }
                }
            }
        }
Exemple #9
0
        public static void OnConstraintListGUI(Constraint[] constraints, CustomTargetTool context)
        {
            var skin = InspectorEditor.Skin;

            if (!GUI.Foldout(EditorData.Instance.GetData(context.Targets[0], "Constraints"),
                             GUI.MakeLabel("Constraints", true), skin))
            {
                context.RemoveEditors(constraints);
                return;
            }

            if (constraints.Length == 0)
            {
                using (new GUI.Indent(12))
                    GUILayout.Label(GUI.MakeLabel("Empty", true), skin.label);
                return;
            }

            using (new GUI.Indent(12)) {
                foreach (var constraint in constraints)
                {
                    GUI.Separator();
                    if (!GUI.Foldout(EditorData.Instance.GetData(context.Targets[0], constraint.GetInstanceID().ToString()),
                                     GUI.MakeLabel("[" + GUI.AddColorTag(constraint.Type.ToString(), Color.Lerp(Color.magenta, Color.black, 0.4f)) + "] " + constraint.name),
                                     skin))
                    {
                        context.RemoveEditor(constraint);
                        continue;
                    }

                    GUI.Separator();
                    using (new GUI.Indent(12)) {
                        var editor = context.GetOrCreateEditor(constraint);
                        editor.OnInspectorGUI();
                    }
                }
            }
        }
Exemple #10
0
        public static void OnConstraintListGUI(Constraint[] constraints, UnityEngine.Object context, GUISkin skin)
        {
            if (!GUI.Foldout(EditorData.Instance.GetData(context, "Constraints"), GUI.MakeLabel("Constraints", true), skin))
            {
                return;
            }

            if (constraints.Length == 0)
            {
                using (new GUI.Indent(12))
                    GUILayout.Label(GUI.MakeLabel("Empty", true), skin.label);
                return;
            }

            using (new GUI.Indent(12)) {
                foreach (var constraint in constraints)
                {
                    GUI.Separator();
                    if (!GUI.Foldout(EditorData.Instance.GetData(context, constraint.GetInstanceID().ToString()),
                                     GUI.MakeLabel("[" + GUI.AddColorTag(constraint.Type.ToString(), Color.Lerp(Color.magenta, Color.black, 0.4f)) + "] " + constraint.name),
                                     skin))
                    {
                        continue;
                    }

                    GUI.Separator();
                    var constraintTool = new ConstraintTool(constraint)
                    {
                        OnFoldoutStateChange = state => EditorUtility.SetDirty(context)
                    };
                    using (new GUI.Indent(12)) {
                        constraintTool.OnPreTargetMembersGUI(skin);
                    }
                }
            }
        }
        private void OnConstraintListGUI(GUISkin skin)
        {
            if (m_constraints.Count == 0)
            {
                return;
            }

            GUI.Separator();

            if (!GUI.Foldout(EditorData.Instance.GetData(RigidBody, "Constraints"), GUI.MakeLabel("Constraints", true), skin))
            {
                return;
            }

            using (new GUI.Indent(12)) {
                foreach (var constraint in m_constraints)
                {
                    GUI.Separator();
                    if (!GUI.Foldout(EditorData.Instance.GetData(RigidBody, constraint.GetInstanceID().ToString()),
                                     GUI.MakeLabel("[" + GUI.AddColorTag(constraint.Type.ToString(), Color.Lerp(Color.magenta, Color.black, 0.4f)) + "] " + constraint.name),
                                     skin))
                    {
                        continue;
                    }

                    GUI.Separator();
                    var constraintTool = new ConstraintTool(constraint)
                    {
                        OnFoldoutStateChange = state => EditorUtility.SetDirty(RigidBody)
                    };
                    using (new GUI.Indent(12)) {
                        constraintTool.OnPreTargetMembersGUI(skin);
                    }
                }
            }
        }
Exemple #12
0
        public static object GenericListDrawer(object obj, InvokeWrapper wrapper, GUISkin skin)
        {
            System.Collections.IList list = wrapper.Get <System.Collections.IList>(obj);
            var target = obj as Object;

            if (GUI.Foldout(EditorData.Instance.GetData(target, wrapper.Member.Name),
                            MakeLabel(wrapper.Member),
                            skin))
            {
                object insertElementBefore = null;
                object insertElementAfter  = null;
                object eraseElement        = null;
                var    buttonLayout        = new GUILayoutOption[] { GUILayout.Width(26), GUILayout.Height(18) };
                using (new GUI.Indent(12)) {
                    foreach (var listObject in list)
                    {
                        GUI.Separator();
                        using (new GUI.Indent(12)) {
                            GUILayout.BeginHorizontal();
                            {
                                GUILayout.BeginVertical();
                                {
                                    // Using target to render listObject since it normally (CollisionGroupEntry) isn't an Object.
                                    InspectorEditor.DrawMembersGUI(new Object[] { target }, ignored => listObject);
                                }
                                GUILayout.EndVertical();

                                using (GUI.NodeListButtonColor) {
                                    if (GUILayout.Button(GUI.MakeLabel(GUI.Symbols.ListInsertElementBefore.ToString(),
                                                                       false,
                                                                       "Insert new element before this"),
                                                         skin.button,
                                                         buttonLayout))
                                    {
                                        insertElementBefore = listObject;
                                    }
                                    if (GUILayout.Button(GUI.MakeLabel(GUI.Symbols.ListInsertElementAfter.ToString(),
                                                                       false,
                                                                       "Insert new element after this"),
                                                         skin.button,
                                                         buttonLayout))
                                    {
                                        insertElementAfter = listObject;
                                    }
                                    if (GUILayout.Button(GUI.MakeLabel(GUI.Symbols.ListEraseElement.ToString(),
                                                                       false,
                                                                       "Erase this element"),
                                                         skin.button,
                                                         buttonLayout))
                                    {
                                        eraseElement = listObject;
                                    }
                                }
                            }
                            GUILayout.EndHorizontal();
                        }
                    }

                    if (list.Count == 0)
                    {
                        GUILayout.Label(GUI.MakeLabel("Empty", true), skin.label);
                    }
                    else
                    {
                        GUI.Separator();
                    }
                }

                bool addElementToList = false;
                GUILayout.BeginHorizontal();
                {
                    GUILayout.FlexibleSpace();
                    using (GUI.NodeListButtonColor)
                        addElementToList = GUILayout.Button(GUI.MakeLabel(GUI.Symbols.ListInsertElementAfter.ToString(),
                                                                          false,
                                                                          "Add new element to list"),
                                                            skin.button,
                                                            buttonLayout);
                }
                GUILayout.EndHorizontal();

                object newObject = null;
                if (addElementToList || insertElementBefore != null || insertElementAfter != null)
                {
                    newObject = Activator.CreateInstance(list.GetType().GetGenericArguments()[0], new object[] { });
                }

                if (eraseElement != null)
                {
                    list.Remove(eraseElement);
                }
                else if (newObject != null)
                {
                    if (addElementToList || (list.Count > 0 && insertElementAfter != null && insertElementAfter == list[list.Count - 1]))
                    {
                        list.Add(newObject);
                    }
                    else if (insertElementAfter != null)
                    {
                        list.Insert(list.IndexOf(insertElementAfter) + 1, newObject);
                    }
                    else if (insertElementBefore != null)
                    {
                        list.Insert(list.IndexOf(insertElementBefore), newObject);
                    }
                }

                if (eraseElement != null || newObject != null)
                {
                    EditorUtility.SetDirty(target);
                }
            }

            // A bit of a hack until I figure out how to handle multi-selection
            // of lists, if that should be possible at all. We're handling the
            // list from inside this drawer and by returning null the return
            // value isn't propagated to any targets.
            return(null);
        }
Exemple #13
0
        private void RouteGUI()
        {
            var      skin             = InspectorEditor.Skin;
            GUIStyle invalidNodeStyle = new GUIStyle(skin.label);

            invalidNodeStyle.normal.background = GUI.CreateColoredTexture(4, 4, Color.Lerp(UnityEngine.GUI.color, Color.red, 0.75f));

            bool  addNewPressed       = false;
            bool  insertBeforePressed = false;
            bool  insertAfterPressed  = false;
            bool  erasePressed        = false;
            NodeT listOpNode          = null;

            Undo.RecordObject(Route, "Route changed");

            GUI.Separator();

            if (GUI.Foldout(EditorData.Instance.GetData(Parent, "Route", (entry) => { entry.Bool = true; }), GUI.MakeLabel("Route", true), skin))
            {
                GUI.Separator();

                Route <NodeT> .ValidatedRoute validatedRoute = Route.GetValidated();
                foreach (var validatedNode in validatedRoute)
                {
                    var node = validatedNode.Node;
                    using (new GUI.Indent(12)) {
                        if (validatedNode.Valid)
                        {
                            GUILayout.BeginVertical();
                        }
                        else
                        {
                            GUILayout.BeginVertical(invalidNodeStyle);
                        }

                        if (GUI.Foldout(GetFoldoutData(node),
                                        GUI.MakeLabel(GetNodeTypeString(node) + " | " + SelectGameObjectDropdownMenuTool.GetGUIContent(node.Parent).text,
                                                      !validatedNode.Valid,
                                                      validatedNode.ErrorString),
                                        skin,
                                        newState =>
                        {
                            Selected = newState ? node : null;
                            EditorUtility.SetDirty(Parent);
                        }))
                        {
                            OnPreFrameGUI(node, skin);

                            GUI.HandleFrame(node, 12);

                            OnPostFrameGUI(node, skin);

                            GUILayout.BeginHorizontal();
                            {
                                GUILayout.FlexibleSpace();

                                using (new GUI.ColorBlock(Color.Lerp(UnityEngine.GUI.color, Color.green, 0.1f))) {
                                    insertBeforePressed = GUILayout.Button(GUI.MakeLabel(GUI.Symbols.ListInsertElementBefore.ToString(),
                                                                                         16,
                                                                                         false,
                                                                                         "Insert a new node before this node"),
                                                                           skin.button,
                                                                           GUILayout.Width(20),
                                                                           GUILayout.Height(16)) || insertBeforePressed;
                                    insertAfterPressed = GUILayout.Button(GUI.MakeLabel(GUI.Symbols.ListInsertElementAfter.ToString(),
                                                                                        16,
                                                                                        false,
                                                                                        "Insert a new node after this node"),
                                                                          skin.button,
                                                                          GUILayout.Width(20),
                                                                          GUILayout.Height(16)) || insertAfterPressed;
                                }
                                using (new GUI.ColorBlock(Color.Lerp(UnityEngine.GUI.color, Color.red, 0.1f)))
                                    erasePressed = GUILayout.Button(GUI.MakeLabel(GUI.Symbols.ListEraseElement.ToString(),
                                                                                  16,
                                                                                  false,
                                                                                  "Erase this node"),
                                                                    skin.button,
                                                                    GUILayout.Width(20),
                                                                    GUILayout.Height(16)) || erasePressed;

                                if (listOpNode == null && (insertBeforePressed || insertAfterPressed || erasePressed))
                                {
                                    listOpNode = node;
                                }
                            }
                            GUILayout.EndHorizontal();
                        }

                        GUILayout.EndVertical();

                        GUI.Separator();
                    }

                    if (GUILayoutUtility.GetLastRect().Contains(Event.current.mousePosition) &&
                        Event.current.type == EventType.MouseDown &&
                        Event.current.button == 0)
                    {
                        Selected = node;
                    }
                }

                GUILayout.BeginHorizontal();
                {
                    GUILayout.FlexibleSpace();

                    using (new GUI.ColorBlock(Color.Lerp(UnityEngine.GUI.color, Color.green, 0.1f)))
                        addNewPressed = GUILayout.Button(GUI.MakeLabel(GUI.Symbols.ListInsertElementAfter.ToString(),
                                                                       16,
                                                                       false,
                                                                       "Add new node to route"),
                                                         skin.button,
                                                         GUILayout.Width(20),
                                                         GUILayout.Height(16));
                    if (listOpNode == null && addNewPressed)
                    {
                        listOpNode = Route.LastOrDefault();
                    }
                }
                GUILayout.EndHorizontal();
            }

            GUI.Separator();

            if (addNewPressed || insertBeforePressed || insertAfterPressed)
            {
                NodeT newRouteNode = null;
                // Clicking "Add" will not copy data from last node.
                newRouteNode = listOpNode != null?
                               addNewPressed?
                               RouteNode.Create <NodeT>(null, listOpNode.Position, listOpNode.Rotation) :
                                   RouteNode.Create <NodeT>(listOpNode.Parent, listOpNode.LocalPosition, listOpNode.LocalRotation) :
                                       RouteNode.Create <NodeT>();

                OnNodeCreate(newRouteNode, listOpNode, addNewPressed);

                if (addNewPressed)
                {
                    Route.Add(newRouteNode);
                }
                if (insertBeforePressed)
                {
                    Route.InsertBefore(newRouteNode, listOpNode);
                }
                if (insertAfterPressed)
                {
                    Route.InsertAfter(newRouteNode, listOpNode);
                }

                if (newRouteNode != null)
                {
                    CreateRouteNodeTool(newRouteNode);
                    Selected = newRouteNode;
                }
            }
            else if (listOpNode != null && erasePressed)
            {
                Selected = null;
                Route.Remove(listOpNode);
            }
        }
        public override void OnPreTargetMembersGUI()
        {
            var  skin          = InspectorEditor.Skin;
            var  disabledPairs = Manager.DisabledPairs;
            bool clearPressed  = false;
            bool addPressed    = false;
            CollisionGroupEntryPair erasePair = null;

            GUILayout.Label(GUI.MakeLabel("Collision Groups Manager", 18, true), new GUIStyle(skin.label)
            {
                alignment = TextAnchor.MiddleCenter
            });

            GUI.Separator3D();

            GUILayout.Label(GUI.MakeLabel("Add pair", true), new GUIStyle(skin.label)
            {
                alignment = TextAnchor.MiddleCenter
            });

            GUILayout.BeginVertical(skin.textArea);
            {
                HandleCollisionGroupEntryPair(m_groupEntryPairToAdd, skin);

                GUILayout.BeginHorizontal();
                {
                    GUILayout.FlexibleSpace();

                    UnityEngine.GUI.enabled = m_groupEntryPairToAdd.First.Tag.Length > 0 || m_groupEntryPairToAdd.Second.Tag.Length > 0;
                    GUILayout.BeginVertical();
                    {
                        GUILayout.Space(8);
                        using (new GUI.ColorBlock(Color.Lerp(UnityEngine.GUI.color, Color.red, 0.1f)))
                            clearPressed = GUILayout.Button(GUI.MakeLabel("Clear"), skin.button, GUILayout.Width(64), GUILayout.Height(16));
                    }
                    GUILayout.EndVertical();

                    UnityEngine.GUI.enabled = m_groupEntryPairToAdd.First.Tag.Length > 0 && m_groupEntryPairToAdd.Second.Tag.Length > 0;
                    using (new GUI.ColorBlock(Color.Lerp(UnityEngine.GUI.color, Color.green, 0.1f)))
                        addPressed = GUILayout.Button(GUI.MakeLabel("Add", false, "Add pair to disabled pairs."), skin.button, GUILayout.Width(64), GUILayout.Height(22));

                    UnityEngine.GUI.enabled = true;
                }
                GUILayout.EndHorizontal();
            }
            GUILayout.EndVertical();

            GUI.Separator3D();

            if (GUI.Foldout(FoldoutDataEntry, GUI.MakeLabel("Disabled Pairs [" + disabledPairs.Length + "]"), skin))
            {
                using (new GUI.Indent(12)) {
                    foreach (var disabledPair in disabledPairs)
                    {
                        GUILayout.BeginHorizontal();
                        {
                            GUI.Separator(1, 10);
                            using (new GUI.ColorBlock(Color.Lerp(UnityEngine.GUI.color, Color.red, 0.1f)))
                                if (GUILayout.Button(GUI.MakeLabel(GUI.Symbols.ListEraseElement.ToString()), skin.button, GUILayout.Width(18), GUILayout.Height(14)))
                                {
                                    erasePair = disabledPair;
                                }
                        }
                        GUILayout.EndHorizontal();

                        HandleCollisionGroupEntryPair(disabledPair, skin);
                    }
                }
            }

            GUI.Separator3D();

            if (clearPressed)
            {
                m_groupEntryPairToAdd.First.Tag = m_groupEntryPairToAdd.Second.Tag = string.Empty;
            }
            if (addPressed)
            {
                Manager.SetEnablePair(m_groupEntryPairToAdd.First.Tag, m_groupEntryPairToAdd.Second.Tag, false);
                m_groupEntryPairToAdd.First.Tag = m_groupEntryPairToAdd.Second.Tag = string.Empty;
                FoldoutDataEntry.Bool           = true;
            }
            if (erasePair != null)
            {
                if (EditorUtility.DisplayDialog("Remove pair", "Erase disabled pair: " + erasePair.First.Tag + " and " + erasePair.Second.Tag + "?", "Yes", "No"))
                {
                    Manager.SetEnablePair(erasePair.First.Tag, erasePair.Second.Tag, true);
                }
            }
        }
Exemple #15
0
        public override void OnPostTargetMembersGUI(GUISkin skin)
        {
            var shapeVisual = ShapeVisual.Find(Shape);

            if (shapeVisual == null)
            {
                return;
            }

            GUI.Separator();
            if (!GUI.FoldoutEx(EditorData.Instance.GetData(Shape,
                                                           "Visual",
                                                           entry => entry.Bool = true),
                               skin.button,
                               GUI.MakeLabel("Shape Visual", 12, true),
                               new GUIStyle(skin.label)
            {
                alignment = TextAnchor.UpperCenter
            }))
            {
                return;
            }

            GUI.Separator();

            GUILayout.Space(6);

            Undo.RecordObjects(shapeVisual.GetComponentsInChildren <MeshRenderer>(), "Shape visual material");

            var materials = shapeVisual.GetMaterials();

            if (materials.Length > 1)
            {
                var distinctMaterials = materials.Distinct().ToArray();
                using (GUI.AlignBlock.Center) {
                    GUILayout.Label(GUI.MakeLabel("Displays material if all materials are the same <b>(otherwise None)</b> and/or assign new material to all objects in this shape."),
                                    new GUIStyle(skin.textArea)
                    {
                        alignment = TextAnchor.MiddleCenter
                    }, GUILayout.Width(Screen.width - 60));
                }
                GUI.MaterialEditor(GUI.MakeLabel("Common material:", true),
                                   128,
                                   distinctMaterials.Length == 1 ? distinctMaterials.First() : null,
                                   skin,
                                   newMaterial => shapeVisual.SetMaterial(newMaterial));

                GUILayout.Space(6);

                GUI.Separator();

                using (GUI.AlignBlock.Center)
                    GUILayout.Label(GUI.MakeLabel("Material list", true), skin.label);

                GUI.Separator();
            }

            for (int i = 0; i < materials.Length; ++i)
            {
                var material           = materials[i];
                var showMaterialEditor = materials.Length == 1 ||
                                         GUI.Foldout(EditorData.Instance.GetData(Shape,
                                                                                 "VisualMaterial" + i),
                                                     GUI.MakeLabel(material.name), skin);
                if (showMaterialEditor)
                {
                    GUI.MaterialEditor(GUI.MakeLabel("Material:", true),
                                       64,
                                       material,
                                       skin,
                                       newMaterial => shapeVisual.ReplaceMaterial(i, newMaterial));
                }
                GUI.Separator();
            }
        }
Exemple #16
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);
            }
        }
Exemple #17
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();
                    }
                }
            }
        }