UnityEditor.SceneViewMotion.HandleMouseDrag C# (CSharp) Method

HandleMouseDrag() private static method

private static HandleMouseDrag ( SceneView view, int id ) : void
view SceneView
id int
return void
        private static void HandleMouseDrag(SceneView view, int id)
        {
            s_Dragged = true;
            if (GUIUtility.hotControl != id)
            {
                return;
            }
            Event current = Event.current;
            switch (Tools.s_LockedViewTool)
            {
                case ViewTool.Orbit:
                    if (!view.in2DMode && !view.isRotationLocked)
                    {
                        OrbitCameraBehavior(view);
                        view.svRot.UpdateGizmoLabel(view, (Vector3) (view.rotation * Vector3.forward), view.m_Ortho.target);
                    }
                    goto Label_031E;

                case ViewTool.Pan:
                {
                    view.viewIsLockedToObject = false;
                    view.FixNegativeSize();
                    Vector3 position = view.camera.WorldToScreenPoint(view.pivot) + new Vector3(-Event.current.delta.x, Event.current.delta.y, 0f);
                    Vector3 vector7 = Camera.current.ScreenToWorldPoint(position) - view.pivot;
                    vector7 = (Vector3) (vector7 * EditorGUIUtility.pixelsPerPoint);
                    if (current.shift)
                    {
                        vector7 = (Vector3) (vector7 * 4f);
                    }
                    view.pivot += vector7;
                    goto Label_031E;
                }
                case ViewTool.Zoom:
                {
                    float num = HandleUtility.niceMouseDeltaZoom * (!current.shift ? ((float) 3) : ((float) 9));
                    if (!view.orthographic)
                    {
                        s_TotalMotion += num;
                        if (s_TotalMotion < 0f)
                        {
                            view.size = s_StartZoom * (1f + (s_TotalMotion * 0.001f));
                        }
                        else
                        {
                            view.size += (num * s_ZoomSpeed) * 0.003f;
                        }
                    }
                    else
                    {
                        view.size = Mathf.Max((float) 0.0001f, (float) (view.size * (1f + (num * 0.001f))));
                    }
                    goto Label_031E;
                }
                case ViewTool.FPS:
                {
                    if (view.in2DMode || view.isRotationLocked)
                    {
                        goto Label_031E;
                    }
                    if (view.orthographic)
                    {
                        OrbitCameraBehavior(view);
                        break;
                    }
                    view.viewIsLockedToObject = false;
                    Vector3 vector = view.pivot - ((Vector3) ((view.rotation * Vector3.forward) * view.cameraDistance));
                    Quaternion rotation = view.rotation;
                    rotation = Quaternion.AngleAxis((current.delta.y * 0.003f) * 57.29578f, (Vector3) (rotation * Vector3.right)) * rotation;
                    rotation = Quaternion.AngleAxis((current.delta.x * 0.003f) * 57.29578f, Vector3.up) * rotation;
                    view.rotation = rotation;
                    view.pivot = vector + ((Vector3) ((rotation * Vector3.forward) * view.cameraDistance));
                    break;
                }
                default:
                    Debug.Log("Enum value Tools.s_LockViewTool not handled");
                    goto Label_031E;
            }
            view.svRot.UpdateGizmoLabel(view, (Vector3) (view.rotation * Vector3.forward), view.m_Ortho.target);
        Label_031E:
            current.Use();
        }

Usage Example

Beispiel #1
0
        public static void DoViewTool(Transform cameraTransform, SceneView view)
        {
            Event     current        = Event.current;
            int       num            = SceneViewMotion.s_ViewToolID;
            EventType typeForControl = current.GetTypeForControl(num);
            float     d = 0f;

            if (view && Tools.s_LockedViewTool == ViewTool.FPS)
            {
                view.FixNegativeSize();
                d = (view.pivot - cameraTransform.position).magnitude;
            }
            switch (typeForControl)
            {
            case EventType.MouseDown:
                SceneViewMotion.HandleMouseDown(view, num, current.button);
                break;

            case EventType.MouseUp:
                SceneViewMotion.HandleMouseUp(view, num, current.button, current.clickCount);
                break;

            case EventType.MouseDrag:
                SceneViewMotion.HandleMouseDrag(cameraTransform, view, num);
                break;

            case EventType.KeyDown:
                SceneViewMotion.HandleKeyDown(view);
                break;

            case EventType.KeyUp:
                SceneViewMotion.HandleKeyUp();
                break;

            case EventType.ScrollWheel:
                SceneViewMotion.HandleScrollWheel(view, !current.alt);
                break;

            case EventType.Layout:
            {
                Vector3 movementDirection = SceneViewMotion.GetMovementDirection();
                if (GUIUtility.hotControl == num && movementDirection.sqrMagnitude != 0f)
                {
                    cameraTransform.position += cameraTransform.rotation * movementDirection;
                }
                break;
            }
            }
            if (view && Tools.s_LockedViewTool == ViewTool.FPS)
            {
                if (!view.orthographic)
                {
                    view.rotation = cameraTransform.rotation;
                }
                view.pivot = cameraTransform.position + cameraTransform.forward * d;
                view.Repaint();
            }
        }
All Usage Examples Of UnityEditor.SceneViewMotion::HandleMouseDrag