Esempio n. 1
0
    // Update is called once per frame
    void Update()
    {
        // Set mouse visibility based on the chosen policy
        if (mouseShowPolicy == MouseShowPolicy.withActivity)
        {
            pointerObject.SetActive(HasMovedRecently() && raycaster.IsFocussed());
        }
        else if (mouseShowPolicy == MouseShowPolicy.withGaze)
        {
            pointerObject.SetActive(raycaster.IsFocussed());
        }

        if (hideGazePointerWhenActive && HasMovedRecently() && raycaster.IsFocussed())
        {
            OVRGazePointer.instance.RequestHide();
        }

        if (defaultMouseMovement && raycaster.IsFocussed())
        {
            // If we're responsible for moving the pointer and we're the currently active
            // raycaster then update the mouse position, keeping it clamped to inside the canvas.
            Vector2 mousePos = pointerObject.GetComponent <RectTransform>().localPosition;
            mousePos += new Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y")) * mouseMoveSpeed;
            float currentPanelWidth  = GetComponent <RectTransform>().rect.width;
            float currentPanelHeight = GetComponent <RectTransform>().rect.height;
            mousePos.x = Mathf.Clamp(mousePos.x, -currentPanelWidth / 2, currentPanelWidth / 2);
            mousePos.y = Mathf.Clamp(mousePos.y, -currentPanelHeight / 2, currentPanelHeight / 2);

            // Position mouse pointer
            SetLocalPosition(mousePos);
        }
    }
Esempio n. 2
0
    // Update is called once per frame
    void Update()
    {
        OVRManager.instance.gameObject.transform.LookAt(GetComponent <OVRRaycaster>().pointer.transform);
        // Set mouse visibility based on the chosen policy
        if (mouseShowPolicy == MouseShowPolicy.withActivity)
        {
            // Active if mouse has moved recently and this raycaster (and associated canvas) is active
            pointerObject.SetActive(HasMovedRecently() && raycaster.IsFocussed());
        }
        else if (mouseShowPolicy == MouseShowPolicy.withGaze)
        {
            // Active if this raycaster (and associated canvas) is active
            pointerObject.SetActive(raycaster.IsFocussed());
        }

        if (hideGazePointerWhenActive && HasMovedRecently() && raycaster.IsFocussed())
        {
            // With this policy we hide the gaze pointer while the mouse is active. It can be confusing to
            // have a mouse pointer and a gaze pointer active at the same time
            OVRGazePointer.instance.RequestHide();
        }

        if (defaultMouseMovement && raycaster.IsFocussed())
        {
            // If we're responsible for moving the pointer and we're the currently active
            // raycaster then update the mouse position, keeping it clamped to inside the canvas.
            Vector2 mousePos = pointerObject.GetComponent <RectTransform>().localPosition;
            mousePos += new Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y")) * mouseMoveSpeed;
            float currentPanelWidth  = GetComponent <RectTransform>().rect.width;
            float currentPanelHeight = GetComponent <RectTransform>().rect.height;
            mousePos.x = Mathf.Clamp(mousePos.x, -currentPanelWidth / 2, currentPanelWidth / 2);
            mousePos.y = Mathf.Clamp(mousePos.y, -currentPanelHeight / 2, currentPanelHeight / 2);

            // Position mouse pointer
            SetLocalPosition(mousePos);
        }
    }