Example #1
0
            public void Update()
            {
                if (!m_State.isDragging)
                {
                    PickingHit hit;
                    ScreenPickingUtility.GetHovered(
                        handles,
                        Input.mousePosition,
                        camera,
                        k_PickingDistance,
                        out hit);

                    m_State.SetHovered(GetHandle(hit.target));
                    m_State.Update(HandleUtility.ProjectScreenPositionOnHandle(
                                       m_State.activeHandle,
                                       Input.mousePosition,
                                       camera));
                }
                else
                {
                    m_State.Update(HandleUtility.ProjectScreenPositionOnHandle(
                                       m_State.activeHandle,
                                       Input.mousePosition,
                                       camera));
                }

                if (Input.GetMouseButtonDown(0))
                {
                    m_State.StartDrag(HandleUtility.ProjectScreenPositionOnHandle(
                                          m_State.activeHandle,
                                          Input.mousePosition,
                                          camera));
                }
                else if (Input.GetMouseButtonUp(0))
                {
                    m_State.StopDrag();
                }
            }
        internal void OnGUI(EditorWindow window, Rect rect, Event evt)
        {
            if (window == null)
            {
                return;
            }

            Assert.IsNotNull(window, "Cannot draw a Editor Window Context with a null window.");
            Assert.IsNotNull(evt, "IMGUIController.OnGUI cannot be called outside an OnGUI method");

            camera = Camera.current;

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

            switch (evt.GetTypeForControl(id))
            {
            case EventType.Layout:
                ScreenPickingUtility.GetHovered(
                    handles,
                    GetMousePosition(evt, rect),
                    camera,
                    k_PickingDistance,
                    out s_Hit);

                HandleUtility.AddControl(id, s_Hit.distance);
                break;

            case EventType.MouseMove:
                //Verify that no unity control is currently considered nearest.
                //We also set hovered if nearest control is 0 because the unity picking distance might not be the same as this context.
                if (HandleUtility.nearestControl == id || HandleUtility.nearestControl == 0)
                {
                    m_State.SetHovered(GetHandle(s_Hit.target));
                }
                else
                {
                    m_State.SetHovered(null);
                }

                if (m_State.activeHandle)
                {
                    m_State.Update(MARSHandles.HandleUtility.ProjectScreenPositionOnHandle(
                                       m_State.activeHandle,
                                       GetMousePosition(evt, rect),
                                       camera));

                    window.Repaint();
                }
                break;

            case EventType.MouseDown:
                if (evt.button != 0)
                {
                    break;
                }

                if (m_State.StartDrag(MARSHandles.HandleUtility.ProjectScreenPositionOnHandle(
                                          m_State.activeHandle,
                                          GetMousePosition(evt, rect),
                                          camera)))
                {
                    GUIUtility.hotControl = id;
                    evt.Use();
                }
                break;

            case EventType.MouseUp:
                if (m_State.StopDrag())
                {
                    GUIUtility.hotControl = 0;
                    evt.Use();
                }
                break;

            case EventType.MouseDrag:
                if (GUIUtility.hotControl == id)
                {
                    m_State.Update(MARSHandles.HandleUtility.ProjectScreenPositionOnHandle(
                                       m_State.activeHandle,
                                       GetMousePosition(evt, rect),
                                       camera));

                    ToolsUtility.InvalidateHandlePosition();
                    evt.Use();
                }
                break;

            case EventType.Repaint:
                Repaint(rect);
                break;
            }
        }
Example #3
0
 public void Update()
 {
     m_Interaction.Update(new Vector3(0, 0, 100));
 }