示例#1
0
        internal static void OnSceneGUI(SceneView sceneView)
        {
            if (e.type == EventType.KeyDown &&
                e.modifiers == EventModifiers.None &&
                e.keyCode == KeyCode.B)
            {
                PeekPlugin.Configuration.displaySceneToolbars = !PeekPlugin.Configuration.displaySceneToolbars;
                PeekPlugin.Configuration.Save();
                e.Use();
            }

            if (!PeekPlugin.Configuration.enableSceneToolbars.Display(sceneView.maximized) ||
                !PeekPlugin.Configuration.displaySceneToolbars)
            {
                return;
            }

            Profiler.BeginSample("Peek." + nameof(SceneToolbars));

            try
            {
                Handles.BeginGUI();

                DrawToolbar(sceneView, selectionToolbarControl, selectionToolbarTargets);

                if (PeekPlugin.Configuration.enableStickyDragAndDrop)
                {
                    if (dragToolbarControl != null)
                    {
                        EditorGUI.BeginDisabledGroup(!dragToolbarLocked);
                        DrawToolbar(sceneView, dragToolbarControl, new[] { dragToolbarTarget });
                        EditorGUI.EndDisabledGroup();
                    }

                    RefreshDragToolbar(sceneView);
                }

                if (PeekPlugin.Configuration.enableHierarchySpaceShortcut &&
                    e.type == EventType.KeyDown &&
                    e.modifiers == EventModifiers.None &&
                    e.keyCode == KeyCode.Space)
                {
                    if (OpenHierarchyTool())
                    {
                        e.Use();
                    }
                }

                Handles.EndGUI();
            }
            catch (Exception ex)
            {
                Debug.LogException(ex);
            }

            Profiler.EndSample();
        }
示例#2
0
        internal static void OnSceneGUI(SceneView sceneView)
        {
            if (PeekPlugin.Configuration.toggleToolbarShortcut.Check())
            {
                PeekPlugin.Configuration.displaySceneToolbars = !PeekPlugin.Configuration.displaySceneToolbars;
                PeekPlugin.Configuration.Save();
                e.TryUse();
            }

            if (!PeekPlugin.Configuration.enableSceneToolbars.Display(sceneView.maximized) ||
                !PeekPlugin.Configuration.displaySceneToolbars)
            {
                return;
            }

            Profiler.BeginSample("Peek." + nameof(SceneToolbars));

            try
            {
                Handles.BeginGUI();

                selectionToolbarControls.TryGetValue(sceneView, out var selectionToolbarControl);

                DrawToolbar(sceneView, selectionToolbarControl, selectionToolbarTargets);

                if (PeekPlugin.Configuration.enableStickyDragAndDrop)
                {
                    if (dragToolbarControl != null)
                    {
                        EditorGUI.BeginDisabledGroup(!dragToolbarLocked);
                        DrawToolbar(sceneView, dragToolbarControl, new[] { dragToolbarTarget });
                        EditorGUI.EndDisabledGroup();
                    }

                    RefreshDragToolbar(sceneView);
                }

                if (PeekPlugin.Configuration.selectionHierarchyShortcut.Check(e))
                {
                    if (OpenHierarchyTool(selectionToolbarControl))
                    {
                        e.Use();
                    }
                }

                Handles.EndGUI();
            }
            catch (Exception ex)
            {
                Debug.LogException(ex);
            }
            finally
            {
                Profiler.EndSample();
            }
        }
示例#3
0
        public static bool SelectPoints(IEditablePoint points, Transform cloudTransform, ref List <int> selection, bool firstSelect)
        {
            int controlID = GUIUtility.GetControlID(FocusType.Passive);

            if (Event.current.alt && Event.current.type != EventType.Repaint)
            {
                return(false);
            }
            bool  result  = false;
            Event current = Event.current;

            switch (current.GetTypeForControl(controlID))
            {
            case EventType.MouseDown:
                if ((HandleUtility.nearestControl == controlID || firstSelect) && current.button == 0)
                {
                    if (!current.shift && !EditorGUI.actionKey)
                    {
                        selection.Clear();
                        result = true;
                    }
                    GUIUtility.hotControl = controlID;
                    PointEditor.s_StartMouseDragPosition = current.mousePosition;
                    PointEditor.s_StartDragSelection     = new List <int>(selection);
                    current.Use();
                }
                break;

            case EventType.MouseUp:
                if (GUIUtility.hotControl == controlID && current.button == 0)
                {
                    if (!PointEditor.s_DidDrag)
                    {
                        int num = PointEditor.FindNearest(PointEditor.s_StartMouseDragPosition, cloudTransform, points);
                        if (num != -1)
                        {
                            if (!current.shift && !EditorGUI.actionKey)
                            {
                                selection.Add(num);
                            }
                            else
                            {
                                int num2 = selection.IndexOf(num);
                                if (num2 != -1)
                                {
                                    selection.RemoveAt(num2);
                                }
                                else
                                {
                                    selection.Add(num);
                                }
                            }
                        }
                        GUI.changed = true;
                        result      = true;
                    }
                    PointEditor.s_StartDragSelection     = null;
                    PointEditor.s_StartMouseDragPosition = Vector2.zero;
                    PointEditor.s_DidDrag = false;
                    GUIUtility.hotControl = 0;
                    current.Use();
                }
                break;

            case EventType.MouseDrag:
                if (GUIUtility.hotControl == controlID && current.button == 0)
                {
                    PointEditor.s_DidDrag = true;
                    selection.Clear();
                    selection.AddRange(PointEditor.s_StartDragSelection);
                    Rect      rect   = PointEditor.FromToRect(PointEditor.s_StartMouseDragPosition, current.mousePosition);
                    Matrix4x4 matrix = Handles.matrix;
                    Handles.matrix = cloudTransform.localToWorldMatrix;
                    for (int i = 0; i < points.Count; i++)
                    {
                        Vector2 point = HandleUtility.WorldToGUIPoint(points.GetPosition(i));
                        if (rect.Contains(point))
                        {
                            selection.Add(i);
                        }
                    }
                    Handles.matrix = matrix;
                    GUI.changed    = true;
                    current.Use();
                }
                break;

            case EventType.Repaint:
                if (GUIUtility.hotControl == controlID && current.mousePosition != PointEditor.s_StartMouseDragPosition)
                {
                    GUIStyle gUIStyle = "SelectionRect";
                    Handles.BeginGUI();
                    gUIStyle.Draw(PointEditor.FromToRect(PointEditor.s_StartMouseDragPosition, current.mousePosition), false, false, false, false);
                    Handles.EndGUI();
                }
                break;

            case EventType.Layout:
                HandleUtility.AddDefaultControl(controlID);
                break;
            }
            selection = selection.Distinct <int>().ToList <int>();
            return(result);
        }
        public void OnGUI()
        {
            Event evt = Event.current;

            Handles.BeginGUI();

            Vector2 mousePos = evt.mousePosition;
            int     id       = s_RectSelectionID;

            switch (evt.GetTypeForControl(id))
            {
            case EventType.Layout:
                if (!Tools.viewToolActive)
                {
                    HandleUtility.AddDefaultControl(id);
                }
                break;

            case EventType.MouseDown:
                if (HandleUtility.nearestControl == id && evt.button == 0)
                {
                    GUIUtility.hotControl = id;
                    m_SelectStartPoint    = mousePos;
                    m_SelectionStart      = Selection.objects;
                    m_RectSelecting       = false;
                }
                break;

            case EventType.MouseDrag:
                if (GUIUtility.hotControl == id)
                {
                    if (!m_RectSelecting && (mousePos - m_SelectStartPoint).magnitude > 6f)
                    {
                        EditorApplication.modifierKeysChanged += SendCommandsOnModifierKeys;
                        m_RectSelecting    = true;
                        m_LastSelection    = null;
                        m_CurrentSelection = null;
                    }
                    if (m_RectSelecting)
                    {
                        m_SelectMousePoint = new Vector2(Mathf.Max(mousePos.x, 0), Mathf.Max(mousePos.y, 0));
                        GameObject[] rectObjs = HandleUtility.PickRectObjects(EditorGUIExt.FromToRect(m_SelectStartPoint, m_SelectMousePoint));
                        m_CurrentSelection = rectObjs;
                        bool setIt = false;
                        if (m_LastSelection == null)
                        {
                            m_LastSelection = new Dictionary <GameObject, bool>();
                            setIt           = true;
                        }
                        setIt |= m_LastSelection.Count != rectObjs.Length;
                        if (!setIt)
                        {
                            Dictionary <GameObject, bool> set = new Dictionary <GameObject, bool>(rectObjs.Length);
                            foreach (GameObject g in rectObjs)
                            {
                                set.Add(g, false);
                            }
                            foreach (GameObject g in m_LastSelection.Keys)
                            {
                                if (!set.ContainsKey(g))
                                {
                                    setIt = true;
                                    break;
                                }
                            }
                        }
                        if (setIt)
                        {
                            m_LastSelection = new Dictionary <GameObject, bool>(rectObjs.Length);
                            foreach (GameObject g in rectObjs)
                            {
                                m_LastSelection.Add(g, false);
                            }
                            if (rectObjs != null)
                            {
                                if (evt.shift)
                                {
                                    UpdateSelection(m_SelectionStart, rectObjs, SelectionType.Additive, m_RectSelecting);
                                }
                                else if (EditorGUI.actionKey)
                                {
                                    UpdateSelection(m_SelectionStart, rectObjs, SelectionType.Subtractive, m_RectSelecting);
                                }
                                else
                                {
                                    UpdateSelection(m_SelectionStart, rectObjs, SelectionType.Normal, m_RectSelecting);
                                }
                            }
                        }
                    }
                    evt.Use();
                }
                break;

            case EventType.Repaint:
                if (GUIUtility.hotControl == id && m_RectSelecting)
                {
                    EditorStyles.selectionRect.Draw(EditorGUIExt.FromToRect(m_SelectStartPoint, m_SelectMousePoint), GUIContent.none, false, false, false, false);
                }
                break;

            case EventType.MouseUp:
                if (GUIUtility.hotControl == id && evt.button == 0)
                {
                    GUIUtility.hotControl = 0;
                    if (m_RectSelecting)
                    {
                        EditorApplication.modifierKeysChanged -= SendCommandsOnModifierKeys;
                        m_RectSelecting  = false;
                        m_SelectionStart = new Object[0];
                        evt.Use();
                    }
                    else
                    {
                        if (evt.shift || EditorGUI.actionKey)
                        {
                            // For shift, we check if EXACTLY the active GO is hovered by mouse and then subtract. Otherwise additive.
                            // For control/cmd, we check if ANY of the selected GO is hovered by mouse and then subtract. Otherwise additive.
                            // Control/cmd takes priority over shift.
                            GameObject hovered = HandleUtility.PickGameObject(evt.mousePosition, false);
                            if (EditorGUI.actionKey ? Selection.gameObjects.Contains(hovered) : Selection.activeGameObject == hovered)
                            {
                                UpdateSelection(m_SelectionStart, hovered, SelectionType.Subtractive, m_RectSelecting);
                            }
                            else
                            {
                                UpdateSelection(m_SelectionStart, HandleUtility.PickGameObject(evt.mousePosition, true), SelectionType.Additive, m_RectSelecting);
                            }
                        }
                        else     // With no modifier keys, we do the "cycle through overlapped" picking logic in SceneViewPicking.cs
                        {
                            GameObject picked = SceneViewPicking.PickGameObject(evt.mousePosition);
                            UpdateSelection(m_SelectionStart, picked, SelectionType.Normal, m_RectSelecting);
                        }

                        evt.Use();
                    }
                }
                break;

            case EventType.ExecuteCommand:
                if (id == GUIUtility.hotControl && evt.commandName == EventCommandNames.ModifierKeysChanged)
                {
                    if (evt.shift)
                    {
                        UpdateSelection(m_SelectionStart, m_CurrentSelection, SelectionType.Additive, m_RectSelecting);
                    }
                    else if (EditorGUI.actionKey)
                    {
                        UpdateSelection(m_SelectionStart, m_CurrentSelection, SelectionType.Subtractive, m_RectSelecting);
                    }
                    else
                    {
                        UpdateSelection(m_SelectionStart, m_CurrentSelection, SelectionType.Normal, m_RectSelecting);
                    }
                    evt.Use();
                }
                break;
            }

            Handles.EndGUI();
        }
