GetMovementDirection() private static method

private static GetMovementDirection ( ) : Vector3
return Vector3
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();
            }
        }
Beispiel #2
0
        public static void DoViewTool(SceneView view)
        {
            Event     current        = Event.current;
            int       num            = SceneViewMotion.s_ViewToolID;
            EventType typeForControl = current.GetTypeForControl(num);

            if (view && Tools.s_LockedViewTool == ViewTool.FPS)
            {
                view.FixNegativeSize();
            }
            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(view, num);
                break;

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

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

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

            case EventType.Layout:
            {
                Vector3 movementDirection = SceneViewMotion.GetMovementDirection();
                if (GUIUtility.hotControl == num && movementDirection.sqrMagnitude != 0f)
                {
                    view.pivot += view.rotation * movementDirection;
                    view.Repaint();
                }
                break;
            }

            case EventType.Used:
                if (GUIUtility.hotControl != num && SceneViewMotion.s_CurrentState != SceneViewMotion.MotionState.kInactive)
                {
                    SceneViewMotion.ResetDragState();
                }
                break;
            }
        }
        public static void DoViewTool(SceneView view)
        {
            Event     current        = Event.current;
            int       viewToolId     = SceneViewMotion.s_ViewToolID;
            EventType typeForControl = current.GetTypeForControl(viewToolId);

            if ((bool)((Object)view) && Tools.s_LockedViewTool == ViewTool.FPS)
            {
                view.FixNegativeSize();
            }
            switch (typeForControl)
            {
            case EventType.MouseDown:
                SceneViewMotion.HandleMouseDown(view, viewToolId, current.button);
                break;

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

            case EventType.MouseDrag:
                SceneViewMotion.HandleMouseDrag(view, viewToolId);
                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 != viewToolId || (double)movementDirection.sqrMagnitude == 0.0)
                {
                    break;
                }
                view.pivot = view.pivot + view.rotation * movementDirection;
                view.Repaint();
                break;
            }
        }
Beispiel #4
0
        public static void ArrowKeys(SceneView sv)
        {
            Event current   = Event.current;
            int   controlID = GUIUtility.GetControlID(FocusType.Passive);

            if (GUIUtility.hotControl == 0 || GUIUtility.hotControl == controlID)
            {
                if (!EditorGUI.actionKey)
                {
                    EventType typeForControl = current.GetTypeForControl(controlID);
                    if (typeForControl != EventType.KeyDown)
                    {
                        if (typeForControl != EventType.KeyUp)
                        {
                            if (typeForControl == EventType.Layout)
                            {
                                if (GUIUtility.hotControl == controlID)
                                {
                                    Vector3 forward;
                                    if (!sv.m_Ortho.value)
                                    {
                                        forward   = Camera.current.transform.forward + Camera.current.transform.up * 0.3f;
                                        forward.y = 0f;
                                        forward.Normalize();
                                    }
                                    else
                                    {
                                        forward = Camera.current.transform.forward;
                                    }
                                    Vector3 movementDirection = SceneViewMotion.GetMovementDirection();
                                    sv.LookAtDirect(sv.pivot + Quaternion.LookRotation(forward) * movementDirection, sv.rotation);
                                    if (SceneViewMotion.s_Motion.sqrMagnitude == 0f)
                                    {
                                        sv.pivot = sv.pivot;
                                        SceneViewMotion.s_FlySpeed = 0f;
                                        GUIUtility.hotControl      = 0;
                                    }
                                    else
                                    {
                                        sv.Repaint();
                                    }
                                }
                            }
                        }
                        else if (GUIUtility.hotControl == controlID)
                        {
                            switch (current.keyCode)
                            {
                            case KeyCode.UpArrow:
                            case KeyCode.DownArrow:
                                SceneViewMotion.s_Motion.z = 0f;
                                SceneViewMotion.s_Motion.y = 0f;
                                current.Use();
                                break;

                            case KeyCode.RightArrow:
                            case KeyCode.LeftArrow:
                                SceneViewMotion.s_Motion.x = 0f;
                                current.Use();
                                break;
                            }
                        }
                    }
                    else
                    {
                        switch (current.keyCode)
                        {
                        case KeyCode.UpArrow:
                            sv.viewIsLockedToObject = false;
                            if (sv.m_Ortho.value)
                            {
                                SceneViewMotion.s_Motion.y = 1f;
                            }
                            else
                            {
                                SceneViewMotion.s_Motion.z = 1f;
                            }
                            GUIUtility.hotControl = controlID;
                            current.Use();
                            break;

                        case KeyCode.DownArrow:
                            sv.viewIsLockedToObject = false;
                            if (sv.m_Ortho.value)
                            {
                                SceneViewMotion.s_Motion.y = -1f;
                            }
                            else
                            {
                                SceneViewMotion.s_Motion.z = -1f;
                            }
                            GUIUtility.hotControl = controlID;
                            current.Use();
                            break;

                        case KeyCode.RightArrow:
                            sv.viewIsLockedToObject    = false;
                            SceneViewMotion.s_Motion.x = 1f;
                            GUIUtility.hotControl      = controlID;
                            current.Use();
                            break;

                        case KeyCode.LeftArrow:
                            sv.viewIsLockedToObject    = false;
                            SceneViewMotion.s_Motion.x = -1f;
                            GUIUtility.hotControl      = controlID;
                            current.Use();
                            break;
                        }
                    }
                }
            }
        }