Ejemplo n.º 1
0
    private void GraphicRaycast(Canvas canvas, Ray ray, List <OVRRaycaster.RaycastHit> results)
    {
        IList <Graphic> graphicsForCanvas = GraphicRegistry.GetGraphicsForCanvas(canvas);

        OVRRaycaster.s_SortedGraphics.Clear();
        for (int i = 0; i < graphicsForCanvas.Count; i++)
        {
            Graphic graphic = graphicsForCanvas[i];
            if (graphic.depth != -1 && !(this.pointer == graphic.gameObject))
            {
                Vector3 vector;
                if (OVRRaycaster.RayIntersectsRectTransform(graphic.rectTransform, ray, out vector))
                {
                    Vector2 sp = this.eventCamera.WorldToScreenPoint(vector);
                    if (graphic.Raycast(sp, this.eventCamera))
                    {
                        OVRRaycaster.RaycastHit item;
                        item.graphic   = graphic;
                        item.worldPos  = vector;
                        item.fromMouse = false;
                        OVRRaycaster.s_SortedGraphics.Add(item);
                    }
                }
            }
        }
        OVRRaycaster.s_SortedGraphics.Sort((OVRRaycaster.RaycastHit g1, OVRRaycaster.RaycastHit g2) => g2.graphic.depth.CompareTo(g1.graphic.depth));
        for (int j = 0; j < OVRRaycaster.s_SortedGraphics.Count; j++)
        {
            results.Add(OVRRaycaster.s_SortedGraphics[j]);
        }
    }
Ejemplo n.º 2
0
    void Awake()
    {
        raycaster = GetComponent <OVRRaycaster>();
#if UNITY_ANDROID
        pointerObject.SetActive(false);
        this.enabled = false;
#endif
    }
Ejemplo n.º 3
0
        /// <summary>
        /// Get state for pointer which is a pointer moving in world space across the surface of a world space canvas.
        /// </summary>
        /// <returns></returns>
        protected MouseState GetCanvasPointerData()
        {
            // Get the OVRRayPointerEventData reference
            PointerEventData leftData;

            GetPointerData(kMouseLeftId, out leftData, true);
            leftData.Reset();

            // Setup default values here. Set position to zero because we don't actually know the pointer
            // positions. Each canvas knows the position of its canvas pointer.
            leftData.position    = Vector2.zero;
            leftData.scrollDelta = Input.mouseScrollDelta;
            leftData.button      = PointerEventData.InputButton.Left;

            if (activeGraphicRaycaster)
            {
                // Let the active raycaster find intersections on its canvas
                activeGraphicRaycaster.RaycastPointer(leftData, m_RaycastResultCache);
                var raycast = FindFirstRaycast(m_RaycastResultCache);
                leftData.pointerCurrentRaycast = raycast;
                m_RaycastResultCache.Clear();

                OVRRaycaster ovrRaycaster = raycast.module as OVRRaycaster;
                if (ovrRaycaster) // raycast may not actually contain a result
                {
                    // The Unity UI system expects event data to have a screen position
                    // so even though this raycast came from a world space ray we must get a screen
                    // space position for the camera attached to this raycaster for compatability
                    Vector2 position = ovrRaycaster.GetScreenPosition(raycast);

                    leftData.delta    = position - leftData.position;
                    leftData.position = position;
                }
            }

            // copy the apropriate data into right and middle slots
            PointerEventData rightData;

            GetPointerData(kMouseRightId, out rightData, true);
            CopyFromTo(leftData, rightData);
            rightData.button = PointerEventData.InputButton.Right;

            PointerEventData middleData;

            GetPointerData(kMouseMiddleId, out middleData, true);
            CopyFromTo(leftData, middleData);
            middleData.button = PointerEventData.InputButton.Middle;

            m_MouseState.SetButtonState(PointerEventData.InputButton.Left, StateForMouseButton(0), leftData);
            m_MouseState.SetButtonState(PointerEventData.InputButton.Right, StateForMouseButton(1), rightData);
            m_MouseState.SetButtonState(PointerEventData.InputButton.Middle, StateForMouseButton(2), middleData);
            return(m_MouseState);
        }