示例#5
0
        // This function implements selection of points. Returns true is selection changes
        public static bool SelectPoints(IEditablePoint points, Transform cloudTransform, ref List <int> selection, bool firstSelect)
        {
            int id = GUIUtility.GetControlID(FocusType.Passive);

            if (Event.current.alt && Event.current.type != EventType.Repaint)
            {
                return(false);
            }

            bool  selectionChanged = false;
            Event evt = Event.current;

            switch (evt.GetTypeForControl(id))
            {
            case EventType.Layout:
                // Tell the handles system that we're the default tool (the one that should get focus when user clicks on nothing else.)
                HandleUtility.AddDefaultControl(id);
                break;

            case EventType.MouseDown:
                // If we got a left-mouse down (HandleUtility.nearestControl== id is only true when the user clicked outside any handles),
                // we should begin selecting.
                if ((HandleUtility.nearestControl == id || firstSelect) && evt.button == 0)
                {
                    // If neither shift nor control is held down, we'll clear the selection as the fist thing.
                    if (!evt.shift && !EditorGUI.actionKey)
                    {
                        selection.Clear();
                        selectionChanged = true;
                    }

                    s_SelectionStart = new List <int>(selection);
                    // Grab focus so that we can do a rect selection.
                    GUIUtility.hotControl = id;
                    // And remember where the drag was from.
                    s_StartMouseDragPosition = evt.mousePosition;

                    // Also remember the selection at the start so additive rect selection will work correctly
                    s_StartDragSelection = new List <int>(selection);

                    // Use the mouse down event so no other controls get them
                    evt.Use();
                }
                break;

            case EventType.MouseDrag:
                // The user dragged the mouse (and we have the focus from MouseDown). We have a rect selection here
                if (GUIUtility.hotControl == id && evt.button == 0)
                {
                    s_DidDrag = true;
                    // Start by resetting the selection to what it was when the drag began.
                    selection.Clear();
                    selection.AddRange(s_StartDragSelection);

                    // now, we'll go over every point and see if it's inside the Rect defined by the mouse position and
                    // the start drag position
                    Rect r = FromToRect(s_StartMouseDragPosition, evt.mousePosition);

                    using (new Handles.DrawingScope())
                    {
                        if (cloudTransform != null)
                        {
                            Handles.matrix = cloudTransform.localToWorldMatrix;
                        }

                        // Go over all the points and add them if they are inside the rect
                        for (int i = 0; i < points.Count; i++)
                        {
                            var point = HandleUtility.WorldToGUIPointWithDepth(points.GetPosition(i));

                            // the point has to be within the selection and in front of the camera
                            if (r.Contains(point) && point.z > 0.0f)
                            {
                                if (EditorGUI.actionKey)
                                {
                                    if (s_SelectionStart.Contains(i))
                                    {
                                        selection.Remove(i);
                                    }
                                }
                                else
                                {
                                    if (!s_SelectionStart.Contains(i))
                                    {
                                        selection.Add(i);
                                    }
                                }
                            }
                        }
                    }

                    // We'll assume the selection has changed and set GUI.changed to true.
                    // Worst case, somebody will validate a bit too much, but oh well.
                    GUI.changed = true;
                    evt.Use();
                }
                break;

            case EventType.MouseUp:
                // If we got the mousedown event, the mouseup is ours as well - this is where we clean up.
                if (GUIUtility.hotControl == id && evt.button == 0)
                {
                    //Dragging vs clicking
                    if (!s_DidDrag)
                    {
                        // Find out if it was on top of a point.
                        int selectedPoint = FindNearest(s_StartMouseDragPosition, cloudTransform, points);

                        // We found a point. We either need to make it selected or add it to an existing selection.
                        if (selectedPoint != -1)
                        {
                            // If neither shift nor action is held down, simply set selection to the picked point.
                            if (!evt.shift && !EditorGUI.actionKey)
                            {
                                selection.Add(selectedPoint);
                            }
                            else
                            {
                                // Shift was held down. This means we need to add/remove the point
                                int alreadyInSelection = selection.IndexOf(selectedPoint);
                                if (alreadyInSelection != -1)
                                {
                                    selection.RemoveAt(alreadyInSelection);
                                }
                                else
                                {
                                    selection.Add(selectedPoint);
                                }
                            }
                        }

                        // Selection has changed. set GUI.changed to true so caller can react (e.g. repaint inspector).
                        GUI.changed      = true;
                        selectionChanged = true;
                    }


                    // Clean up various stuff.
                    s_StartDragSelection     = null;
                    s_StartMouseDragPosition = Vector2.zero;
                    s_DidDrag = false;

                    // Release the mouse focus
                    GUIUtility.hotControl = 0;

                    // use the event
                    evt.Use();
                }
                break;

            case EventType.Repaint:
                // If we have focus and the mouse has been moved, we'll the draw selection rect.
                if (GUIUtility.hotControl == id && evt.mousePosition != s_StartMouseDragPosition)
                {
                    GUIStyle gs = "SelectionRect";
                    Handles.BeginGUI();
                    gs.Draw(FromToRect(s_StartMouseDragPosition, evt.mousePosition), false, false, false, false);
                    Handles.EndGUI();
                }
                break;
            }
            if (selectionChanged)
            {
                selection = selection.Distinct().ToList();
            }
            return(selectionChanged);
        }
