Ejemplo n.º 1
0
        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();
            }
        }
Ejemplo n.º 2
0
        private void RouteGUI(GUISkin 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, skin, 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);
            }
        }
        private void HandleDragDrop(Event current, SceneView sceneView)
        {
            var mouseOverSceneView = EditorWindow.mouseOverWindow == sceneView;
            var mouseOverHierarchy = !mouseOverSceneView &&
                                     EditorWindow.mouseOverWindow != null &&
                                     EditorWindow.mouseOverWindow.GetType().FullName == "UnityEditor.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 =>
                {
                    AgXUnity.Collide.Shape[] shapes = go.GetComponentsInChildren <AgXUnity.Collide.Shape>();
                    AgXUnity.Wire[]          wires  = go.GetComponentsInChildren <AgXUnity.Wire>();
                    AgXUnity.Cable[]         cables = go.GetComponentsInChildren <AgXUnity.Cable>();
                    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;
                        }
                        Undo.CollapseUndoOperations(undoGroup);
                    };

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

                    DroppedShapeMaterial = null;
                };
                menuTool.Show();
                AddChild(menuTool);
            }
        }