Ejemplo n.º 4
0
    /// <summary>
    /// Sets up canvas in front of Buildings to interact with the pointer.
    /// </summary>
    /// <param name="go">Building to set up interaction.</param>
    private void SetRaycasterValues(GameObject go)
    {
        Canvas       canvas    = go.GetComponentInChildren <Canvas>();
        OVRRaycaster raycaster = go.GetComponentInChildren <OVRRaycaster>();

        if (canvas)
        {
            canvas.worldCamera = eventCamera;
        }
        if (raycaster)
        {
            raycaster.pointer = laserPointer;
        }
    }
Ejemplo n.º 5
0
    protected override void Awake()
    {
        base.Awake();
        if (!Application.isPlaying)
        {
            return;
        }

        GetComponent <Canvas>().worldCamera = FindObjectOfType <VRMovement>().cam;
        user              = FindObjectOfType <VRMovement>();
        rect              = GetComponent <RectTransform>();
        raycaster         = GetComponent <OVRRaycaster>();
        raycaster.pointer = FindObjectOfType <OVRGazePointer>().gameObject;
        target            = Camera.main.transform;
    }
Ejemplo n.º 6
0
    protected override void Awake()
    {
        base.Awake();
        if (!Application.isPlaying)
        {
            return;
        }

        GetComponent <Canvas>().worldCamera = FindObjectOfType <VRMovement>().cam;
        raycaster         = GetComponent <OVRRaycaster>();
        raycaster.pointer = FindObjectOfType <OVRGazePointer>().gameObject;

        rect   = GetComponent <RectTransform>();
        target = Camera.main.transform;

        heightFactor = Random.Range(0.5f, 0.9f);
        heightDrag   = Random.Range(0.02f, 0.07f);
    }
Ejemplo n.º 7
0
        protected PointerInputModule.MouseState GetCanvasPointerData()
        {
            PointerEventData pointerEventData;

            base.GetPointerData(-1, out pointerEventData, true);
            pointerEventData.Reset();
            pointerEventData.position    = Vector2.zero;
            pointerEventData.scrollDelta = Input.mouseScrollDelta;
            pointerEventData.button      = PointerEventData.InputButton.Left;
            if (this.activeGraphicRaycaster)
            {
                this.activeGraphicRaycaster.RaycastPointer(pointerEventData, this.m_RaycastResultCache);
                RaycastResult raycastResult = BaseInputModule.FindFirstRaycast(this.m_RaycastResultCache);
                pointerEventData.pointerCurrentRaycast = raycastResult;
                this.m_RaycastResultCache.Clear();
                OVRRaycaster ovrraycaster = raycastResult.module as OVRRaycaster;
                if (ovrraycaster)
                {
                    Vector2 screenPosition = ovrraycaster.GetScreenPosition(raycastResult);
                    pointerEventData.delta    = screenPosition - pointerEventData.position;
                    pointerEventData.position = screenPosition;
                }
            }
            PointerEventData pointerEventData2;

            base.GetPointerData(-2, out pointerEventData2, true);
            this.CopyFromTo(pointerEventData, pointerEventData2);
            pointerEventData2.button = PointerEventData.InputButton.Right;
            PointerEventData pointerEventData3;

            base.GetPointerData(-3, out pointerEventData3, true);
            this.CopyFromTo(pointerEventData, pointerEventData3);
            pointerEventData3.button = PointerEventData.InputButton.Middle;
            this.m_MouseState.SetButtonState(PointerEventData.InputButton.Left, base.StateForMouseButton(0), pointerEventData);
            this.m_MouseState.SetButtonState(PointerEventData.InputButton.Right, base.StateForMouseButton(1), pointerEventData2);
            this.m_MouseState.SetButtonState(PointerEventData.InputButton.Middle, base.StateForMouseButton(2), pointerEventData3);
            return(this.m_MouseState);
        }