示例#6
0
        // Ensure all controlIDs used in this OnGUI are permanent controlIDs so this method can be called
        // in different places for handling input early and rendering late.
        internal void OnGUI(SceneView view)
        {
            Rect  cameraGUIRect = view.cameraRect;
            float screenSize    = Mathf.Min(cameraGUIRect.width, cameraGUIRect.height);

            if (screenSize < kRotationSize)
            {
                return;
            }

            if (Event.current.type == EventType.Repaint)
            {
                Profiler.BeginSample("SceneView.AxisSelector");
            }

            HandleContextClick(view);

            // This is a pretty weird way of doing things, but it works, so...
            Camera cam = view.camera;

            HandleUtility.PushCamera(cam);
            if (cam.orthographic)
            {
                cam.orthographicSize = .5f;
            }

            cam.cullingMask        = 0;
            cam.transform.position = cam.transform.rotation * new Vector3(0, 0, -5);
            cam.clearFlags         = CameraClearFlags.Nothing;
            cam.nearClipPlane      = .1f;
            cam.farClipPlane       = 10;
            cam.fieldOfView        = view.m_Ortho.Fade(70, 0);

            SceneView.AddCursorRect(new Rect(cameraGUIRect.width - kRotationSize + kRotationMenuInset, kRotationMenuInset, kRotationSize - 2 * kRotationMenuInset, kRotationSize + 24 - kRotationMenuInset), MouseCursor.Arrow);

            Handles.SetCamera(new Rect(cameraGUIRect.width - kRotationSize, 0, kRotationSize, kRotationSize), cam);

            Handles.BeginGUI();

            DrawRotationLock(view);
            DrawLabels(view);

            Handles.EndGUI();

            // animate visibility of three axis widgets
            for (int i = 0; i < 3; ++i)
            {
                Vector3 direction = kDirectionRotations[i] * Vector3.forward;
                dirVisible[i].target = Mathf.Abs(Vector3.Dot(cam.transform.forward, direction)) < 0.9f;
            }

            float size = HandleUtility.GetHandleSize(Vector3.zero) * .2f;

            // Do axes behind the center one
            AxisSelectors(view, cam, size, -1.0f, styles.viewAxisLabelStyle);

            // Do center handle

            Color centerColor = Handles.centerColor;

            centerColor    = Color.Lerp(centerColor, Color.gray, faded2Dgray);
            centerColor.a *= fadedVisibility;
            if (centerColor.a <= 0.1f || view.isRotationLocked)
            {
                GUI.enabled = false;
            }

            Handles.color = centerColor;
            if (Handles.Button(m_CenterButtonControlID, Vector3.zero, Quaternion.identity, size * 0.8f, size, Handles.CubeHandleCap) && !view.in2DMode && !view.isRotationLocked)
            {
                if (Event.current.clickCount == 2)
                {
                    view.FrameSelected();
                }
                else
                {
                    // If middle-click or shift-click, choose a perspective view from a nice angle,
                    // similar to in Unity 3.5.
                    if (Event.current.shift || Event.current.button == 2)
                    {
                        ViewFromNiceAngle(view, true);
                    }
                    // Else, toggle perspective
                    else
                    {
                        ViewSetOrtho(view, !view.orthographic);
                    }
                }
            }

            // Do axes in front of the center one
            AxisSelectors(view, cam, size, 1.0f, styles.viewAxisLabelStyle);

            GUI.enabled = true;

            if (!view.in2DMode && !view.isRotationLocked)
            {
                // Swipe handling
                if (Event.current.type == EditorGUIUtility.swipeGestureEventType)
                {
                    // Get swipe dir as Vector3
                    Event   evt = Event.current;
                    Vector3 swipeDir;
                    if (evt.delta.y > 0)
                    {
                        swipeDir = Vector3.up;
                    }
                    else if (evt.delta.y < 0)
                    {
                        swipeDir = -Vector3.up;
                    }
                    else if (evt.delta.x < 0) // delta x inverted for some reason
                    {
                        swipeDir = Vector3.right;
                    }
                    else
                    {
                        swipeDir = -Vector3.right;
                    }

                    // Inverse swipe dir, so swiping down will go to top view etc.
                    // This is consistent with how we do orbiting, where moving the mouse down sees the object more from above etc.
                    // Also, make swipe dir point almost 45 degrees in towards the camera.
                    // This means the swipe will pick the closest axis in the swiped direction,
                    // instead of picking the one closest to being 90 degrees away.
                    Vector3 goalVector = -swipeDir - Vector3.forward * 0.9f;

                    // Transform swipe dir by camera transform, so up is camera's local up, etc.
                    goalVector = view.camera.transform.TransformDirection(goalVector);

                    // Get global axis that's closest to the swipe dir vector
                    float bestDotProduct = 0;
                    int   dir            = 0;
                    for (int i = 0; i < 6; i++)
                    {
                        // Note that kDirectionRotations are not the forward direction of each dir;
                        // it's the back direction *towards* the camera.
                        float dotProduct = Vector3.Dot(kDirectionRotations[i] * -Vector3.forward, goalVector);
                        if (dotProduct > bestDotProduct)
                        {
                            bestDotProduct = dotProduct;
                            dir            = i;
                        }
                    }

                    // Look along chosen axis
                    ViewAxisDirection(view, dir);
                    Event.current.Use();
                }
            }

            HandleUtility.PopCamera(cam);
            Handles.SetCamera(cam);

            if (Event.current.type == EventType.Repaint)
            {
                Profiler.EndSample();
            }
        }
示例#7
0
        internal void OnGUI(SceneView view)
        {
            float num = Mathf.Min(view.position.width, view.position.height);

            if (num >= 100f)
            {
                if (Event.current.type == EventType.Repaint)
                {
                    Profiler.BeginSample("SceneView.AxisSelector");
                }
                this.HandleContextClick(view);
                Camera camera = view.camera;
                HandleUtility.PushCamera(camera);
                if (camera.orthographic)
                {
                    camera.orthographicSize = 0.5f;
                }
                camera.cullingMask        = 0;
                camera.transform.position = camera.transform.rotation * new Vector3(0f, 0f, -5f);
                camera.clearFlags         = CameraClearFlags.Nothing;
                camera.nearClipPlane      = 0.1f;
                camera.farClipPlane       = 10f;
                camera.fieldOfView        = view.m_Ortho.Fade(70f, 0f);
                SceneView.AddCursorRect(new Rect(view.position.width - 100f + 22f, 22f, 56f, 102f), MouseCursor.Arrow);
                Handles.SetCamera(new Rect(view.position.width - 100f, 0f, 100f, 100f), camera);
                Handles.BeginGUI();
                this.DrawRotationLock(view);
                this.DrawLabels(view);
                Handles.EndGUI();
                for (int i = 0; i < 3; i++)
                {
                    Vector3 rhs = SceneViewRotation.kDirectionRotations[i] * Vector3.forward;
                    this.dirVisible[i].target = (Mathf.Abs(Vector3.Dot(camera.transform.forward, rhs)) < 0.9f);
                }
                float num2 = HandleUtility.GetHandleSize(Vector3.zero) * 0.2f;
                this.AxisSelectors(view, camera, num2, -1f, SceneViewRotation.styles.viewAxisLabelStyle);
                Color color = Handles.centerColor;
                color    = Color.Lerp(color, Color.gray, this.faded2Dgray);
                color.a *= this.fadedVisibility;
                if (color.a <= 0.1f || view.isRotationLocked)
                {
                    GUI.enabled = false;
                }
                Handles.color = color;
                int        arg_27C_0 = this.m_CenterButtonControlID;
                Vector3    arg_27C_1 = Vector3.zero;
                Quaternion arg_27C_2 = Quaternion.identity;
                float      arg_27C_3 = num2 * 0.8f;
                float      arg_27C_4 = num2;
                if (SceneViewRotation.< > f__mg$cache2 == null)
                {
                    SceneViewRotation.< > f__mg$cache2 = new Handles.CapFunction(Handles.CubeHandleCap);
                }
                if (Handles.Button(arg_27C_0, arg_27C_1, arg_27C_2, arg_27C_3, arg_27C_4, SceneViewRotation.< > f__mg$cache2) && !view.in2DMode && !view.isRotationLocked)
                {
                    if (Event.current.clickCount == 2)
                    {
                        view.FrameSelected();
                    }
                    else if (Event.current.shift || Event.current.button == 2)
                    {
                        this.ViewFromNiceAngle(view, true);
                    }
                    else
                    {
                        this.ViewSetOrtho(view, !view.orthographic);
                    }
                }
                this.AxisSelectors(view, camera, num2, 1f, SceneViewRotation.styles.viewAxisLabelStyle);
                GUI.enabled = true;
                if (!view.in2DMode && !view.isRotationLocked)
                {
                    if (Event.current.type == EditorGUIUtility.swipeGestureEventType)
                    {
                        Event   current = Event.current;
                        Vector3 a;
                        if (current.delta.y > 0f)
                        {
                            a = Vector3.up;
                        }
                        else if (current.delta.y < 0f)
                        {
                            a = -Vector3.up;
                        }
                        else if (current.delta.x < 0f)
                        {
                            a = Vector3.right;
                        }
                        else
                        {
                            a = -Vector3.right;
                        }
                        Vector3 vector = -a - Vector3.forward * 0.9f;
                        vector = view.camera.transform.TransformDirection(vector);
                        float num3 = 0f;
                        int   dir  = 0;
                        for (int j = 0; j < 6; j++)
                        {
                            float num4 = Vector3.Dot(SceneViewRotation.kDirectionRotations[j] * -Vector3.forward, vector);
                            if (num4 > num3)
                            {
                                num3 = num4;
                                dir  = j;
                            }
                        }
                        this.ViewAxisDirection(view, dir);
                        Event.current.Use();
                    }
                }
                HandleUtility.PopCamera(camera);
                Handles.SetCamera(camera);
                if (Event.current.type == EventType.Repaint)
                {
                    Profiler.EndSample();
                }
            }
        }
