示例#1
0
        private NodeFoldoutState NodeFoldout(Route <NodeT> .ValidatedNode validatedNode)
        {
            if (s_invalidNodeStyle == null)
            {
                s_invalidNodeStyle = new GUIStyle(InspectorEditor.Skin.Label);
                s_invalidNodeStyle.normal.background = GUI.CreateColoredTexture(1,
                                                                                1,
                                                                                Color.Lerp(UnityEngine.GUI.color,
                                                                                           Color.red,
                                                                                           0.75f));
            }

            var state = new NodeFoldoutState();
            var node  = validatedNode.Node;

            var verticalScope = !validatedNode.Valid ?
                                new EditorGUILayout.VerticalScope(s_invalidNodeStyle) :
                                null;
            var horizontalScope = node == Selected ?
                                  new EditorGUILayout.HorizontalScope(InspectorEditor.Skin.Label) :
                                  new EditorGUILayout.HorizontalScope(InspectorEditor.Skin.TextArea);

            state.Foldout = InspectorGUI.Foldout(GetFoldoutData(node),
                                                 GUI.MakeLabel(GetNodeTypeString(node) + ' ' +
                                                               SelectGameObjectDropdownMenuTool.GetGUIContent(node.Parent).text,
                                                               !validatedNode.Valid,
                                                               validatedNode.ErrorString),
                                                 newState =>
            {
                Selected = newState ? node : null;
                EditorUtility.SetDirty(Parent);
            });

            state.InsertBefore = InspectorGUI.Button(MiscIcon.EntryInsertBefore,
                                                     true,
                                                     "Insert a new node before this node.",
                                                     GUILayout.Width(18));
            state.InsertAfter = InspectorGUI.Button(MiscIcon.EntryInsertAfter,
                                                    true,
                                                    "Insert a new node after this node.",
                                                    GUILayout.Width(18));
            state.Erase = InspectorGUI.Button(MiscIcon.EntryRemove,
                                              true,
                                              "Remove this node from the route.",
                                              GUILayout.Width(18));
            horizontalScope?.Dispose();
            verticalScope?.Dispose();

            return(state);
        }
示例#2
0
        private void HandleDragDrop(Event current, SceneView sceneView)
        {
            var mouseOverSceneView = Manager.IsMouseOverWindow(sceneView);
            var mouseOverHierarchy = !mouseOverSceneView &&
                                     Manager.IsMouseOverWindow(Manager.EditorWindowType.SceneHierarchyWindow);

            var dragDropSceneViewActive = (mouseOverSceneView || mouseOverHierarchy) &&
                                          (current.type == EventType.DragPerform || current.type == EventType.DragUpdated);

            if (!dragDropSceneViewActive)
            {
                return;
            }

            Manager.UpdateMouseOverPrimitives(current, true);

            var mouseOverShapes         = HasShapeMaterialProperty(Manager.MouseOverObject);
            var isDraggingShapeMaterial = DragAndDrop.objectReferences.Length == 1 &&
                                          DragAndDrop.objectReferences[0] is AGXUnity.ShapeMaterial;

            DragAndDrop.visualMode = isDraggingShapeMaterial && mouseOverShapes ?
                                     DragAndDropVisualMode.Copy :
                                     DragAndDropVisualMode.Rejected;
            if (mouseOverShapes &&
                isDraggingShapeMaterial &&
                Event.current.type == EventType.DragPerform)
            {
                DragAndDrop.AcceptDrag();

                DroppedShapeMaterial = DragAndDrop.objectReferences[0] as AGXUnity.ShapeMaterial;

                var menuTool = new SelectGameObjectDropdownMenuTool()
                {
                    Target = Manager.MouseOverObject
                };
                menuTool.OnSelect = go =>
                {
                    var    shapes    = go.GetComponentsInChildren <AGXUnity.Collide.Shape>();
                    var    wires     = go.GetComponentsInChildren <AGXUnity.Wire>();
                    var    cables    = go.GetComponentsInChildren <AGXUnity.Cable>();
                    var    tracks    = go.GetComponentsInChildren <AGXUnity.Model.Track>();
                    var    terrains  = go.GetComponentsInChildren <AGXUnity.Model.DeformableTerrain>();
                    Action assignAll = () =>
                    {
                        Undo.SetCurrentGroupName("Assigning shape materials.");
                        var undoGroup = Undo.GetCurrentGroup();
                        foreach (var shape in shapes)
                        {
                            Undo.RecordObject(shape, "New shape material");
                            shape.Material = DroppedShapeMaterial;
                        }
                        foreach (var wire in wires)
                        {
                            Undo.RecordObject(wire, "New shape material");
                            wire.Material = DroppedShapeMaterial;
                        }
                        foreach (var cable in cables)
                        {
                            Undo.RecordObject(cable, "New shape material");
                            cable.Material = DroppedShapeMaterial;
                        }
                        foreach (var track in tracks)
                        {
                            Undo.RecordObject(track, "New shape material");
                            track.Material = DroppedShapeMaterial;
                        }
                        foreach (var terrain in terrains)
                        {
                            Undo.RecordObject(terrain, "New shape material");
                            terrain.Material = DroppedShapeMaterial;
                        }

                        // TODO GUI: Call RigidBody.UpdateMassProperties for affected bodies.

                        Undo.CollapseUndoOperations(undoGroup);
                    };

                    var sumSupported = shapes.Length + wires.Length + cables.Length + tracks.Length + terrains.Length;
                    if (sumSupported == 0)
                    {
                        Debug.LogWarning("Object selected doesn't have shapes, wires, cables or tracks.", go);
                    }
                    else if (sumSupported == 1 || EditorUtility.DisplayDialog("Assign shape materials",
                                                                              string.Format("Assign materials to:\n  - #shapes: {0}\n  - #wires: {1}\n  - #cables: {2}\n  - #tracks: {3}",
                                                                                            shapes.Length, wires.Length, cables.Length, tracks.Length), "Assign", "Ignore all"))
                    {
                        assignAll();
                    }

                    DroppedShapeMaterial = null;
                };
                menuTool.Show();
                AddChild(menuTool);
            }
        }
