internal static void UpdateMeshHandles(bool selectionOrVertexCountChanged = true)
        {
            if (!s_Instance)
            {
                return;
            }

            try
            {
                EditorHandleDrawing.RebuildSelectedHandles(MeshSelection.topInternal, selectMode);
            }
            catch
            {
                // happens on undo when c++ object is gone but c# isn't in the know
                EditorHandleDrawing.ClearHandles();
            }
        }
        void DrawHandleGUI(SceneView sceneView)
        {
            if (sceneView != SceneView.lastActiveSceneView)
            {
                return;
            }

            if (m_CurrentEvent.type == EventType.Repaint &&
                !SceneDragAndDropListener.isDragging &&
                m_Hovering != null &&
                GUIUtility.hotControl == 0 &&
                HandleUtility.nearestControl == m_DefaultControl &&
                selectMode.IsMeshElementMode())
            {
                try
                {
                    EditorHandleDrawing.DrawSceneSelection(m_Hovering);
                }
                catch
                {
                    // this happens on undo, when c++ object is destroyed but c# side thinks it's still alive
                }
            }

            using (new HandleGUI())
            {
                int screenWidth  = (int)sceneView.position.width;
                int screenHeight = (int)sceneView.position.height;

                switch ((SceneToolbarLocation)s_SceneToolbarLocation)
                {
                case SceneToolbarLocation.BottomCenter:
                    m_ElementModeToolbarRect.x = (screenWidth / 2 - 64);
                    m_ElementModeToolbarRect.y = screenHeight - m_ElementModeToolbarRect.height * 3;
                    break;

                case SceneToolbarLocation.BottomLeft:
                    m_ElementModeToolbarRect.x = 12;
                    m_ElementModeToolbarRect.y = screenHeight - m_ElementModeToolbarRect.height * 3;
                    break;

                case SceneToolbarLocation.BottomRight:
                    m_ElementModeToolbarRect.x = screenWidth - (m_ElementModeToolbarRect.width + 12);
                    m_ElementModeToolbarRect.y = screenHeight - m_ElementModeToolbarRect.height * 3;
                    break;

                case SceneToolbarLocation.UpperLeft:
                    m_ElementModeToolbarRect.x = 12;
                    m_ElementModeToolbarRect.y = 10;
                    break;

                case SceneToolbarLocation.UpperRight:
                    m_ElementModeToolbarRect.x = screenWidth - (m_ElementModeToolbarRect.width + 96);
                    m_ElementModeToolbarRect.y = 10;
                    break;

                default:
                    m_ElementModeToolbarRect.x = (screenWidth / 2 - 64);
                    m_ElementModeToolbarRect.y = 10;
                    break;
                }

                selectMode = UI.EditorGUIUtility.DoElementModeToolbar(m_ElementModeToolbarRect, selectMode);

                if (s_ShowSceneInfo)
                {
                    Vector2 size = UI.EditorStyles.sceneTextBox.CalcSize(m_SceneInfo);
                    m_SceneInfoRect.width  = size.x;
                    m_SceneInfoRect.height = size.y;
                    GUI.Label(m_SceneInfoRect, m_SceneInfo, UI.EditorStyles.sceneTextBox);
                }

                if (m_IsDragging)
                {
                    if (m_CurrentEvent.type == EventType.Repaint)
                    {
                        // Always draw from lowest to largest values
                        var start = Vector2.Min(m_InitialMousePosition, m_CurrentEvent.mousePosition);
                        var end   = Vector2.Max(m_InitialMousePosition, m_CurrentEvent.mousePosition);

                        m_MouseDragRect = new Rect(start.x, start.y, end.x - start.x, end.y - start.y);

                        SceneStyles.selectionRect.Draw(m_MouseDragRect, false, false, false, false);
                    }
                    else if (m_CurrentEvent.isMouse)
                    {
                        HandleUtility.Repaint();
                    }
                }
            }
        }
        void OnSceneGUI(SceneView sceneView)
        {
            SceneStyles.Init();

            m_CurrentEvent = Event.current;

            EditorHandleDrawing.DrawSceneHandles(SceneDragAndDropListener.isDragging ? SelectMode.None : selectMode);

            DrawHandleGUI(sceneView);

            if (m_CurrentEvent.type == EventType.KeyDown)
            {
                // Escape isn't assignable as a shortcut
                if (m_CurrentEvent.keyCode == KeyCode.Escape && selectMode != SelectMode.Object)
                {
                    selectMode = SelectMode.Object;

                    m_IsDragging          = false;
                    m_IsReadyForMouseDrag = false;

                    m_CurrentEvent.Use();
                }
            }

            if (selectMode == SelectMode.Object)
            {
                return;
            }

            bool pathSelectionModifier = EditorHandleUtility.IsSelectionPathModifier(m_CurrentEvent.modifiers);

            // Check mouse position in scene and determine if we should highlight something
            if (s_ShowHoverHighlight &&
                selectMode.IsMeshElementMode() &&
                (m_CurrentEvent.type == EventType.MouseMove ||
                 (m_wasSelectingPath != pathSelectionModifier && m_CurrentEvent.isKey)))
            {
                m_Hovering.CopyTo(m_HoveringPrevious);
                if (GUIUtility.hotControl != 0 ||
                    EditorSceneViewPicker.MouseRayHitTest(m_CurrentEvent.mousePosition, selectMode, m_ScenePickerPreferences, m_Hovering) > ScenePickerPreferences.maxPointerDistance)
                {
                    m_Hovering.Clear();
                }

                if (!m_Hovering.Equals(m_HoveringPrevious))
                {
                    if (pathSelectionModifier)
                    {
                        EditorSceneViewPicker.DoMouseHover(m_Hovering);
                    }

                    SceneView.RepaintAll();
                }
            }

            m_wasSelectingPath = pathSelectionModifier;

            if (Tools.current == Tool.View)
            {
                return;
            }

            switch (m_CurrentEvent.type)
            {
            case EventType.ValidateCommand:
            case EventType.ExecuteCommand:
                bool execute = m_CurrentEvent.type == EventType.ExecuteCommand;
                switch (m_CurrentEvent.commandName)
                {
                case "SelectAll":
                    if (execute)
                    {
                        SelectAll();
                    }
                    m_CurrentEvent.Use();
                    break;

                case "DeselectAll":
                    if (execute)
                    {
                        DeselectAll();
                    }
                    m_CurrentEvent.Use();
                    break;

                case "InvertSelection":
                    if (execute)
                    {
                        InvertSelection();
                    }
                    m_CurrentEvent.Use();
                    break;
                }
                break;
            }

            if (EditorHandleUtility.SceneViewInUse(m_CurrentEvent))
            {
                if (m_IsDragging)
                {
                    m_IsDragging = false;
                }

                if (GUIUtility.hotControl == m_DefaultControl)
                {
                    GUIUtility.hotControl = 0;
                }

                return;
            }

            // This prevents us from selecting other objects in the scene,
            // and allows for the selection of faces / vertices.
            m_DefaultControl = GUIUtility.GetControlID(FocusType.Passive);
            if (Event.current.type == EventType.Layout)
            {
                HandleUtility.AddDefaultControl(m_DefaultControl);
            }

            if (m_CurrentEvent.type == EventType.MouseDown && HandleUtility.nearestControl == m_DefaultControl)
            {
                // double clicking object
                if (m_CurrentEvent.clickCount > 1)
                {
                    DoubleClick(m_CurrentEvent);
                }

                m_InitialMousePosition = m_CurrentEvent.mousePosition;
                // readyForMouseDrag prevents a bug wherein after ending a drag an errant
                // MouseDrag event is sent with no corresponding MouseDown/MouseUp event.
                m_IsReadyForMouseDrag = true;

                GUIUtility.hotControl = m_DefaultControl;
            }

            if (m_CurrentEvent.type == EventType.MouseDrag && m_IsReadyForMouseDrag && GUIUtility.hotControl == m_DefaultControl)
            {
                if (!m_IsDragging && Vector2.Distance(m_CurrentEvent.mousePosition, m_InitialMousePosition) > k_MouseDragThreshold)
                {
                    sceneView.Repaint();
                    m_IsDragging = true;
                }
            }

            if (m_CurrentEvent.type == EventType.Ignore)
            {
                if (m_IsDragging)
                {
                    m_IsReadyForMouseDrag = false;
                    m_IsDragging          = false;
                    EditorSceneViewPicker.DoMouseDrag(m_MouseDragRect, selectMode, m_ScenePickerPreferences);
                }

                if (m_WasDoubleClick)
                {
                    m_WasDoubleClick = false;
                }

                if (GUIUtility.hotControl == m_DefaultControl)
                {
                    GUIUtility.hotControl = 0;
                }
            }

            if (m_CurrentEvent.type == EventType.MouseUp && GUIUtility.hotControl == m_DefaultControl)
            {
                GUIUtility.hotControl = 0;

                if (m_WasDoubleClick)
                {
                    m_WasDoubleClick = false;
                }
                else
                {
                    if (!m_IsDragging)
                    {
                        if (UVEditor.instance)
                        {
                            UVEditor.instance.ResetUserPivot();
                        }

                        EditorSceneViewPicker.DoMouseClick(m_CurrentEvent, selectMode, m_ScenePickerPreferences);
                        UpdateSelection();
                    }
                    else
                    {
                        m_IsDragging          = false;
                        m_IsReadyForMouseDrag = false;

                        if (UVEditor.instance)
                        {
                            UVEditor.instance.ResetUserPivot();
                        }

                        EditorSceneViewPicker.DoMouseDrag(m_MouseDragRect, selectMode, m_ScenePickerPreferences);

                        if (GUIUtility.hotControl == m_DefaultControl)
                        {
                            GUIUtility.hotControl = 0;
                        }
                    }
                }
            }
        }