示例#8
0
        public void OnGUI()
        {
            Event current = Event.current;

            Handles.BeginGUI();
            Vector2   mousePosition  = current.mousePosition;
            int       controlID      = s_RectSelectionID;
            EventType typeForControl = current.GetTypeForControl(controlID);

            switch (typeForControl)
            {
            case EventType.MouseDown:
                if ((HandleUtility.nearestControl == controlID) && (current.button == 0))
                {
                    GUIUtility.hotControl   = controlID;
                    this.m_SelectStartPoint = mousePosition;
                    this.m_SelectionStart   = Selection.objects;
                    this.m_RectSelecting    = false;
                }
                goto Label_04D2;

            case EventType.MouseUp:
                if ((GUIUtility.hotControl == controlID) && (current.button == 0))
                {
                    GUIUtility.hotControl = 0;
                    if (!this.m_RectSelecting)
                    {
                        if (current.shift || EditorGUI.actionKey)
                        {
                            GameObject[] gameObjects = !current.shift ? Selection.gameObjects : new GameObject[] { Selection.activeGameObject };
                            GameObject   hovered     = SceneViewPicking.GetHovered(current.mousePosition, gameObjects);
                            if (hovered != null)
                            {
                                UpdateSelection(this.m_SelectionStart, hovered, SelectionType.Subtractive, this.m_RectSelecting);
                            }
                            else
                            {
                                UpdateSelection(this.m_SelectionStart, HandleUtility.PickGameObject(current.mousePosition, true), SelectionType.Additive, this.m_RectSelecting);
                            }
                        }
                        else
                        {
                            GameObject newObject = SceneViewPicking.PickGameObject(current.mousePosition);
                            UpdateSelection(this.m_SelectionStart, newObject, SelectionType.Normal, this.m_RectSelecting);
                        }
                        current.Use();
                    }
                    else
                    {
                        EditorApplication.modifierKeysChanged = (EditorApplication.CallbackFunction)Delegate.Remove(EditorApplication.modifierKeysChanged, new EditorApplication.CallbackFunction(this.SendCommandsOnModifierKeys));
                        this.m_RectSelecting  = false;
                        this.m_SelectionStart = new Object[0];
                        current.Use();
                    }
                }
                goto Label_04D2;

            case EventType.MouseDrag:
                if (GUIUtility.hotControl != controlID)
                {
                    goto Label_04D2;
                }
                if (!this.m_RectSelecting)
                {
                    Vector2 vector2 = mousePosition - this.m_SelectStartPoint;
                    if (vector2.magnitude > 6f)
                    {
                        EditorApplication.modifierKeysChanged = (EditorApplication.CallbackFunction)Delegate.Combine(EditorApplication.modifierKeysChanged, new EditorApplication.CallbackFunction(this.SendCommandsOnModifierKeys));
                        this.m_RectSelecting    = true;
                        this.m_LastSelection    = null;
                        this.m_CurrentSelection = null;
                    }
                }
                if (this.m_RectSelecting)
                {
                    float x = Mathf.Max(mousePosition.x, 0f);
                    this.m_SelectMousePoint = new Vector2(x, Mathf.Max(mousePosition.y, 0f));
                    GameObject[] newObjects = HandleUtility.PickRectObjects(EditorGUIExt.FromToRect(this.m_SelectStartPoint, this.m_SelectMousePoint));
                    this.m_CurrentSelection = newObjects;
                    bool flag = false;
                    if (this.m_LastSelection == null)
                    {
                        this.m_LastSelection = new Dictionary <GameObject, bool>();
                        flag = true;
                    }
                    flag |= this.m_LastSelection.Count != newObjects.Length;
                    if (!flag)
                    {
                        Dictionary <GameObject, bool> dictionary = new Dictionary <GameObject, bool>(newObjects.Length);
                        foreach (GameObject obj2 in newObjects)
                        {
                            dictionary.Add(obj2, false);
                        }
                        foreach (GameObject obj3 in this.m_LastSelection.Keys)
                        {
                            if (!dictionary.ContainsKey(obj3))
                            {
                                flag = true;
                                break;
                            }
                        }
                    }
                    if (flag)
                    {
                        this.m_LastSelection = new Dictionary <GameObject, bool>(newObjects.Length);
                        foreach (GameObject obj4 in newObjects)
                        {
                            this.m_LastSelection.Add(obj4, false);
                        }
                        if (newObjects != null)
                        {
                            if (current.shift)
                            {
                                UpdateSelection(this.m_SelectionStart, newObjects, SelectionType.Additive, this.m_RectSelecting);
                            }
                            else if (EditorGUI.actionKey)
                            {
                                UpdateSelection(this.m_SelectionStart, newObjects, SelectionType.Subtractive, this.m_RectSelecting);
                            }
                            else
                            {
                                UpdateSelection(this.m_SelectionStart, newObjects, SelectionType.Normal, this.m_RectSelecting);
                            }
                        }
                    }
                }
                break;

            case EventType.Repaint:
                if ((GUIUtility.hotControl == controlID) && this.m_RectSelecting)
                {
                    EditorStyles.selectionRect.Draw(EditorGUIExt.FromToRect(this.m_SelectStartPoint, this.m_SelectMousePoint), GUIContent.none, false, false, false, false);
                }
                goto Label_04D2;

            case EventType.Layout:
                if (!Tools.viewToolActive)
                {
                    HandleUtility.AddDefaultControl(controlID);
                }
                goto Label_04D2;

            default:
                if ((typeForControl == EventType.ExecuteCommand) && ((controlID == GUIUtility.hotControl) && (current.commandName == "ModifierKeysChanged")))
                {
                    if (current.shift)
                    {
                        UpdateSelection(this.m_SelectionStart, this.m_CurrentSelection, SelectionType.Additive, this.m_RectSelecting);
                    }
                    else if (EditorGUI.actionKey)
                    {
                        UpdateSelection(this.m_SelectionStart, this.m_CurrentSelection, SelectionType.Subtractive, this.m_RectSelecting);
                    }
                    else
                    {
                        UpdateSelection(this.m_SelectionStart, this.m_CurrentSelection, SelectionType.Normal, this.m_RectSelecting);
                    }
                    current.Use();
                }
                goto Label_04D2;
            }
            current.Use();
Label_04D2:
            Handles.EndGUI();
        }