Ejemplo n.º 8
0
        // Overridden so that we can process the two types of pointer separately


        // The following 2 functions are equivalent to PointerInputModule.GetMousePointerEventData but are customized to
        // get data for ray pointers and canvas mouse pointers.

        /// <summary>
        /// State for a pointer controlled by a world space ray. E.g. gaze pointer
        /// </summary>
        /// <returns></returns>
        protected MouseState GetGazePointerData()
        {
            // Get the OVRRayPointerEventData reference
            OVRRayPointerEventData leftData;

            GetPointerData(kMouseLeftId, out leftData, true);
            leftData.Reset();

            //Now set the world space ray. This ray is what the user uses to point at UI elements
            leftData.worldSpaceRay = new Ray(rayTransform.position, rayTransform.forward);
            leftData.scrollDelta   = GetExtraScrollDelta();

            //Populate some default values
            leftData.button           = PointerEventData.InputButton.Left;
            leftData.useDragThreshold = true;
            // Perform raycast to find intersections with world
            eventSystem.RaycastAll(leftData, m_RaycastResultCache);
            var raycast = FindFirstRaycast(m_RaycastResultCache);

            leftData.pointerCurrentRaycast = raycast;
            m_RaycastResultCache.Clear();

            OVRRaycaster ovrRaycaster = raycast.module as OVRRaycaster;

            // We're only interested in intersections from OVRRaycasters
            if (ovrRaycaster)
            {
                // The Unity UI system expects event data to have a screen position
                // so even though this raycast came from a world space ray we must get a screen
                // space position for the camera attached to this raycaster for compatability
                leftData.position = ovrRaycaster.GetScreenPosition(raycast);


                // Find the world position and normal the Graphic the ray intersected
                RectTransform graphicRect = raycast.gameObject.GetComponent <RectTransform>();
                if (graphicRect != null)
                {
                    // Set are gaze indicator with this world position and normal
                    Vector3 worldPos = raycast.worldPosition;
                    Vector3 normal   = GetRectTransformNormal(graphicRect);
                    OVRGazePointer.instance.SetPosition(worldPos, normal);
                    // Make sure it's being shown
                    OVRGazePointer.instance.RequestShow();
                }
            }
            OVRPhysicsRaycaster physicsRaycaster = raycast.module as OVRPhysicsRaycaster;

            if (physicsRaycaster)
            {
                leftData.position = physicsRaycaster.GetScreenPos(raycast.worldPosition);
                OVRGazePointer.instance.RequestShow();
                OVRGazePointer.instance.SetPosition(raycast.worldPosition, raycast.worldNormal);
            }



            // Stick default data values in right and middle slots for compatability

            // copy the apropriate data into right and middle slots
            OVRRayPointerEventData rightData;

            GetPointerData(kMouseRightId, out rightData, true);
            CopyFromTo(leftData, rightData);
            rightData.button = PointerEventData.InputButton.Right;

            OVRRayPointerEventData middleData;

            GetPointerData(kMouseMiddleId, out middleData, true);
            CopyFromTo(leftData, middleData);
            middleData.button = PointerEventData.InputButton.Middle;


            m_MouseState.SetButtonState(PointerEventData.InputButton.Left, GetGazeButtonState(), leftData);
            m_MouseState.SetButtonState(PointerEventData.InputButton.Right, PointerEventData.FramePressState.NotChanged, rightData);
            m_MouseState.SetButtonState(PointerEventData.InputButton.Middle, PointerEventData.FramePressState.NotChanged, middleData);
            return(m_MouseState);
        }
        // The following 2 functions are equivalent to PointerInputModule.GetMousePointerEventData but are customized to
        // get data for ray pointers and canvas mouse pointers.

        /// <summary>
        /// State for a pointer controlled by a world space ray. E.g. gaze pointer
        /// </summary>
        /// <returns></returns>
        virtual protected MouseState GetGazePointerData()
        {
            // Get the OVRRayPointerEventData reference
            OVRPointerEventData leftData;

            GetPointerData(kMouseLeftId, out leftData, true);
            leftData.Reset();

            //Now set the world space ray. This ray is what the user uses to point at UI elements
            leftData.worldSpaceRay = new Ray(rayTransform.position, rayTransform.forward);
            leftData.scrollDelta   = GetExtraScrollDelta();

            //Populate some default values
            leftData.button           = PointerEventData.InputButton.Left;
            leftData.useDragThreshold = true;
            // Perform raycast to find intersections with world
            eventSystem.RaycastAll(leftData, m_RaycastResultCache);
            var raycast = FindFirstRaycast(m_RaycastResultCache);

            leftData.pointerCurrentRaycast = raycast;
            m_RaycastResultCache.Clear();

            m_Cursor.SetCursorRay(rayTransform);

            OVRRaycaster ovrRaycaster = raycast.module as OVRRaycaster;

            // We're only interested in intersections from OVRRaycasters
            if (ovrRaycaster)
            {
                // The Unity UI system expects event data to have a screen position
                // so even though this raycast came from a world space ray we must get a screen
                // space position for the camera attached to this raycaster for compatability
                leftData.position = ovrRaycaster.GetScreenPosition(raycast);

                // Find the world position and normal the Graphic the ray intersected
                RectTransform graphicRect = raycast.gameObject.GetComponent <RectTransform>();
                if (graphicRect != null)
                {
                    // Set are gaze indicator with this world position and normal
                    Vector3 worldPos = raycast.worldPosition;
                    Vector3 normal   = GetRectTransformNormal(graphicRect);
                    m_Cursor.SetCursorStartDest(rayTransform.position, worldPos, normal, raycast.gameObject);
                }
            }

            // Now process physical raycast intersections
            OVRPhysicsRaycaster physicsRaycaster = raycast.module as OVRPhysicsRaycaster;

            if (physicsRaycaster)
            {
                Vector3 position = raycast.worldPosition;

                if (performSphereCastForGazepointer)
                {
                    // Here we cast a sphere into the scene rather than a ray. This gives a more accurate depth
                    // for positioning a circular gaze pointer
                    List <RaycastResult> results = new List <RaycastResult>();
                    physicsRaycaster.Spherecast(leftData, results, m_SpherecastRadius);
                    if (results.Count > 0 && results[0].distance < raycast.distance)
                    {
                        position = results[0].worldPosition;
                    }
                }

                leftData.position = physicsRaycaster.GetScreenPos(raycast.worldPosition);

                m_Cursor.SetCursorStartDest(rayTransform.position, position, raycast.worldNormal);
            }

            // Stick default data values in right and middle slots for compatability

            // copy the apropriate data into right and middle slots
            OVRPointerEventData rightData;

            GetPointerData(kMouseRightId, out rightData, true);
            CopyFromTo(leftData, rightData);
            rightData.button = PointerEventData.InputButton.Right;

            OVRPointerEventData middleData;

            GetPointerData(kMouseMiddleId, out middleData, true);
            CopyFromTo(leftData, middleData);
            middleData.button = PointerEventData.InputButton.Middle;


            m_MouseState.SetButtonState(PointerEventData.InputButton.Left, GetGazeButtonState(), leftData);
            m_MouseState.SetButtonState(PointerEventData.InputButton.Right, PointerEventData.FramePressState.NotChanged, rightData);
            m_MouseState.SetButtonState(PointerEventData.InputButton.Middle, PointerEventData.FramePressState.NotChanged, middleData);
            return(m_MouseState);
        }