示例#3
0
        public void OnInspectorGUI()
        {
            InspectorGUI.OnDropdownToolBegin($"Disable collisions between {m_mainObject.name} and other objects selected in Scene View.");

            var skin         = InspectorEditor.Skin;
            var emptyContent = GUI.MakeLabel(" ");

            EditorGUILayout.LabelField(GUI.MakeLabel("Disable: ", true),
                                       SelectGameObjectDropdownMenuTool.GetGUIContent(m_mainObject),
                                       skin.TextArea);


            EditorGUILayout.LabelField(emptyContent,
                                       GUI.MakeLabel(GUI.Symbols.ArrowLeftRight.ToString()));

            if (m_selected.Count == 0)
            {
                EditorGUILayout.LabelField(emptyContent,
                                           GUI.MakeLabel("Select object(s) in scene view" + AwaitingUserActionDots()),
                                           skin.TextArea);
            }
            else
            {
                int removeIndex = -1;
                for (int i = 0; i < m_selected.Count; ++i)
                {
                    GUILayout.BeginHorizontal();
                    {
                        EditorGUILayout.LabelField(emptyContent,
                                                   SelectGameObjectDropdownMenuTool.GetGUIContent(m_selected[i]),
                                                   skin.TextArea);
                        if (InspectorGUI.Button(MiscIcon.EntryRemove,
                                                true,
                                                "Remove pair.",
                                                GUILayout.Width(14)))
                        {
                            removeIndex = i;
                        }
                    }
                    GUILayout.EndHorizontal();
                }

                if (removeIndex >= 0)
                {
                    m_selected.RemoveAt(removeIndex);
                }
            }

            var applyCancelState = InspectorGUI.PositiveNegativeButtons(m_selected.Count > 0,
                                                                        "Apply",
                                                                        "Apply current configuration.",
                                                                        "Cancel");

            if (applyCancelState == InspectorGUI.PositiveNegativeResult.Positive)
            {
                string selectedGroupName   = m_mainObject.GetInstanceID().ToString();
                string mainObjectGroupName = "";
                for (int i = 0; i < m_selected.Count; ++i)
                {
                    mainObjectGroupName += m_selected[i].GetInstanceID().ToString() +
                                           (i != m_selected.Count - 1 ? "_" : "");
                }

                Undo.SetCurrentGroupName("Disabling collisions");
                var undoGroupId = Undo.GetCurrentGroup();

                if (m_mainObject.GetComponent <CollisionGroups>() == null)
                {
                    Undo.AddComponent <CollisionGroups>(m_mainObject);
                }

                Undo.RecordObject(m_mainObject.GetComponent <CollisionGroups>(), "Adding collision group");
                m_mainObject.GetComponent <CollisionGroups>().AddGroup(mainObjectGroupName,
                                                                       ShouldPropagateToChildren(m_mainObject));
                foreach (var selected in m_selected)
                {
                    if (selected.GetComponent <CollisionGroups>() == null)
                    {
                        Undo.AddComponent <CollisionGroups>(selected);
                    }
                    Undo.RecordObject(selected.GetComponent <CollisionGroups>(), "Adding collision group");
                    selected.GetComponent <CollisionGroups>().AddGroup(selectedGroupName,
                                                                       ShouldPropagateToChildren(selected));
                }

                // TopMenu.GetOrCreate works with Undo.
                Undo.RecordObject(TopMenu.GetOrCreateUniqueGameObject <CollisionGroupsManager>(),
                                  "Adding collision group to manager.");

                CollisionGroupsManager.Instance.SetEnablePair(mainObjectGroupName, selectedGroupName, false);

                Undo.CollapseUndoOperations(undoGroupId);

                PerformRemoveFromParent();
            }
            else if (applyCancelState == InspectorGUI.PositiveNegativeResult.Negative)
            {
                PerformRemoveFromParent();
            }

            InspectorGUI.OnDropdownToolEnd();
        }
        public void OnInspectorGUI(GUISkin skin)
        {
            GUILayout.BeginHorizontal();
            {
                GUILayout.Label(GUI.MakeLabel("Disable: ", true), skin.label);
                GUILayout.Label(SelectGameObjectDropdownMenuTool.GetGUIContent(m_mainObject), skin.textField);
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            {
                GUILayout.FlexibleSpace();
                GUILayout.Label(GUI.MakeLabel(GUI.Symbols.Synchronized.ToString()), skin.label);
                GUILayout.BeginVertical();
                {
                    if (m_selected.Count == 0)
                    {
                        GUILayout.Label(GUI.MakeLabel("None", true), skin.label, GUILayout.Width(180));
                    }
                    else
                    {
                        int removeIndex = -1;
                        for (int i = 0; i < m_selected.Count; ++i)
                        {
                            GUILayout.BeginHorizontal();
                            {
                                GUILayout.Label(SelectGameObjectDropdownMenuTool.GetGUIContent(m_selected[i]), GUI.Align(skin.textField, TextAnchor.MiddleLeft), GUILayout.Height(20));
                                using (GUI.NodeListButtonColor)
                                    if (GUILayout.Button(GUI.MakeLabel(GUI.Symbols.ListEraseElement.ToString()), skin.button, GUILayout.Width(18), GUILayout.Height(18)))
                                    {
                                        removeIndex = i;
                                    }
                            }
                            GUILayout.EndHorizontal();
                        }

                        if (removeIndex >= 0)
                        {
                            m_selected.RemoveAt(removeIndex);
                        }
                    }
                }
                GUILayout.EndVertical();
            }
            GUILayout.EndHorizontal();

            GUILayout.Space(12);

            bool applyPressed  = false;
            bool cancelPressed = false;

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

                UnityEngine.GUI.enabled = m_selected.Count > 0;
                applyPressed            = GUILayout.Button(GUI.MakeLabel("Apply", true, "Apply current configuration"), skin.button, GUILayout.Width(86), GUILayout.Height(26));
                UnityEngine.GUI.enabled = true;

                GUILayout.BeginVertical();
                {
                    GUILayout.Space(11);
                    cancelPressed = GUILayout.Button(GUI.MakeLabel("Cancel", false, "Cancel/reset"), skin.button, GUILayout.Width(64), GUILayout.Height(18));
                }
                GUILayout.EndVertical();
            }
            GUILayout.EndHorizontal();

            if (applyPressed)
            {
                string selectedGroupName   = m_mainObject.GetInstanceID().ToString();
                string mainObjectGroupName = "";
                for (int i = 0; i < m_selected.Count; ++i)
                {
                    mainObjectGroupName += m_selected[i].GetInstanceID().ToString() + (i != m_selected.Count - 1 ? "_" : "");
                }

                m_mainObject.GetOrCreateComponent <CollisionGroups>().AddGroup(mainObjectGroupName, ShouldPropagateToChildren(m_mainObject));
                foreach (var selected in m_selected)
                {
                    selected.GetOrCreateComponent <CollisionGroups>().AddGroup(selectedGroupName, ShouldPropagateToChildren(selected));
                }

                CollisionGroupsManager.Instance.SetEnablePair(mainObjectGroupName, selectedGroupName, false);

                PerformRemoveFromParent();
            }
            else if (cancelPressed)
            {
                PerformRemoveFromParent();
            }
        }
示例#5
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);
            }
        }