示例#9
0
        public void OnGUI()
        {
            Event current = Event.current;

            Handles.BeginGUI();
            Vector2   mousePosition  = current.mousePosition;
            int       num            = RectSelection.s_RectSelectionID;
            EventType typeForControl = current.GetTypeForControl(num);

            switch (typeForControl)
            {
            case EventType.MouseDown:
                if (HandleUtility.nearestControl == num && current.button == 0)
                {
                    GUIUtility.hotControl   = num;
                    this.m_SelectStartPoint = mousePosition;
                    this.m_SelectionStart   = Selection.objects;
                    this.m_RectSelecting    = false;
                }
                goto IL_4CB;

            case EventType.MouseUp:
                if (GUIUtility.hotControl == num && current.button == 0)
                {
                    GUIUtility.hotControl = 0;
                    if (this.m_RectSelecting)
                    {
                        EditorApplication.modifierKeysChanged = (EditorApplication.CallbackFunction)Delegate.Remove(EditorApplication.modifierKeysChanged, new EditorApplication.CallbackFunction(this.SendCommandsOnModifierKeys));
                        this.m_RectSelecting  = false;
                        this.m_SelectionStart = new UnityEngine.Object[0];
                        current.Use();
                    }
                    else
                    {
                        if (current.shift || EditorGUI.actionKey)
                        {
                            GameObject gameObject = HandleUtility.PickGameObject(current.mousePosition, false);
                            if ((!EditorGUI.actionKey) ? (Selection.activeGameObject == gameObject) : Selection.gameObjects.Contains(gameObject))
                            {
                                RectSelection.UpdateSelection(this.m_SelectionStart, gameObject, RectSelection.SelectionType.Subtractive, this.m_RectSelecting);
                            }
                            else
                            {
                                RectSelection.UpdateSelection(this.m_SelectionStart, HandleUtility.PickGameObject(current.mousePosition, true), RectSelection.SelectionType.Additive, this.m_RectSelecting);
                            }
                        }
                        else
                        {
                            GameObject newObject = SceneViewPicking.PickGameObject(current.mousePosition);
                            RectSelection.UpdateSelection(this.m_SelectionStart, newObject, RectSelection.SelectionType.Normal, this.m_RectSelecting);
                        }
                        current.Use();
                    }
                }
                goto IL_4CB;

            case EventType.MouseMove:
            case EventType.KeyDown:
            case EventType.KeyUp:
            case EventType.ScrollWheel:
IL_4C:
                if (typeForControl != EventType.ExecuteCommand)
                {
                    goto IL_4CB;
                }
                if (num == GUIUtility.hotControl && current.commandName == "ModifierKeysChanged")
                {
                    if (current.shift)
                    {
                        RectSelection.UpdateSelection(this.m_SelectionStart, this.m_CurrentSelection, RectSelection.SelectionType.Additive, this.m_RectSelecting);
                    }
                    else if (EditorGUI.actionKey)
                    {
                        RectSelection.UpdateSelection(this.m_SelectionStart, this.m_CurrentSelection, RectSelection.SelectionType.Subtractive, this.m_RectSelecting);
                    }
                    else
                    {
                        RectSelection.UpdateSelection(this.m_SelectionStart, this.m_CurrentSelection, RectSelection.SelectionType.Normal, this.m_RectSelecting);
                    }
                    current.Use();
                }
                goto IL_4CB;

            case EventType.MouseDrag:
                if (GUIUtility.hotControl == num)
                {
                    if (!this.m_RectSelecting && (mousePosition - this.m_SelectStartPoint).magnitude > 6f)
                    {
                        EditorApplication.modifierKeysChanged = (EditorApplication.CallbackFunction)Delegate.Combine(EditorApplication.modifierKeysChanged, new EditorApplication.CallbackFunction(this.SendCommandsOnModifierKeys));
                        this.m_RectSelecting    = true;
                        this.m_LastSelection    = null;
                        this.m_CurrentSelection = null;
                    }
                    if (this.m_RectSelecting)
                    {
                        this.m_SelectMousePoint = new Vector2(Mathf.Max(mousePosition.x, 0f), Mathf.Max(mousePosition.y, 0f));
                        GameObject[] array = HandleUtility.PickRectObjects(EditorGUIExt.FromToRect(this.m_SelectStartPoint, this.m_SelectMousePoint));
                        this.m_CurrentSelection = array;
                        bool flag = false;
                        if (this.m_LastSelection == null)
                        {
                            this.m_LastSelection = new Dictionary <GameObject, bool>();
                            flag = true;
                        }
                        flag |= (this.m_LastSelection.Count != array.Length);
                        if (!flag)
                        {
                            Dictionary <GameObject, bool> dictionary = new Dictionary <GameObject, bool>(array.Length);
                            GameObject[] array2 = array;
                            for (int i = 0; i < array2.Length; i++)
                            {
                                GameObject key = array2[i];
                                dictionary.Add(key, false);
                            }
                            foreach (GameObject current2 in this.m_LastSelection.Keys)
                            {
                                if (!dictionary.ContainsKey(current2))
                                {
                                    flag = true;
                                    break;
                                }
                            }
                        }
                        if (flag)
                        {
                            this.m_LastSelection = new Dictionary <GameObject, bool>(array.Length);
                            GameObject[] array3 = array;
                            for (int j = 0; j < array3.Length; j++)
                            {
                                GameObject key2 = array3[j];
                                this.m_LastSelection.Add(key2, false);
                            }
                            if (array != null)
                            {
                                if (current.shift)
                                {
                                    RectSelection.UpdateSelection(this.m_SelectionStart, array, RectSelection.SelectionType.Additive, this.m_RectSelecting);
                                }
                                else if (EditorGUI.actionKey)
                                {
                                    RectSelection.UpdateSelection(this.m_SelectionStart, array, RectSelection.SelectionType.Subtractive, this.m_RectSelecting);
                                }
                                else
                                {
                                    RectSelection.UpdateSelection(this.m_SelectionStart, array, RectSelection.SelectionType.Normal, this.m_RectSelecting);
                                }
                            }
                        }
                    }
                    current.Use();
                }
                goto IL_4CB;

            case EventType.Repaint:
                if (GUIUtility.hotControl == num && this.m_RectSelecting)
                {
                    EditorStyles.selectionRect.Draw(EditorGUIExt.FromToRect(this.m_SelectStartPoint, this.m_SelectMousePoint), GUIContent.none, false, false, false, false);
                }
                goto IL_4CB;

            case EventType.Layout:
                if (!Tools.viewToolActive)
                {
                    HandleUtility.AddDefaultControl(num);
                }
                goto IL_4CB;
            }
            goto IL_4C;
IL_4CB:
            Handles.EndGUI();
        }
示例#10
0
 internal void OnGUI(SceneView view)
 {
     if (Mathf.Min(view.position.width, view.position.height) >= 100f)
     {
         if (Event.current.type == EventType.Repaint)
         {
             Profiler.BeginSample("SceneView.AxisSelector");
         }
         this.HandleContextClick(view);
         Camera camera = view.camera;
         HandleUtility.PushCamera(camera);
         if (camera.orthographic)
         {
             camera.orthographicSize = 0.5f;
         }
         camera.cullingMask        = 0;
         camera.transform.position = (Vector3)(camera.transform.rotation * new Vector3(0f, 0f, -5f));
         camera.clearFlags         = CameraClearFlags.Nothing;
         camera.nearClipPlane      = 0.1f;
         camera.farClipPlane       = 10f;
         camera.fieldOfView        = view.m_Ortho.Fade(70f, 0f);
         SceneView.AddCursorRect(new Rect((view.position.width - 100f) + 22f, 22f, 56f, 102f), MouseCursor.Arrow);
         Handles.SetCamera(new Rect(view.position.width - 100f, 0f, 100f, 100f), camera);
         Handles.BeginGUI();
         this.DrawLabels(view);
         Handles.EndGUI();
         for (int i = 0; i < 3; i++)
         {
             Vector3 rhs = (Vector3)(kDirectionRotations[i] * Vector3.forward);
             this.dirVisible[i].target = Mathf.Abs(Vector3.Dot(camera.transform.forward, rhs)) < 0.9f;
         }
         float size = HandleUtility.GetHandleSize(Vector3.zero) * 0.2f;
         this.AxisSelectors(view, camera, size, -1f, styles.viewAxisLabelStyle);
         Color color = Color.Lerp(Handles.centerColor, Color.gray, this.faded2Dgray);
         color.a *= this.m_Visible.faded;
         if (color.a <= 0.1f)
         {
             GUI.enabled = false;
         }
         Handles.color = color;
         if (Handles.Button(this.m_CenterButtonControlID, Vector3.zero, Quaternion.identity, size * 0.8f, size, new Handles.DrawCapFunction(Handles.CubeCap)) && !view.in2DMode)
         {
             if (Event.current.clickCount == 2)
             {
                 view.FrameSelected();
             }
             else if (Event.current.shift || (Event.current.button == 2))
             {
                 this.ViewFromNiceAngle(view, true);
             }
             else
             {
                 this.ViewSetOrtho(view, !view.orthographic);
             }
         }
         this.AxisSelectors(view, camera, size, 1f, styles.viewAxisLabelStyle);
         GUI.enabled = true;
         if (!view.in2DMode && (Event.current.type == EditorGUIUtility.swipeGestureEventType))
         {
             Vector3 up;
             Event   current = Event.current;
             if (current.delta.y > 0f)
             {
                 up = Vector3.up;
             }
             else if (current.delta.y < 0f)
             {
                 up = -Vector3.up;
             }
             else if (current.delta.x < 0f)
             {
                 up = Vector3.right;
             }
             else
             {
                 up = -Vector3.right;
             }
             Vector3 direction = -up - ((Vector3)(Vector3.forward * 0.9f));
             direction = view.camera.transform.TransformDirection(direction);
             float num4 = 0f;
             int   dir  = 0;
             for (int j = 0; j < 6; j++)
             {
                 float num7 = Vector3.Dot((Vector3)(kDirectionRotations[j] * -Vector3.forward), direction);
                 if (num7 > num4)
                 {
                     num4 = num7;
                     dir  = j;
                 }
             }
             this.ViewAxisDirection(view, dir);
             Event.current.Use();
         }
         HandleUtility.PopCamera(camera);
         Handles.SetCamera(camera);
         if (Event.current.type == EventType.Repaint)
         {
             Profiler.EndSample();
         }
     }
 }