Ejemplo n.º 10
0
 void Awake()
 {
     raycaster = GetComponent<OVRRaycaster>();
     #if UNITY_ANDROID
     pointerObject.SetActive(false);
     this.enabled = false;
     #endif
 }
Ejemplo n.º 11
0
        // The following 2 functions are equivalent to PointerInputModule.GetMousePointerEventData but are customized to
        // get data for ray pointers and canvas mouse pointers.

        /// <summary>
        /// State for a pointer controlled by a world space ray. E.g. gaze pointer
        /// </summary>
        /// <returns></returns>
        virtual protected MouseState GetGazePointerData()
        {
            // Get the OVRRayPointerEventData reference
            OVRPointerEventData leftData;

            GetPointerData(kMouseLeftId, out leftData, true);
            leftData.Reset();

            //Now set the world space ray. This ray is what the user uses to point at UI elements
            leftData.worldSpaceRay = new Ray(rayTransform.position, rayTransform.forward);
            OVRInput.Controller controller = OVRInput.GetConnectedControllers() & (OVRInput.Controller.LTrackedRemote | OVRInput.Controller.RTrackedRemote);
            if (lineRenderer != null)
            {
                lineRenderer.enabled = trackingSpace != null && controller != OVRInput.Controller.None;
            }
            if (trackingSpace != null && controller != OVRInput.Controller.None)
            {
                controller = ((controller & OVRInput.Controller.LTrackedRemote) != OVRInput.Controller.None) ? OVRInput.Controller.LTrackedRemote : OVRInput.Controller.RTrackedRemote;

                Quaternion orientation     = OVRInput.GetLocalControllerRotation(controller);
                Vector3    localStartPoint = OVRInput.GetLocalControllerPosition(controller);

                Matrix4x4 localToWorld     = trackingSpace.localToWorldMatrix;
                Vector3   worldStartPoint  = localToWorld.MultiplyPoint(localStartPoint);
                Vector3   worldOrientation = localToWorld.MultiplyVector(orientation * Vector3.forward);
                leftData.worldSpaceRay = new Ray(worldStartPoint, worldOrientation);
                if (lineRenderer != null)
                {
                    lineRenderer.SetPosition(0, worldStartPoint);
                    lineRenderer.SetPosition(1, worldStartPoint + worldOrientation * 500.0f);
                }
            }
            else
            {
                leftData.worldSpaceRay = new Ray(rayTransform.position, rayTransform.forward);
            }
            leftData.scrollDelta = GetExtraScrollDelta();
            //leftdata.scrolldelta = getextrascrolldelta();

            //Populate some default values
            leftData.button           = PointerEventData.InputButton.Left;
            leftData.useDragThreshold = true;
            // Perform raycast to find intersections with world
            eventSystem.RaycastAll(leftData, m_RaycastResultCache);
            var raycast = FindFirstRaycast(m_RaycastResultCache);

            leftData.pointerCurrentRaycast = raycast;
            m_RaycastResultCache.Clear();

            OVRRaycaster ovrRaycaster = raycast.module as OVRRaycaster;

            // We're only interested in intersections from OVRRaycasters
            if (ovrRaycaster)
            {
                // The Unity UI system expects event data to have a screen position
                // so even though this raycast came from a world space ray we must get a screen
                // space position for the camera attached to this raycaster for compatability
                leftData.position = ovrRaycaster.GetScreenPosition(raycast);


                // Find the world position and normal the Graphic the ray intersected
                RectTransform graphicRect = raycast.gameObject.GetComponent <RectTransform>();
                if (graphicRect != null)
                {
                    // Set are gaze indicator with this world position and normal
                    Vector3 worldPos = raycast.worldPosition;
                    Vector3 normal   = GetRectTransformNormal(graphicRect);
                    OVRGazePointer.instance.SetPosition(worldPos, normal);
                    // Make sure it's being shown
                    OVRGazePointer.instance.RequestShow();
                    if (lineRenderer != null)
                    {
                        lineRenderer.SetPosition(1, raycast.worldPosition);
                    }
                }
            }

            // Now process physical raycast intersections
            OVRPhysicsRaycaster physicsRaycaster = raycast.module as OVRPhysicsRaycaster;

            if (physicsRaycaster)
            {
                Vector3 position = raycast.worldPosition;

                if (performSphereCastForGazepointer)
                {
                    // Here we cast a sphere into the scene rather than a ray. This gives a more accurate depth
                    // for positioning a circular gaze pointer
                    List <RaycastResult> results = new List <RaycastResult>();
                    physicsRaycaster.Spherecast(leftData, results, OVRGazePointer.instance.GetCurrentRadius());
                    if (results.Count > 0 && results[0].distance < raycast.distance)
                    {
                        position = results[0].worldPosition;
                    }
                }

                leftData.position = physicsRaycaster.GetScreenPos(raycast.worldPosition);

                // Show the cursor while pointing at an interactable object
                OVRGazePointer.instance.RequestShow();
                if (lineRenderer != null)
                {
                    lineRenderer.SetPosition(1, raycast.worldPosition);
                }
                if (matchNormalOnPhysicsColliders)
                {
                    OVRGazePointer.instance.SetPosition(position, raycast.worldNormal);
                }
                else
                {
                    OVRGazePointer.instance.SetPosition(position);
                }
            }



            // Stick default data values in right and middle slots for compatability

            // copy the apropriate data into right and middle slots
            OVRPointerEventData rightData;

            GetPointerData(kMouseRightId, out rightData, true);
            CopyFromTo(leftData, rightData);
            rightData.button = PointerEventData.InputButton.Right;

            OVRPointerEventData middleData;

            GetPointerData(kMouseMiddleId, out middleData, true);
            CopyFromTo(leftData, middleData);
            middleData.button = PointerEventData.InputButton.Middle;


            m_MouseState.SetButtonState(PointerEventData.InputButton.Left, GetGazeButtonState(), leftData);
            m_MouseState.SetButtonState(PointerEventData.InputButton.Right, PointerEventData.FramePressState.NotChanged, rightData);
            m_MouseState.SetButtonState(PointerEventData.InputButton.Middle, PointerEventData.FramePressState.NotChanged, middleData);
            return(m_MouseState);
        }
