예제 #1
0
        public override void Update(CameraState cameraState, Camera cam, EditorWindow window)
        {
            Event evt = Event.current;

            if (evt.type == EventType.MouseUp)
            {
                m_CurrentViewTool = ViewTool.None;
            }

            if (evt.type == EventType.MouseDown)
            {
                int button = evt.button;

                bool controlKeyOnMac = (evt.control && Application.platform == RuntimePlatform.OSXEditor);

                var rightMouseButton = false;
                if (button == 2)
                {
                    m_CurrentViewTool = ViewTool.Pan;
                }
                else if ((button <= 0 && controlKeyOnMac) ||
                         (button == 1 && evt.alt))
                {
                    m_CurrentViewTool = ViewTool.Zoom;

                    m_StartZoom      = cameraState.viewSize.value;
                    m_ZoomSpeed      = Mathf.Max(Mathf.Abs(m_StartZoom), .3f);
                    m_TotalMotion    = 0;
                    rightMouseButton = button == 1;
                }
                else if (button <= 0)
                {
                    m_CurrentViewTool = ViewTool.Orbit;
                }
                else if (button == 1 && !evt.alt)
                {
                    m_CurrentViewTool = ViewTool.FPS;
                    rightMouseButton  = true;
                }

                // see also SceneView.HandleClickAndDragToFocus()
                if (rightMouseButton && Application.platform == RuntimePlatform.OSXEditor)
                {
                    window.Focus();
                }
            }

            var id = GUIUtility.GetControlID(FocusType.Passive);

            using (var inputSamplingScope = new CameraFlyModeContext.InputSamplingScope(m_CameraFlyModeContext, m_CurrentViewTool, id))
            {
                if (inputSamplingScope.inputVectorChanged)
                {
                    m_FlySpeed = 0;
                }
                m_Motion = inputSamplingScope.currentInputVector;
            }

            switch (evt.type)
            {
            case EventType.ScrollWheel: HandleCameraScrollWheel(cameraState); break;

            case EventType.MouseUp:     HandleCameraMouseUp(); break;

            case EventType.MouseDrag:   HandleCameraMouseDrag(cameraState, cam); break;

            case EventType.KeyDown:     HandleCameraKeyDown(); break;

            case EventType.Layout:
            {
                Vector3 motion = GetMovementDirection();
                if (motion.sqrMagnitude != 0)
                {
                    cameraState.pivot.value = cameraState.pivot.value + cameraState.rotation.value * motion;
                }
            }
            break;
            }
        }
예제 #2
0
        public static void DoViewTool(SceneView view)
        {
            Event evt = Event.current;

            // Ensure we always call the GetControlID the same number of times
            int id = s_ViewToolID;

            EventType eventType = evt.GetTypeForControl(id);

            // In FPS mode we update the pivot for Orbit mode (see below and inside HandleMouseDrag)
            if (view && Tools.s_LockedViewTool == ViewTool.FPS)
            {
                view.FixNegativeSize();
            }

            using (var inputSamplingScope = new CameraFlyModeContext.InputSamplingScope(s_CameraFlyModeContext, Tools.s_LockedViewTool, id, view.orthographic))
            {
                if (inputSamplingScope.currentlyMoving)
                {
                    view.viewIsLockedToObject = false;
                }
                if (inputSamplingScope.inputVectorChanged)
                {
                    s_FlySpeed = 0;
                }
                s_Motion = inputSamplingScope.currentInputVector;
            }

            switch (eventType)
            {
            case EventType.ScrollWheel:     HandleScrollWheel(view, view.in2DMode == evt.alt); break;     // Default to zooming to mouse position in 2D mode without alt

            case EventType.MouseDown:       HandleMouseDown(view, id, evt.button); break;

            case EventType.MouseUp:         HandleMouseUp(view, id, evt.button, evt.clickCount); break;

            case EventType.MouseDrag:       HandleMouseDrag(view, id); break;

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

            case EventType.Layout:
            {
                Vector3 motion = GetMovementDirection();
                // This seems to be the best way to have a continuously repeating event
                if (GUIUtility.hotControl == id && motion.sqrMagnitude != 0)
                {
                    view.pivot = view.pivot + view.rotation * motion;
                    view.Repaint();
                }
            }
            break;

            case EventType.Used:
                // since FPS tool acts on right click, nothing prevents a regular control
                // from taking the control ID on left click, so some cleanup is necessary
                // to not get locked into FPS mode (case 777346)
                if (GUIUtility.hotControl != id && s_CurrentState != MotionState.kInactive)
                {
                    ResetDragState();
                }
                break;
            }
        }
        public static void DoViewTool(SceneView view)
        {
            Init();

            s_CurrentSceneView = view;

            // If a SceneView is currently taking input, don't let other views accept input
            if (s_ActiveSceneView != null && s_CurrentSceneView != s_ActiveSceneView)
            {
                return;
            }

            Event evt = Event.current;

            // Ensure we always call the GetControlID the same number of times
            int id = s_ViewToolID;

            EventType eventType = evt.GetTypeForControl(id);

            // In FPS mode we update the pivot for Orbit mode (see below and inside HandleMouseDrag)
            if (view && Tools.s_LockedViewTool == ViewTool.FPS)
            {
                view.FixNegativeSize();
            }

            using (var inputSamplingScope = new CameraFlyModeContext.InputSamplingScope(s_CameraFlyModeContext, Tools.s_LockedViewTool, id, view, view.orthographic))
            {
                if (inputSamplingScope.currentlyMoving)
                {
                    view.viewIsLockedToObject = false;
                }

                s_Motion = inputSamplingScope.currentInputVector;
            }

            switch (eventType)
            {
            case EventType.ScrollWheel: HandleScrollWheel(view, view.in2DMode == evt.alt); break;     // Default to zooming to mouse position in 2D mode without alt

            case EventType.MouseDown: HandleMouseDown(view, id, evt.button); break;

            case EventType.KeyUp:
            case EventType.MouseUp: HandleMouseUp(view, id, evt.button, evt.clickCount); break;

            case EventType.KeyDown: HandleKeyDown(view, id); break;

            case EventType.MouseMove:
            case EventType.MouseDrag: HandleMouseDrag(view, id); break;

            case EventType.Layout:
                if (GUIUtility.hotControl == id || s_FlySpeed.isAnimating || s_Moving)
                {
                    view.pivot = view.pivot + view.rotation * GetMovementDirection();
                    view.Repaint();
                }
                break;

            case EventType.Used:
                // since FPS tool acts on right click, nothing prevents a regular control
                // from taking the control ID on left click, so some cleanup is necessary
                // to not get locked into FPS mode (case 777346)
                if (GUIUtility.hotControl != id && s_CurrentState != MotionState.kInactive)
                {
                    ResetDragState();
                }
                break;
            }

            if (s_CurrentState == MotionState.kDragging && evt.type == EventType.Repaint)
            {
                HandleMouseDrag(view, id);
            }

            if (shortcutKey != KeyCode.None)
            {
                GUIUtility.hotControl = s_ViewToolID;
            }
        }