示例#11
0
        public void OnGUI()
        {
            Event current1 = Event.current;

            Handles.BeginGUI();
            Vector2   mousePosition   = current1.mousePosition;
            int       rectSelectionId = RectSelection.s_RectSelectionID;
            EventType typeForControl  = current1.GetTypeForControl(rectSelectionId);

            switch (typeForControl)
            {
            case EventType.MouseDown:
                if (HandleUtility.nearestControl == rectSelectionId && current1.button == 0)
                {
                    GUIUtility.hotControl   = rectSelectionId;
                    this.m_SelectStartPoint = mousePosition;
                    this.m_SelectionStart   = Selection.objects;
                    this.m_RectSelecting    = false;
                    break;
                }
                break;

            case EventType.MouseUp:
                if (GUIUtility.hotControl == rectSelectionId && current1.button == 0)
                {
                    GUIUtility.hotControl = 0;
                    if (this.m_RectSelecting)
                    {
                        EditorApplication.modifierKeysChanged -= new EditorApplication.CallbackFunction(this.SendCommandsOnModifierKeys);
                        this.m_RectSelecting  = false;
                        this.m_SelectionStart = new UnityEngine.Object[0];
                        current1.Use();
                        break;
                    }
                    if (current1.shift || EditorGUI.actionKey)
                    {
                        GameObject[] gameObjectArray;
                        if (current1.shift)
                        {
                            gameObjectArray = new GameObject[1]
                            {
                                Selection.activeGameObject
                            }
                        }
                        ;
                        else
                        {
                            gameObjectArray = Selection.gameObjects;
                        }
                        GameObject[] gameObjects = gameObjectArray;
                        GameObject   hovered     = SceneViewPicking.GetHovered(current1.mousePosition, gameObjects);
                        if ((UnityEngine.Object)hovered != (UnityEngine.Object)null)
                        {
                            RectSelection.UpdateSelection(this.m_SelectionStart, (UnityEngine.Object)hovered, RectSelection.SelectionType.Subtractive, this.m_RectSelecting);
                        }
                        else
                        {
                            RectSelection.UpdateSelection(this.m_SelectionStart, (UnityEngine.Object)HandleUtility.PickGameObject(current1.mousePosition, true), RectSelection.SelectionType.Additive, this.m_RectSelecting);
                        }
                    }
                    else
                    {
                        RectSelection.UpdateSelection(this.m_SelectionStart, (UnityEngine.Object)SceneViewPicking.PickGameObject(current1.mousePosition), RectSelection.SelectionType.Normal, this.m_RectSelecting);
                    }
                    current1.Use();
                    break;
                }
                break;

            case EventType.MouseDrag:
                if (GUIUtility.hotControl == rectSelectionId)
                {
                    if (!this.m_RectSelecting && (double)(mousePosition - this.m_SelectStartPoint).magnitude > 6.0)
                    {
                        EditorApplication.modifierKeysChanged += new EditorApplication.CallbackFunction(this.SendCommandsOnModifierKeys);
                        this.m_RectSelecting    = true;
                        this.m_LastSelection    = (Dictionary <GameObject, bool>)null;
                        this.m_CurrentSelection = (UnityEngine.Object[])null;
                    }
                    if (this.m_RectSelecting)
                    {
                        this.m_SelectMousePoint = new Vector2(Mathf.Max(mousePosition.x, 0.0f), Mathf.Max(mousePosition.y, 0.0f));
                        GameObject[] gameObjectArray = HandleUtility.PickRectObjects(EditorGUIExt.FromToRect(this.m_SelectStartPoint, this.m_SelectMousePoint));
                        this.m_CurrentSelection = (UnityEngine.Object[])gameObjectArray;
                        bool flag1 = false;
                        if (this.m_LastSelection == null)
                        {
                            this.m_LastSelection = new Dictionary <GameObject, bool>();
                            flag1 = true;
                        }
                        bool flag2 = flag1 | this.m_LastSelection.Count != gameObjectArray.Length;
                        if (!flag2)
                        {
                            Dictionary <GameObject, bool> dictionary = new Dictionary <GameObject, bool>(gameObjectArray.Length);
                            foreach (GameObject key in gameObjectArray)
                            {
                                dictionary.Add(key, false);
                            }
                            using (Dictionary <GameObject, bool> .KeyCollection.Enumerator enumerator = this.m_LastSelection.Keys.GetEnumerator())
                            {
                                while (enumerator.MoveNext())
                                {
                                    GameObject current2 = enumerator.Current;
                                    if (!dictionary.ContainsKey(current2))
                                    {
                                        flag2 = true;
                                        break;
                                    }
                                }
                            }
                        }
                        if (flag2)
                        {
                            this.m_LastSelection = new Dictionary <GameObject, bool>(gameObjectArray.Length);
                            foreach (GameObject key in gameObjectArray)
                            {
                                this.m_LastSelection.Add(key, false);
                            }
                            if (gameObjectArray != null)
                            {
                                if (current1.shift)
                                {
                                    RectSelection.UpdateSelection(this.m_SelectionStart, (UnityEngine.Object[])gameObjectArray, RectSelection.SelectionType.Additive, this.m_RectSelecting);
                                }
                                else if (EditorGUI.actionKey)
                                {
                                    RectSelection.UpdateSelection(this.m_SelectionStart, (UnityEngine.Object[])gameObjectArray, RectSelection.SelectionType.Subtractive, this.m_RectSelecting);
                                }
                                else
                                {
                                    RectSelection.UpdateSelection(this.m_SelectionStart, (UnityEngine.Object[])gameObjectArray, RectSelection.SelectionType.Normal, this.m_RectSelecting);
                                }
                            }
                        }
                    }
                    current1.Use();
                    break;
                }
                break;

            case EventType.Repaint:
                if (GUIUtility.hotControl == rectSelectionId && this.m_RectSelecting)
                {
                    EditorStyles.selectionRect.Draw(EditorGUIExt.FromToRect(this.m_SelectStartPoint, this.m_SelectMousePoint), GUIContent.none, false, false, false, false);
                    break;
                }
                break;

            case EventType.Layout:
                if (!Tools.viewToolActive)
                {
                    HandleUtility.AddDefaultControl(rectSelectionId);
                    break;
                }
                break;

            default:
                if (typeForControl == EventType.ExecuteCommand && rectSelectionId == GUIUtility.hotControl && current1.commandName == "ModifierKeysChanged")
                {
                    if (current1.shift)
                    {
                        RectSelection.UpdateSelection(this.m_SelectionStart, this.m_CurrentSelection, RectSelection.SelectionType.Additive, this.m_RectSelecting);
                    }
                    else if (EditorGUI.actionKey)
                    {
                        RectSelection.UpdateSelection(this.m_SelectionStart, this.m_CurrentSelection, RectSelection.SelectionType.Subtractive, this.m_RectSelecting);
                    }
                    else
                    {
                        RectSelection.UpdateSelection(this.m_SelectionStart, this.m_CurrentSelection, RectSelection.SelectionType.Normal, this.m_RectSelecting);
                    }
                    current1.Use();
                    break;
                }
                break;
            }
            Handles.EndGUI();
        }