Ejemplo n.º 12
0
        // Overridden so that we can process the two types of pointer separately


        // The following 2 functions are equivalent to PointerInputModule.GetMousePointerEventData but are customized to
        // get data for ray pointers and canvas mouse pointers.

        /// <summary>
        /// State for a pointer controlled by a world space ray. E.g. gaze pointer
        /// </summary>
        /// <returns></returns>
        protected MouseState GetGazePointerData()
        {
            // Get the OVRRayPointerEventData reference
            OVRRayPointerEventData leftData;

            GetPointerData(kMouseLeftId, out leftData, true);
            leftData.Reset();

            //Now set the world space ray. This ray is what the user uses to point at UI elements
            leftData.worldSpaceRay = new Ray(rayAnchor.position, rayAnchor.forward);
            leftData.scrollDelta   = GetExtraScrollDelta();

            //Populate some default values
            leftData.button           = PointerEventData.InputButton.Left;
            leftData.useDragThreshold = true;
            // Perform raycast to find intersections with world
            eventSystem.RaycastAll(leftData, m_RaycastResultCache);
            var raycast = FindFirstRaycast(m_RaycastResultCache);

            leftData.pointerCurrentRaycast = raycast;
            m_RaycastResultCache.Clear();

            OVRRaycaster ovrRaycaster = raycast.module as OVRRaycaster;

            // We're only interested in intersections from OVRRaycasters
            if (ovrRaycaster && raycast.gameObject.GetComponent <MaskableGraphic>() && !raycast.gameObject.GetComponent <MaskableGraphic>().raycastTarget)
            {
                print("!!!");
            }
            if (ovrRaycaster && !(raycast.gameObject.GetComponent <MaskableGraphic>() && !raycast.gameObject.GetComponent <MaskableGraphic>().raycastTarget))
            {
                // The Unity UI system expects event data to have a screen position
                // so even though this raycast came from a world space ray we must get a screen
                // space position for the camera attached to this raycaster for compatability
                leftData.position = ovrRaycaster.GetScreenPosition(raycast);


                // Find the world position and normal the Graphic the ray intersected
                RectTransform graphicRect = raycast.gameObject.GetComponent <RectTransform>();
                if (graphicRect != null)
                {
                    Vector3 worldPos = raycast.worldPosition;
                    if (Vector3.Distance(worldPos, controllerPointer.transform.position) > maxDistance)
                    {
                        controllerPointer.psEnable = false;
                        leftData.scrollDelta       = Vector2.zero;
                    }
                    else
                    {
                        controllerPointer.psEnable = true;
                        controllerPointer.SetPointLine(worldPos);
                    }
                }
            }
            else
            {
                controllerPointer.psEnable = false;
            }

            // Stick default data values in right and middle slots for compatability

            // copy the apropriate data into right and middle slots
            OVRRayPointerEventData rightData;

            GetPointerData(kMouseRightId, out rightData, true);
            CopyFromTo(leftData, rightData);
            rightData.button = PointerEventData.InputButton.Right;

            OVRRayPointerEventData middleData;

            GetPointerData(kMouseMiddleId, out middleData, true);
            CopyFromTo(leftData, middleData);
            middleData.button = PointerEventData.InputButton.Middle;


            m_MouseState.SetButtonState(PointerEventData.InputButton.Left, GetGazeButtonState(), leftData);
            m_MouseState.SetButtonState(PointerEventData.InputButton.Right, PointerEventData.FramePressState.NotChanged, rightData);
            m_MouseState.SetButtonState(PointerEventData.InputButton.Middle, PointerEventData.FramePressState.NotChanged, middleData);
            return(m_MouseState);
        }
