BeginGUI() 공개 정적인 메소드

Begin a 2D GUI block inside the 3D handle GUI.

public static BeginGUI ( ) : void
리턴 void
예제 #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
        // 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();
            }
        }