示例#12
0
        public void OnGUI()
        {
            Event evt = Event.current;

            Handles.BeginGUI();

            Vector2 mousePos = evt.mousePosition;
            int     id       = s_RectSelectionID;

            switch (evt.GetTypeForControl(id))
            {
            case EventType.Layout:
            case EventType.MouseMove:
                if (!Tools.viewToolActive)
                {
                    HandleUtility.AddDefaultControl(id);
                }
                break;

            case EventType.MouseDown:
                if (HandleUtility.nearestControl == id && evt.button == 0)
                {
                    GUIUtility.hotControl = id;
                    m_SelectStartPoint    = mousePos;
                    m_SelectionStart      = Selection.objects;
                    m_RectSelecting       = false;
                }
                break;

            case EventType.MouseDrag:
                if (GUIUtility.hotControl == id)
                {
                    if (!m_RectSelecting && (mousePos - m_SelectStartPoint).magnitude > 6f)
                    {
                        EditorApplication.modifierKeysChanged += SendCommandsOnModifierKeys;
                        m_RectSelecting = true;
                        ActiveEditorTracker.delayFlushDirtyRebuild = true;
                        m_LastSelection    = null;
                        m_CurrentSelection = null;
                        rectSelectionStarting();
                    }
                    if (m_RectSelecting)
                    {
                        m_SelectMousePoint = new Vector2(Mathf.Max(mousePos.x, 0), Mathf.Max(mousePos.y, 0));
                        GameObject[] rectObjs = HandleUtility.PickRectObjects(EditorGUIExt.FromToRect(m_SelectStartPoint, m_SelectMousePoint));
                        m_CurrentSelection = rectObjs;
                        bool setIt = false;
                        if (m_LastSelection == null)
                        {
                            m_LastSelection = new Dictionary <GameObject, bool>();
                            setIt           = true;
                        }
                        setIt |= m_LastSelection.Count != rectObjs.Length;
                        if (!setIt)
                        {
                            Dictionary <GameObject, bool> set = new Dictionary <GameObject, bool>(rectObjs.Length);
                            foreach (GameObject g in rectObjs)
                            {
                                set.Add(g, false);
                            }
                            foreach (GameObject g in m_LastSelection.Keys)
                            {
                                if (!set.ContainsKey(g))
                                {
                                    setIt = true;
                                    break;
                                }
                            }
                        }
                        if (setIt)
                        {
                            m_LastSelection = new Dictionary <GameObject, bool>(rectObjs.Length);
                            foreach (GameObject g in rectObjs)
                            {
                                m_LastSelection.Add(g, false);
                            }
                            if (evt.shift)
                            {
                                UpdateSelection(m_SelectionStart, rectObjs, SelectionType.Additive, m_RectSelecting);
                            }
                            else if (EditorGUI.actionKey)
                            {
                                UpdateSelection(m_SelectionStart, rectObjs, SelectionType.Subtractive, m_RectSelecting);
                            }
                            else
                            {
                                UpdateSelection(m_SelectionStart, rectObjs, SelectionType.Normal, m_RectSelecting);
                            }
                        }
                    }
                    evt.Use();
                }
                break;

            case EventType.Repaint:
                if (GUIUtility.hotControl == id && m_RectSelecting)
                {
                    EditorStyles.selectionRect.Draw(EditorGUIExt.FromToRect(m_SelectStartPoint, m_SelectMousePoint), GUIContent.none, false, false, false, false);
                }
                break;

            case EventType.MouseUp:
                if (GUIUtility.hotControl == id && evt.button == 0)
                {
                    GUIUtility.hotControl = 0;
                    if (m_RectSelecting)
                    {
                        EditorApplication.modifierKeysChanged -= SendCommandsOnModifierKeys;
                        m_RectSelecting = false;
                        ActiveEditorTracker.delayFlushDirtyRebuild = false;
                        ActiveEditorTracker.RebuildAllIfNecessary();
                        m_SelectionStart = new Object[0];
                        rectSelectionFinished();
                        evt.Use();
                    }
                    else
                    {
                        if (evt.shift || EditorGUI.actionKey)
                        {
                            // For shift, we check if EXACTLY the active GO is hovered by mouse and then subtract. Otherwise additive.
                            // For control/cmd, we check if ANY of the selected GO is hovered by mouse and then subtract. Otherwise additive.
                            // Control/cmd takes priority over shift.
                            GameObject hovered = HandleUtility.PickGameObject(evt.mousePosition, false);

                            var handledIt = false;
                            // shift-click deselects only if the active GO is exactly what we clicked on
                            if (!EditorGUI.actionKey && Selection.activeGameObject == hovered)
                            {
                                UpdateSelection(m_SelectionStart, hovered, SelectionType.Subtractive, m_RectSelecting);
                                handledIt = true;
                            }

                            // ctrl-click deselects everything up to prefab root, that is already selected
                            if (!handledIt && EditorGUI.actionKey)
                            {
                                var selectedGos  = Selection.gameObjects;
                                var hoveredRoot  = HandleUtility.FindSelectionBaseForPicking(hovered);
                                var deselectList = new List <Object>();
                                while (hovered != null)
                                {
                                    if (selectedGos.Contains(hovered))
                                    {
                                        deselectList.Add(hovered);
                                    }
                                    if (hovered == hoveredRoot)
                                    {
                                        break;
                                    }
                                    var parent = hovered.transform.parent;
                                    if (parent)
                                    {
                                        hovered = parent.gameObject;
                                    }
                                    else
                                    {
                                        break;
                                    }
                                }
                                if (deselectList.Any())
                                {
                                    UpdateSelection(m_SelectionStart, deselectList.ToArray(), SelectionType.Subtractive, m_RectSelecting);
                                    handledIt = true;
                                }
                            }

                            // we did not deselect anything, so add the new thing into selection instead
                            if (!handledIt)
                            {
                                UpdateSelection(m_SelectionStart, HandleUtility.PickGameObject(evt.mousePosition, true), SelectionType.Additive, m_RectSelecting);
                            }
                        }
                        else     // With no modifier keys, we do the "cycle through overlapped" picking logic in SceneViewPicking.cs
                        {
                            GameObject picked = SceneViewPicking.PickGameObject(evt.mousePosition);
                            UpdateSelection(m_SelectionStart, picked, SelectionType.Normal, m_RectSelecting);
                        }

                        evt.Use();
                    }
                }
                break;

            case EventType.ExecuteCommand:
                if (id == GUIUtility.hotControl && evt.commandName == EventCommandNames.ModifierKeysChanged)
                {
                    if (evt.shift)
                    {
                        UpdateSelection(m_SelectionStart, m_CurrentSelection, SelectionType.Additive, m_RectSelecting);
                    }
                    else if (EditorGUI.actionKey)
                    {
                        UpdateSelection(m_SelectionStart, m_CurrentSelection, SelectionType.Subtractive, m_RectSelecting);
                    }
                    else
                    {
                        UpdateSelection(m_SelectionStart, m_CurrentSelection, SelectionType.Normal, m_RectSelecting);
                    }
                    evt.Use();
                }
                break;
            }

            Handles.EndGUI();
        }