Ejemplo n.º 13
0
        protected virtual PointerInputModule.MouseState GetGazePointerData()
        {
            OVRPointerEventData ovrpointerEventData;

            this.GetPointerData(-1, out ovrpointerEventData, true);
            ovrpointerEventData.Reset();
            ovrpointerEventData.worldSpaceRay    = new Ray(this.rayTransform.position, this.rayTransform.forward);
            ovrpointerEventData.scrollDelta      = this.GetExtraScrollDelta();
            ovrpointerEventData.button           = PointerEventData.InputButton.Left;
            ovrpointerEventData.useDragThreshold = true;
            base.eventSystem.RaycastAll(ovrpointerEventData, this.m_RaycastResultCache);
            RaycastResult raycastResult = BaseInputModule.FindFirstRaycast(this.m_RaycastResultCache);

            ovrpointerEventData.pointerCurrentRaycast = raycastResult;
            this.m_RaycastResultCache.Clear();
            OVRRaycaster ovrraycaster = raycastResult.module as OVRRaycaster;

            if (ovrraycaster)
            {
                ovrpointerEventData.position = ovrraycaster.GetScreenPosition(raycastResult);
                RectTransform component = raycastResult.gameObject.GetComponent <RectTransform>();
                if (component != null)
                {
                    Vector3 worldPosition       = raycastResult.worldPosition;
                    Vector3 rectTransformNormal = OVRInputModule.GetRectTransformNormal(component);
                    OVRGazePointer.instance.SetPosition(worldPosition, rectTransformNormal);
                    OVRGazePointer.instance.RequestShow();
                }
            }
            OVRPhysicsRaycaster ovrphysicsRaycaster = raycastResult.module as OVRPhysicsRaycaster;

            if (ovrphysicsRaycaster)
            {
                Vector3 worldPosition2 = raycastResult.worldPosition;
                if (this.performSphereCastForGazepointer)
                {
                    List <RaycastResult> list = new List <RaycastResult>();
                    ovrphysicsRaycaster.Spherecast(ovrpointerEventData, list, OVRGazePointer.instance.GetCurrentRadius());
                    if (list.Count > 0 && list[0].distance < raycastResult.distance)
                    {
                        worldPosition2 = list[0].worldPosition;
                    }
                }
                ovrpointerEventData.position = ovrphysicsRaycaster.GetScreenPos(raycastResult.worldPosition);
                OVRGazePointer.instance.RequestShow();
                if (this.matchNormalOnPhysicsColliders)
                {
                    OVRGazePointer.instance.SetPosition(worldPosition2, raycastResult.worldNormal);
                }
                else
                {
                    OVRGazePointer.instance.SetPosition(worldPosition2);
                }
            }
            OVRPointerEventData ovrpointerEventData2;

            this.GetPointerData(-2, out ovrpointerEventData2, true);
            this.CopyFromTo(ovrpointerEventData, ovrpointerEventData2);
            ovrpointerEventData2.button = PointerEventData.InputButton.Right;
            OVRPointerEventData ovrpointerEventData3;

            this.GetPointerData(-3, out ovrpointerEventData3, true);
            this.CopyFromTo(ovrpointerEventData, ovrpointerEventData3);
            ovrpointerEventData3.button = PointerEventData.InputButton.Middle;
            this.m_MouseState.SetButtonState(PointerEventData.InputButton.Left, this.GetGazeButtonState(), ovrpointerEventData);
            this.m_MouseState.SetButtonState(PointerEventData.InputButton.Right, PointerEventData.FramePressState.NotChanged, ovrpointerEventData2);
            this.m_MouseState.SetButtonState(PointerEventData.InputButton.Middle, PointerEventData.FramePressState.NotChanged, ovrpointerEventData3);
            return(this.m_MouseState);
        }
Ejemplo n.º 14
0
 // Start is called before the first frame update
 void Awake()
 {
     m_ovrRaycaster      = GetComponent <OVRRaycaster>();
     m_defaultStartColor = m_lineRenderer.startColor;
     m_defaultEndColor   = m_lineRenderer.endColor;
 }