Beispiel #1
0
    // Update is called once per frame
    void Update()
    {
        this.activeController = OVRInputHelpers.GetControllerForButton(OVRInput.Button.PrimaryIndexTrigger, this.activeController);
        Ray pointer = OVRInputHelpers.GetSelectionRay(this.activeController, this.trackingSpace);

        RaycastHit hit;

        if (this.boxCollider.Raycast(pointer, out hit, 500))
        {
            // We got a hit in the scroll view. Check if we're already within the bounds - if so, do nothing.
            if (!isInBounds)
            {
                // We entered the scroll view, so enable box colliders on children.
                foreach (var boxCollider in this.content.gameObject.GetComponentsInChildren <BoxCollider>())
                {
                    boxCollider.enabled = true;
                }

                isInBounds = true;
            }
        }
        else if (isInBounds)
        {
            // We are outside the scroll view and were previously inside, so disable box colliders on children.
            foreach (var boxCollider in this.content.gameObject.GetComponentsInChildren <BoxCollider>())
            {
                boxCollider.enabled = false;
            }

            isInBounds = false;
        }
    }
Beispiel #2
0
    // Update is called once per frame
    void Update()
    {
        activeController = OVRInputHelpers.GetControllerForButton(OVRInput.Button.PrimaryIndexTrigger, activeController);

        if (OVRInput.GetDown(OVRInput.Button.PrimaryIndexTrigger, activeController))
        {
            isEnabled = true;
        }

        raycaster.enabled = isEnabled;
        visualizer.gameObject.SetActive(isEnabled);
        if (!isEnabled)
        {
            return;
        }

        Ray        pointer = OVRInputHelpers.GetSelectionRay(activeController, trackingSpace);
        RaycastHit hit; // Was anything hit?

        if (!Physics.Raycast(pointer, out hit, 10))
        {
            return;
        }

        icoGlobe = hit.collider.transform.parent.GetComponent <IcoGlobe>();
        if (icoGlobe == null)
        {
            return;
        }

        if (activeController == OVRInput.Controller.RTouch)
        {
            icoGlobe.Hover(hit.triangleIndex);

            if (OVRInput.Get(OVRInput.RawButton.A, activeController))
            {
                icoGlobe.Select(hit.triangleIndex);
            }
        }
        else if (activeController == OVRInput.Controller.LTouch)
        {
            grabbing = OVRInput.Get(OVRInput.RawButton.LIndexTrigger, activeController);
        }

        if (grabbing)
        {
            rotateX = OVRInput.GetLocalControllerVelocity(activeController).x;
            icoGlobe.transform.eulerAngles = new Vector3(0, icoGlobe.transform.eulerAngles.y - (rotateX * 150 * Time.deltaTime), 0);
        }
    }
    // Update is called once per frame
    void Update()
    {
        var  activeControllerLeft = OVRInputHelpers.GetConnectedControllers(OVRInputHelpers.HandFilter.Left);
        Ray  pointerLeft;
        bool gotRayLeft = OVRInputHelpers.GetSelectionRay(activeControllerLeft, this.trackingSpace, out pointerLeft);

        var  activeControllerRight = OVRInputHelpers.GetConnectedControllers(OVRInputHelpers.HandFilter.Right);
        Ray  pointerRight;
        bool gotRayRight = OVRInputHelpers.GetSelectionRay(activeControllerRight, this.trackingSpace, out pointerRight);

        RaycastHit hitLeft;
        RaycastHit hitRight;

        if (gotRayLeft && this.boxCollider.Raycast(pointerLeft, out hitLeft, 500) || gotRayRight && this.boxCollider.Raycast(pointerRight, out hitRight, 500))
        {
            // We got a hit in the scroll view. Check if we're already within the bounds - if so, do nothing.
            if (!isInBounds)
            {
                // We entered the scroll view, so enable box colliders on children.
                foreach (var boxCollider in this.content.gameObject.GetComponentsInChildren <BoxCollider>())
                {
                    boxCollider.enabled = true;
                }

                isInBounds = true;
            }
        }
        else if (isInBounds)
        {
            // We are outside the scroll view and were previously inside, so disable box colliders on children.
            foreach (var boxCollider in this.content.gameObject.GetComponentsInChildren <BoxCollider>())
            {
                boxCollider.enabled = false;
            }

            isInBounds = false;
        }
    }
        void Update()
        {
            // The scroll view has a viewport that masks the UI that is outside the scroll view.
            // However, it does not filter any ray casting that is outside the mask!
            // This means that the box colliders of the individual cells still get hit outside the scroll view itself,
            // which can interfer with the tabs above the scroll view.
            //
            // To fix this issue, we cast a ray from current pointer to the scroll view's box collider.
            // If we get a hit, it means we're inside the scroll view - so we enable all the children box
            // colliders, which will behave as expected.
            // If we do not get a hit, it means that we're outside the scroll view - so we disable all the children
            // box colliders, which addresses the issue above.
            var  activeControllerLeft = OVRInputHelpers.GetConnectedControllers(OVRInputHelpers.HandFilter.Left);
            Ray  pointerLeft;
            bool gotRayLeft = OVRInputHelpers.GetSelectionRay(activeControllerLeft, this.trackingSpace, out pointerLeft);

            var  activeControllerRight = OVRInputHelpers.GetConnectedControllers(OVRInputHelpers.HandFilter.Right);
            Ray  pointerRight;
            bool gotRayRight = OVRInputHelpers.GetSelectionRay(activeControllerRight, this.trackingSpace, out pointerRight);

            RaycastHit hitLeft;
            RaycastHit hitRight;

            if (gotRayLeft && this.boxCollider.Raycast(pointerLeft, out hitLeft, 500) || gotRayRight && this.boxCollider.Raycast(pointerRight, out hitRight, 500))
            {
                // We got a hit in the scroll view. Check if we're already within the bounds - if so, do nothing.
                if (!isInBounds)
                {
                    // We entered the scroll view, so enable box colliders on children.
                    foreach (var boxCollider in this.content.gameObject.GetComponentsInChildren <BoxCollider>())
                    {
                        boxCollider.enabled = true;
                    }

                    isInBounds = true;
                }
            }
            else if (isInBounds)
            {
                // We are outside the scroll view and were previously inside, so disable box colliders on children.
                foreach (var boxCollider in this.content.gameObject.GetComponentsInChildren <BoxCollider>())
                {
                    boxCollider.enabled = false;
                }

                isInBounds = false;
            }

            // Get vector from either left or right thumbstick
            var moveVector = OVRInput.Get(OVRInput.Axis2D.PrimaryThumbstick);

            if (moveVector.x == 0 && moveVector.y == 0)
            {
                moveVector = OVRInput.Get(OVRInput.Axis2D.SecondaryThumbstick);
            }
            if (moveVector.x == 0 && moveVector.y == 0)
            {
                moveVector = OVRInput.Get(OVRInput.Axis2D.PrimaryTouchpad);
            }
            if (moveVector.x == 0 && moveVector.y == 0)
            {
                moveVector = OVRInput.Get(OVRInput.Axis2D.SecondaryTouchpad);
            }

            if (moveVector.y == 0)
            {
                // No y-movement, so return. Also reset the speed multiplier
                this.lastSpeedMultiplier = 0;
                return;
            }

            // Scroll by a fixed amount proportional to thumbstick position on each frame
            // and map this to a fraction of the total viewport size:
            //   moveVector.y: The thumbstick vertical position normalized to [-1,1].
            //   Time.deltaTime: The time delta since last frame
            //   speedMultiplier: Just a multiplier to get a good scrolling speed. Increase over time to speed up scrolling.
            // So, moveVector.y * Time.deltaTime * speedMultiplier = the amount to scroll in "units"
            //   proportional to thumbstick position since last frame.
            // this.cellHeight / this.content.sizeDelta.y = cell height / total content height.
            float speedMultiplier   = Mathf.Clamp(this.lastSpeedMultiplier * SpeedMultiplierIncrease, SpeedMultiplier, MaxSpeedMultiplier);
            float verticalIncrement = moveVector.y * Time.deltaTime * speedMultiplier * this.cellHeight / this.content.sizeDelta.y;

            this.lastSpeedMultiplier        = speedMultiplier;
            this.verticalNormalizedPosition = Mathf.Clamp01(this.verticalNormalizedPosition + verticalIncrement);
        }
Beispiel #5
0
 // Use this for initialization
 void Start()
 {
     trackingSpace = OVRInputHelpers.FindTrackingSpace();
     raycaster     = GetComponentInChildren <OVRPhysicsRaycaster>();
 }