示例#13
0
        internal void OnGUI(SceneView view)
        {
            if ((double)Mathf.Min(view.position.width, view.position.height) < 100.0)
            {
                return;
            }
            if (Event.current.type == EventType.Repaint)
            {
                Profiler.BeginSample("SceneView.AxisSelector");
            }
            this.HandleContextClick(view);
            Camera camera = view.camera;

            HandleUtility.PushCamera(camera);
            if (camera.orthographic)
            {
                camera.orthographicSize = 0.5f;
            }
            camera.cullingMask        = 0;
            camera.transform.position = camera.transform.rotation * new Vector3(0.0f, 0.0f, -5f);
            camera.clearFlags         = CameraClearFlags.Nothing;
            camera.nearClipPlane      = 0.1f;
            camera.farClipPlane       = 10f;
            camera.fieldOfView        = view.m_Ortho.Fade(70f, 0.0f);
            SceneView.AddCursorRect(new Rect((float)((double)view.position.width - 100.0 + 22.0), 22f, 56f, 102f), MouseCursor.Arrow);
            Handles.SetCamera(new Rect(view.position.width - 100f, 0.0f, 100f, 100f), camera);
            Handles.BeginGUI();
            this.DrawLabels(view);
            Handles.EndGUI();
            for (int index = 0; index < 3; ++index)
            {
                Vector3 rhs = SceneViewRotation.kDirectionRotations[index] * Vector3.forward;
                this.dirVisible[index].target = (double)Mathf.Abs(Vector3.Dot(camera.transform.forward, rhs)) < 0.899999976158142;
            }
            float num1 = HandleUtility.GetHandleSize(Vector3.zero) * 0.2f;

            this.AxisSelectors(view, camera, num1, -1f, SceneViewRotation.styles.viewAxisLabelStyle);
            Color color = Color.Lerp(Handles.centerColor, Color.gray, this.faded2Dgray);

            color.a *= this.m_Visible.faded;
            if ((double)color.a <= 0.100000001490116)
            {
                GUI.enabled = false;
            }
            Handles.color = color;
            if (Handles.Button(this.m_CenterButtonControlID, Vector3.zero, Quaternion.identity, num1 * 0.8f, num1, new Handles.DrawCapFunction(Handles.CubeCap)) && !view.in2DMode)
            {
                if (Event.current.clickCount == 2)
                {
                    view.FrameSelected();
                }
                else if (Event.current.shift || Event.current.button == 2)
                {
                    this.ViewFromNiceAngle(view, true);
                }
                else
                {
                    this.ViewSetOrtho(view, !view.orthographic);
                }
            }
            this.AxisSelectors(view, camera, num1, 1f, SceneViewRotation.styles.viewAxisLabelStyle);
            GUI.enabled = true;
            if (!view.in2DMode && Event.current.type == EditorGUIUtility.swipeGestureEventType)
            {
                Event   current   = Event.current;
                Vector3 direction = -((double)current.delta.y <= 0.0 ? ((double)current.delta.y >= 0.0 ? ((double)current.delta.x >= 0.0 ? -Vector3.right : Vector3.right) : -Vector3.up) : Vector3.up) - Vector3.forward * 0.9f;
                Vector3 rhs       = view.camera.transform.TransformDirection(direction);
                float   num2      = 0.0f;
                int     dir       = 0;
                for (int index = 0; index < 6; ++index)
                {
                    float num3 = Vector3.Dot(SceneViewRotation.kDirectionRotations[index] * -Vector3.forward, rhs);
                    if ((double)num3 > (double)num2)
                    {
                        num2 = num3;
                        dir  = index;
                    }
                }
                this.ViewAxisDirection(view, dir);
                Event.current.Use();
            }
            HandleUtility.PopCamera(camera);
            Handles.SetCamera(camera);
            if (Event.current.type != EventType.Repaint)
            {
                return;
            }
            Profiler.EndSample();
        }
示例#14
0
        internal void OnGUI(SceneView view)
        {
            int num = Mathf.Min(Screen.width, Screen.height);

            if (num < 100)
            {
                return;
            }
            if (Event.current.type == EventType.Repaint)
            {
                Profiler.BeginSample("SceneView.AxisSelector");
            }
            Camera camera = view.camera;

            HandleUtility.PushCamera(camera);
            if (camera.orthographic)
            {
                camera.orthographicSize = 0.5f;
            }
            camera.cullingMask        = 0;
            camera.transform.position = camera.transform.rotation * new Vector3(0f, 0f, -5f);
            camera.clearFlags         = CameraClearFlags.Nothing;
            camera.nearClipPlane      = 0.1f;
            camera.farClipPlane       = 10f;
            camera.fieldOfView        = view.m_Ortho.Fade(70f, 0f);
            SceneView.AddCursorRect(new Rect((float)(Screen.width - 100 + 22), 22f, 56f, 102f), MouseCursor.Arrow);
            Handles.SetCamera(new Rect((float)(Screen.width - 100), 0f, 100f, 100f), camera);
            Handles.BeginGUI();
            Rect rect = new Rect((float)(Screen.width - 100 + 17), 92f, 66f, 16f);

            if (!view.in2DMode && GUI.Button(rect, string.Empty, SceneViewRotation.styles.viewLabelStyleLeftAligned))
            {
                if (Event.current.button == 1)
                {
                    this.DisplayContextMenu(rect, view);
                }
                else
                {
                    this.ViewSetOrtho(view, !view.orthographic);
                }
            }
            int   num2     = 8;
            Rect  position = rect;
            float num3     = 0f;
            float num4     = 0f;

            for (int i = 0; i < SceneViewRotation.kDirNames.Length; i++)
            {
                if (i != num2)
                {
                    num4 += this.dirNameVisible[i].faded;
                    if (this.dirNameVisible[i].faded > 0f)
                    {
                        num3 += SceneViewRotation.styles.viewLabelStyleLeftAligned.CalcSize(EditorGUIUtility.TempContent(SceneViewRotation.kDirNames[i])).x *this.dirNameVisible[i].faded;
                    }
                }
            }
            if (num4 > 0f)
            {
                num3 /= num4;
            }
            position.x += 37f - num3 * 0.5f;
            position.x  = (float)Mathf.RoundToInt(position.x);
            int num5 = 0;

            while (num5 < this.dirNameVisible.Length && num5 < SceneViewRotation.kDirNames.Length)
            {
                if (num5 != num2)
                {
                    Color centerColor = Handles.centerColor;
                    centerColor.a *= this.dirNameVisible[num5].faded;
                    if (centerColor.a > 0f)
                    {
                        GUI.color = centerColor;
                        GUI.Label(position, SceneViewRotation.kDirNames[num5], SceneViewRotation.styles.viewLabelStyleLeftAligned);
                    }
                }
                num5++;
            }
            Color centerColor2 = Handles.centerColor;

            centerColor2.a *= this.faded2Dgray * this.m_Visible.faded;
            if (centerColor2.a > 0f)
            {
                GUI.color = centerColor2;
                GUI.Label(rect, SceneViewRotation.kDirNames[num2], SceneViewRotation.styles.viewLabelStyleCentered);
            }
            if (this.faded2Dgray < 1f)
            {
                this.DrawIsoStatusSymbol(new Vector3(position.x - 8f, position.y + 8.5f, 0f), view, 1f - this.faded2Dgray);
            }
            Handles.EndGUI();
            for (int j = 0; j < 3; j++)
            {
                Vector3 rhs = SceneViewRotation.kDirectionRotations[j] * Vector3.forward;
                this.dirVisible[j].target = (Mathf.Abs(Vector3.Dot(camera.transform.forward, rhs)) < 0.9f);
            }
            float num6 = HandleUtility.GetHandleSize(Vector3.zero) * 0.2f;

            this.AxisSelectors(view, camera, num6, -1f, SceneViewRotation.styles.viewAxisLabelStyle);
            Color color = Handles.centerColor;

            color    = Color.Lerp(color, Color.gray, this.faded2Dgray);
            color.a *= this.m_Visible.faded;
            if (color.a <= 0.1f)
            {
                GUI.enabled = false;
            }
            Handles.color = color;
            if (Handles.Button(Vector3.zero, Quaternion.identity, num6 * 0.8f, num6, new Handles.DrawCapFunction(Handles.CubeCap)) && !view.in2DMode)
            {
                if (Event.current.clickCount == 2)
                {
                    view.FrameSelected();
                }
                else
                {
                    if (Event.current.shift || Event.current.button == 2)
                    {
                        this.ViewFromNiceAngle(view, true);
                    }
                    else
                    {
                        this.ViewSetOrtho(view, !view.orthographic);
                    }
                }
            }
            this.AxisSelectors(view, camera, num6, 1f, SceneViewRotation.styles.viewAxisLabelStyle);
            GUI.enabled = true;
            if (!view.in2DMode && Event.current.type == EditorGUIUtility.swipeGestureEventType)
            {
                Event   current = Event.current;
                Vector3 a;
                if (current.delta.y > 0f)
                {
                    a = Vector3.up;
                }
                else
                {
                    if (current.delta.y < 0f)
                    {
                        a = -Vector3.up;
                    }
                    else
                    {
                        if (current.delta.x < 0f)
                        {
                            a = Vector3.right;
                        }
                        else
                        {
                            a = -Vector3.right;
                        }
                    }
                }
                Vector3 vector = -a - Vector3.forward * 0.9f;
                vector = view.camera.transform.TransformDirection(vector);
                float num7 = 0f;
                int   dir  = 0;
                for (int k = 0; k < 6; k++)
                {
                    float num8 = Vector3.Dot(SceneViewRotation.kDirectionRotations[k] * -Vector3.forward, vector);
                    if (num8 > num7)
                    {
                        num7 = num8;
                        dir  = k;
                    }
                }
                this.ViewAxisDirection(view, dir);
                Event.current.Use();
            }
            HandleUtility.PopCamera(camera);
            Handles.SetCamera(camera);
            if (Event.current.type == EventType.Repaint)
            {
                Profiler.EndSample();
            }
        }