예제 #4
0
        void OnSceneGUI(SceneView sceneView)
        {
            SceneStyles.Init();

            m_CurrentEvent = Event.current;

            EditorHandleDrawing.DrawSceneHandles(SceneDragAndDropListener.isDragging ? SelectMode.None : selectMode);

            DrawHandleGUI(sceneView);

            if (m_CurrentEvent.type == EventType.KeyDown)
            {
                // Escape isn't assignable as a shortcut
                if (m_CurrentEvent.keyCode == KeyCode.Escape && selectMode != SelectMode.Object)
                {
                    selectMode = SelectMode.Object;

                    m_IsDragging          = false;
                    m_IsReadyForMouseDrag = false;

                    m_CurrentEvent.Use();
                }
            }

            if (selectMode == SelectMode.Object)
            {
                return;
            }

            bool pathSelectionModifier = EditorHandleUtility.IsSelectionPathModifier(m_CurrentEvent.modifiers);

            // Check mouse position in scene and determine if we should highlight something
            if (s_ShowHoverHighlight &&
                selectMode.IsMeshElementMode() &&
                (m_CurrentEvent.type == EventType.MouseMove ||
                 (m_wasSelectingPath != pathSelectionModifier && m_CurrentEvent.isKey)))
            {
                m_Hovering.CopyTo(m_HoveringPrevious);
                if (GUIUtility.hotControl != 0 ||
                    EditorSceneViewPicker.MouseRayHitTest(m_CurrentEvent.mousePosition, selectMode, m_ScenePickerPreferences, m_Hovering) > ScenePickerPreferences.maxPointerDistance)
                {
                    m_Hovering.Clear();
                }

                if (!m_Hovering.Equals(m_HoveringPrevious))
                {
                    if (pathSelectionModifier)
                    {
                        EditorSceneViewPicker.DoMouseHover(m_Hovering);
                    }

                    SceneView.RepaintAll();
                }
            }

            m_wasSelectingPath = pathSelectionModifier;

            if (Tools.current == Tool.View)
            {
                return;
            }

            switch (m_CurrentEvent.type)
            {
            case EventType.ValidateCommand:
            case EventType.ExecuteCommand:
                bool execute = m_CurrentEvent.type == EventType.ExecuteCommand;
                switch (m_CurrentEvent.commandName)
                {
                case "SelectAll":
                    if (execute)
                    {
                        SelectAll();
                    }
                    m_CurrentEvent.Use();
                    break;

                case "DeselectAll":
                    if (execute)
                    {
                        DeselectAll();
                    }
                    m_CurrentEvent.Use();
                    break;

                case "InvertSelection":
                    if (execute)
                    {
                        InvertSelection();
                    }
                    m_CurrentEvent.Use();
                    break;
                }
                break;
            }

            if (EditorHandleUtility.SceneViewInUse(m_CurrentEvent))
            {
                if (m_IsDragging)
                {
                    m_IsDragging = false;
                }

                if (GUIUtility.hotControl == m_DefaultControl)
                {
                    GUIUtility.hotControl = 0;
                }

                return;
            }

            // This prevents us from selecting other objects in the scene,
            // and allows for the selection of faces / vertices.
            m_DefaultControl = GUIUtility.GetControlID(FocusType.Passive);
            if (Event.current.type == EventType.Layout)
            {
                HandleUtility.AddDefaultControl(m_DefaultControl);
            }

            HandleMouseEvent(sceneView, m_DefaultControl);
        }