コード例 #1
0
    public override string ToString()
    {
        VRCursorController cursor     = VRCursorController.GetInstance();
        Vector3            position   = cursor.GetCursorPosition();
        StringBuilder      outputText = new StringBuilder();

        outputText.AppendFormat("Cursor Position: ({0}, {1}, {2})\n", position.x, position.y, position.z);
        outputText.AppendFormat("Cursor Pressed: {0}\n", cursor.GetCursorPressed() ? "yes" : "no");
        outputText.AppendFormat("Cursor Scroll Amount: {0}\n", cursor.GetCursorScroll());
        outputText.AppendFormat("Raycast Hit: {0}\n", m_guiRaycastHit ? "yes" : "no");
        outputText.AppendFormat("Hover Object: {0}\n",
                                m_currentHoverObject != null ? m_currentHoverObject.name : "(null)");
        outputText.AppendFormat("Pressed Object: {0}\n",
                                m_currentPressedObject != null ? m_currentPressedObject.name : "(null)");
        outputText.AppendFormat("Dragging Object: {0}\n",
                                m_currentDraggingObject != null ? m_currentDraggingObject.name : "(null)");

        return(outputText.ToString());
    }
コード例 #2
0
    // Process is called by UI system to process events
    public override void Process()
    {
        VRCursorController cursor = VRCursorController.GetInstance();

        // send update events if there is a selected object - this is important for InputField to receive keyboard events
        SendUpdateEventToSelectedObject();

        // see if there is a UI element that is currently being looked at
        PointerEventData lookData = GetLookPointerEventData();

        m_currentHoverObject = lookData.pointerCurrentRaycast.gameObject;

        // handle enter and exit events (highlight)
        // using the function that is already defined in BaseInputModule
        HandlePointerExitAndEnter(lookData, m_currentHoverObject);

        // Cursor Pressed Handling
        if (cursor.GetCursorPressed())
        {
            ClearSelection();

            lookData.pressPosition       = lookData.position;
            lookData.pointerPressRaycast = lookData.pointerCurrentRaycast;
            lookData.pointerPress        = null;

            if (m_currentHoverObject != null)
            {
                GameObject newPressed = null;
                m_currentPressedObject = m_currentHoverObject;

                newPressed = ExecuteEvents.ExecuteHierarchy(m_currentPressedObject, lookData, ExecuteEvents.pointerDownHandler);

                if (newPressed == null)
                {
                    // some UI elements might only have click handler and not pointer down handler
                    newPressed = ExecuteEvents.ExecuteHierarchy(m_currentPressedObject, lookData, ExecuteEvents.pointerClickHandler);

                    if (newPressed != null)
                    {
                        m_currentPressedObject = newPressed;
                    }
                }
                else
                {
                    m_currentPressedObject = newPressed;

                    // we want to do click on button down at same time, unlike regular mouse processing
                    // which does click when mouse goes up over same object it went down on
                    // reason to do this is head tracking might be jittery and this makes it easier to click buttons
                    ExecuteEvents.Execute(newPressed, lookData, ExecuteEvents.pointerClickHandler);
                }

                if (newPressed != null)
                {
                    lookData.pointerPress  = newPressed;
                    m_currentPressedObject = newPressed;

                    Select(m_currentPressedObject);
                }

                if (ExecuteEvents.Execute(m_currentPressedObject, lookData, ExecuteEvents.beginDragHandler))
                {
                    lookData.pointerDrag    = m_currentPressedObject;
                    m_currentDraggingObject = m_currentPressedObject;
                }
            }
        }

        // Cursor release handling
        if (cursor.GetCursorReleased())
        {
            if (m_currentDraggingObject)
            {
                ExecuteEvents.Execute(m_currentDraggingObject, lookData, ExecuteEvents.endDragHandler);

                if (m_currentHoverObject != null)
                {
                    ExecuteEvents.ExecuteHierarchy(m_currentHoverObject, lookData, ExecuteEvents.dropHandler);
                }

                lookData.pointerDrag    = null;
                m_currentDraggingObject = null;
            }

            if (m_currentPressedObject)
            {
                ExecuteEvents.Execute(m_currentPressedObject, lookData, ExecuteEvents.pointerUpHandler);

                lookData.rawPointerPress = null;
                lookData.pointerPress    = null;
                m_currentPressedObject   = null;
            }
        }

        // Drag handling
        if (m_currentDraggingObject != null)
        {
            ExecuteEvents.Execute(m_currentDraggingObject, lookData, ExecuteEvents.dragHandler);
        }

        // Scroll Handling
        if (eventSystem.currentSelectedGameObject != null)
        {
            float scrollAmount = cursor.GetCursorScroll();

            if (scrollAmount > 0.01f || scrollAmount < -0.01f)
            {
                Slider slider = eventSystem.currentSelectedGameObject.GetComponent <Slider>();

                if (slider != null)
                {
                    float multiplier = slider.maxValue - slider.minValue;

                    slider.value += scrollAmount * ScrollSpeedMultiplier * multiplier;
                }
                else
                {
                    Scrollbar scrollBar = eventSystem.currentSelectedGameObject.GetComponent <Scrollbar>();

                    if (scrollBar != null)
                    {
                        scrollBar.value += scrollAmount * ScrollSpeedMultiplier;
                    }
                }
            }
        }

        // Tab Handling
        if (eventSystem.currentSelectedGameObject != null && Input.GetKeyUp(KeyCode.Tab))
        {
            AxisEventData axisData = new AxisEventData(this.eventSystem);

            axisData.moveDir = MoveDirection.Down;

            ExecuteEvents.Execute(eventSystem.currentSelectedGameObject, axisData, ExecuteEvents.moveHandler);
        }
    }