void HandleNoRayHit()
        {
            float distance = rayDrawDistance;

            activeController = OVRInputHelpers.GetControllerForButton(OVRInput.Button.PrimaryIndexTrigger, activeController);
            Ray ray = OVRInputHelpers.GetSelectionRay(activeController, trackingSpace);

            SetPointerVisibility();

            if (linePointer != null)
            {
                RaycastHit hit;
                if (Physics.Raycast(ray, out hit, rayDrawDistance))
                {
                    distance = hit.distance;
                }
                linePointer.SetPosition(0, ray.origin);
                linePointer.SetPosition(1, ray.origin + ray.direction * distance);
            }

            if (gazePointer != null)
            {
                gazePointer.gameObject.SetActive(gazePointerVisibility);
                gazePointer.position = ray.origin + ray.direction * distance;
            }
        }
Beispiel #2
0
        public override void UpdateModule()
        {
            activeController = OVRInputHelpers.GetControllerForButton(OVRInput.Button.PrimaryIndexTrigger, activeController);

            m_LastMousePosition = m_MousePosition;
            m_MousePosition     = Input.mousePosition;
        }
Beispiel #3
0
        void Update()
        {
            activeController = OVRInputHelpers.GetControllerForButton(OVRInput.Button.PrimaryIndexTrigger, activeController);
            Ray selectionRay = OVRInputHelpers.GetSelectionRay(activeController, trackingSpace);

            SetPointerVisibility();
            SetPointer(selectionRay);
        }
Beispiel #4
0
 void Awake()
 {
     if (trackingSpace == null)
     {
         Debug.LogWarning("OVRPointerVisualizer did not have a tracking space set. Looking for one");
         trackingSpace = OVRInputHelpers.FindTrackingSpace();
     }
 }
Beispiel #5
0
 void OnSceneLoaded(Scene scene, LoadSceneMode mode)
 {
     if (trackingSpace == null)
     {
         Debug.LogWarning("OVRInputModule did not have a tracking space set. Looking for one");
         trackingSpace = OVRInputHelpers.FindTrackingSpace();
     }
 }
Beispiel #6
0
 protected override void Awake()
 {
     base.Awake();
     if (trackingSpace == null)
     {
         Debug.LogWarning("OVRInputModule did not have a tracking space set. Looking for one");
         trackingSpace = OVRInputHelpers.FindTrackingSpace();
     }
 }
Beispiel #7
0
 void Awake()
 {
     if (trackingSpace == null)
     {
         Debug.LogWarning("OVRRawRaycaster did not have a tracking space set. Looking for one");
         trackingSpace = OVRInputHelpers.FindTrackingSpace();
     }
     centreEyeAnchor = trackingSpace.transform.Find("CenterEyeAnchor");
 }
Beispiel #8
0
        void Update()
        {
            var activeController = OVRInputHelpers.GetConnectedControllers((OVRInputHelpers.HandFilter)handType);

            Ray  selectionRay;
            bool gotRay = OVRInputHelpers.GetSelectionRay(activeController, trackingSpace, out selectionRay);

            SetPointerVisibility(gotRay && trackingSpace != null && activeController != OVRInput.Controller.None);

            if (gotRay)
            {
                SetPointer(selectionRay);
            }
        }
Beispiel #9
0
 void Awake()
 {
     if (trackingSpace == null)
     {
         Debug.LogWarning("OVRRawRaycaster did not have a tracking space set. Looking for one");
         trackingSpace = OVRInputHelpers.FindTrackingSpace();
     }
     centreEyeAnchor  = trackingSpace.transform.Find("CenterEyeAnchor");
     playerController = GameObject.Find("OVRPlayerController").transform;
     if (playerController == null)
     {
         Debug.LogError("Could not find OVRPlayerController in scene");
     }
 }
Beispiel #10
0
        void Update()
        {
            activeController = OVRInputHelpers.GetControllerForButton(OVRInput.Button.PrimaryIndexTrigger, activeController);
            Ray selectionRay = OVRInputHelpers.GetSelectionRay(activeController, trackingSpace);

            if (Application.isEditor)
            {
                // WM: in Editor, force right touch controller to be active.
                activeController = OVRInput.Controller.RTouch;
                selectionRay     = EditorRay;
            }

            SetPointerVisibility();
            SetPointer(selectionRay);
        }
Beispiel #11
0
        /// <summary>
        /// Get state of button corresponding to gaze pointer
        /// </summary>
        /// <returns></returns>
        protected UnityEngine.EventSystems.PointerEventData.FramePressState GetGazeButtonState(OVRInput.Controller activeController)
        {
            var pressed  = false;
            var released = false;

            if (activeController != OVRInput.Controller.None)
            {
                if ((activeController & OVRInput.Controller.Touch) != OVRInput.Controller.None)
                {
                    // Handle touch controllers
                    pressed  = OVRInput.GetDown(joyPadClickButton, activeController);
                    released = OVRInput.GetUp(joyPadClickButton, activeController);
                }
                else if ((activeController & OVRInput.Controller.Hands) != OVRInput.Controller.None &&
                         OVRPlugin.GetHandTrackingEnabled() && null != HandsManager.Instance && HandsManager.Instance.IsInitialized())
                {
                    pressed  = OVRInputHelpers.IsFingerStartPinching(activeController, pinchFinger);
                    released = OVRInputHelpers.IsFingerStopPinching(activeController, pinchFinger);
                }
            }
            else
            {
                pressed  = OVRInput.GetDown(joyPadClickButton);
                released = OVRInput.GetUp(joyPadClickButton);
            }

#if UNITY_ANDROID && !UNITY_EDITOR
            pressed  |= Input.GetMouseButtonDown(0);
            released |= Input.GetMouseButtonUp(0);
#endif

            if (pressed && released)
            {
                return(UnityEngine.EventSystems.PointerEventData.FramePressState.PressedAndReleased);
            }
            if (pressed)
            {
                return(UnityEngine.EventSystems.PointerEventData.FramePressState.Pressed);
            }
            if (released)
            {
                return(UnityEngine.EventSystems.PointerEventData.FramePressState.Released);
            }

            return(UnityEngine.EventSystems.PointerEventData.FramePressState.NotChanged);
        }
        void HandleSelectionRayHit(Vector3 hitPosition, Vector3 hitNormal)
        {
            activeController = OVRInputHelpers.GetControllerForButton(OVRInput.Button.PrimaryIndexTrigger, activeController);
            Ray ray = OVRInputHelpers.GetSelectionRay(activeController, trackingSpace);

            SetPointerVisibility();

            if (linePointer != null)
            {
                linePointer.SetPosition(0, ray.origin);
                linePointer.SetPosition(1, hitPosition);
            }

            if (gazePointer != null)
            {
                gazePointer.gameObject.SetActive(true);
                gazePointer.position = hitPosition;
            }
        }
 void Awake()
 {
     if (trackingSpace == null)
     {
         Debug.LogWarning("OVRPointerVisualizer did not have a tracking space set. Looking for one");
         trackingSpace = OVRInputHelpers.FindTrackingSpace();
     }
     if (gazePointer != null)
     {
         // gazePointerにコライダが付いていると動作に支障をきたすのでオフっておく。
         var collider = gazePointer.GetComponent <Collider>();
         if (collider != null)
         {
             collider.enabled = false;
         }
     }
     if (inputModule == null)
     {
         inputModule = EventSystem.current.currentInputModule as OVRInputModule;
     }
 }
Beispiel #14
0
        void Update()
        {
            Ray pointerLeft;
            Ray pointerRight;

            // Get left & right rays
            var activeControllerLeft  = OVRInputHelpers.GetConnectedControllers(OVRInputHelpers.HandFilter.Left);
            var activeControllerRight = OVRInputHelpers.GetConnectedControllers(OVRInputHelpers.HandFilter.Right);

            bool gotRayLeft  = OVRInputHelpers.GetSelectionRay(activeControllerLeft, trackingSpace, out pointerLeft);
            bool gotRayRight = OVRInputHelpers.GetSelectionRay(activeControllerRight, trackingSpace, out pointerRight);

            // Cast the rays
            RaycastHit hitLeft    = default(RaycastHit);
            RaycastHit hitRight   = default(RaycastHit);
            bool       isHitLeft  = gotRayLeft && Physics.Raycast(pointerLeft, out hitLeft, raycastDistance, ~excludeLayers);
            bool       isHitRight = gotRayRight && Physics.Raycast(pointerRight, out hitRight, raycastDistance, ~excludeLayers);

            // Process the hits
            _actions.Clear();

            if (lastHitLeft != null)
            {
                _actions[lastHitLeft] = HoverAction.None;
            }

            if (lastHitRight != null)
            {
                _actions[lastHitRight] = HoverAction.None;
            }

            if (isHitLeft)
            {
                _actions[hitLeft.transform] = HoverAction.None;
            }

            if (isHitRight)
            {
                _actions[hitRight.transform] = HoverAction.None;
            }

            ProcessHit(_actions, isHitLeft, hitLeft.transform, ref lastHitLeft);
            ProcessHit(_actions, isHitRight, hitRight.transform, ref lastHitRight);

            // Perform the actions
            foreach (KeyValuePair <Transform, HoverAction> kvp in _actions)
            {
                // Only perform enter / exit actions if we are not staying on existing transform
                // and if we're not both entering & exiting
                if ((kvp.Value & HoverAction.Stay) == HoverAction.None &&
                    (kvp.Value & (HoverAction.Enter | HoverAction.Exit)) != (HoverAction.Enter | HoverAction.Exit))
                {
                    if ((kvp.Value & HoverAction.Enter) != HoverAction.None && onHoverEnter != null)
                    {
                        onHoverEnter.Invoke(kvp.Key);
                    }

                    if ((kvp.Value & HoverAction.Exit) != HoverAction.None && onHoverExit != null)
                    {
                        onHoverExit.Invoke(kvp.Key);
                    }
                }

                if ((kvp.Value & HoverAction.Hover) != HoverAction.None && onHover != null)
                {
                    // Hovering over transform
                    onHover.Invoke(kvp.Key);
                }
            }

            if (isHitLeft && !_isDragging)
            {
                ProcessButtonPresses(activeControllerLeft, true, lastHitLeft, ref triggerButtonDownLeft, ref padButtonDownLeft, ref tertiaryButtonDownLeft);
                ProcessHandPinch(activeControllerLeft, lastHitLeft, ref triggerFingerDownLeft, ref padFingerDownLeft, ref tertiaryFingerDownLeft);
            }

            if (isHitRight && !_isDragging)
            {
                ProcessButtonPresses(activeControllerRight, false, lastHitRight, ref triggerButtonDownRight, ref padButtonDownRight, ref tertiaryButtonDownRight);
                ProcessHandPinch(activeControllerRight, lastHitRight, ref triggerFingerDownRight, ref padFingerDownRight, ref tertiaryFingerDownRight);
            }
        }
Beispiel #15
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(bool isLeft)
        {
            // Get the OVRRayPointerEventData reference
            OVRRayPointerEventData leftData;

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

            leftData.worldSpaceRay = default(Ray);
            var  activeController = OVRInputHelpers.GetConnectedControllers(isLeft ? OVRInputHelpers.HandFilter.Left : OVRInputHelpers.HandFilter.Right);
            bool gotRay           = OVRInputHelpers.GetSelectionRay(activeController, trackingSpace, out leftData.worldSpaceRay);

            leftData.scrollDelta = GetExtraScrollDelta();

            //Populate some default values
            leftData.button           = UnityEngine.EventSystems.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);

                    if (OnSelectionRayHit != null)
                    {
                        OnSelectionRayHit(raycast.worldPosition, raycast.worldNormal);
                    }
                }
            }
            OVRPhysicsRaycaster physicsRaycaster = raycast.module as OVRPhysicsRaycaster;

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

                if (OnSelectionRayHit != null)
                {
                    OnSelectionRayHit(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, isLeft);
            CopyFromTo(leftData, rightData);
            rightData.button = UnityEngine.EventSystems.PointerEventData.InputButton.Right;

            OVRRayPointerEventData middleData;

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

            var mouseState = isLeft ? m_MouseStateLeft : m_MouseStateRight;

            mouseState.SetButtonState(UnityEngine.EventSystems.PointerEventData.InputButton.Left, GetGazeButtonState(activeController), leftData);
            mouseState.SetButtonState(UnityEngine.EventSystems.PointerEventData.InputButton.Right, UnityEngine.EventSystems.PointerEventData.FramePressState.NotChanged, rightData);
            mouseState.SetButtonState(UnityEngine.EventSystems.PointerEventData.InputButton.Middle, UnityEngine.EventSystems.PointerEventData.FramePressState.NotChanged, middleData);
            return(mouseState);
        }
Beispiel #16
0
        void Update()
        {
            activeController = OVRInputHelpers.GetControllerForButton(OVRInput.Button.PrimaryIndexTrigger, activeController);
            Ray pointer = OVRInputHelpers.GetSelectionRay(activeController, trackingSpace);

            RaycastHit hit; // Was anything hit?

            if (Physics.Raycast(pointer, out hit, raycastDistance, ~excludeLayers))
            {
                myHitPos = hit.point;
                myOVRPointerVisualizer.rayDrawDistance = hit.distance;
                //Debug.Log(hit.distance);


                if (lastHit != null && lastHit != hit.transform)
                {
                    if (onHoverExit != null)
                    {
                        onHoverExit.Invoke(lastHit);
                    }
                    lastHit = null;
                }

                if (lastHit == null)
                {
                    if (onHoverEnter != null)
                    {
                        onHoverEnter.Invoke(hit.transform);
                    }
                }

                if (onHover != null)
                {
                    onHover.Invoke(hit.transform);
                }

                lastHit = hit.transform;

                // Handle selection callbacks. An object is selected if the button selecting it was
                // pressed AND released while hovering over the object.

                if (activeController != OVRInput.Controller.None)
                {
                    if (OVRInput.GetDown(secondaryButton, activeController))
                    {
                        secondaryDown = lastHit;
                        //Debug.Log("1");
                    }
                    else if (OVRInput.GetUp(secondaryButton, activeController))
                    {
                        if (secondaryDown != null && secondaryDown == lastHit)
                        {
                            if (onSecondarySelect != null)
                            {
                                onSecondarySelect.Invoke(secondaryDown, pointer);
                                //Debug.Log("2");
                            }
                        }
                    }
                    if (!OVRInput.Get(secondaryButton, activeController))
                    {
                        secondaryDown = null;
                        //Debug.Log("3");
                    }

                    if (OVRInput.GetDown(primaryButton, activeController))
                    {
                        primaryDown = lastHit;
                        //Debug.Log("4");
                    }
                    else if (OVRInput.GetUp(primaryButton, activeController))
                    {
                        if (primaryDown != null && primaryDown == lastHit)
                        {
                            if (onPrimarySelect != null)
                            {
                                onPrimarySelect.Invoke(primaryDown, pointer);
                                //Debug.Log("5");
                            }
                        }
                    }
                    if (!OVRInput.Get(primaryButton, activeController))
                    {
                        primaryDown = null;
                        //Debug.Log("6");
                    }
                }

                if (lastHit)
                {
                    ///
                    if (OVRInput.Get(aButton, activeController))
                    {
                        aDown = lastHit;
                    }
                    else
                    {
                        aDown = null;
                    }
                    if (OVRInput.Get(bButton, activeController))
                    {
                        bDown = lastHit;
                    }
                    else
                    {
                        bDown = null;
                    }
                }



                if (aDown)
                {
                    //Debug.Log("A---->" + aDown);
                    onHoverADown.Invoke(aDown);
                }

                if (bDown)
                {
                    //Debug.Log("B---->" + bDown);
                    onHoverBDown.Invoke(bDown);
                }

                if (primaryDown && !secondaryDown)
                {
                    //Debug.Log(primaryDown);
                    //Debug.Log(axisValue);
                    if (!tractorBeaming)
                    {
                        tractorBeaming           = true;
                        tractorTime              = 0.0f;
                        tractorAxisInputFiltered = 0.0f;
                    }
                    else
                    {
                        tractorTime += Time.deltaTime;
                        if (tractorTime > tractorDelay)
                        {
                            float axisValue = OVRInput.Get(OVRInput.Axis1D.PrimaryIndexTrigger, activeController);
                            tractorAxisInputFiltered = Mathf.Lerp(tractorAxisInputFiltered, axisValue, tractorLerp);
                            onPrimarySelectDownAxis.Invoke(primaryDown, pointer, tractorAxisInputFiltered);
                        }
                    }
                }
                else if (secondaryDown && !primaryDown)
                {
                    //Debug.Log(secondaryDown);
                    //Debug.Log(axisValue);
                    if (!tractorBeaming)
                    {
                        tractorBeaming           = true;
                        tractorTime             += Time.deltaTime;
                        tractorAxisInputFiltered = 0.0f;
                    }
                    else
                    {
                        tractorTime++;
                        if (tractorTime > tractorDelay)
                        {
                            float axisValue = OVRInput.Get(OVRInput.Axis1D.PrimaryHandTrigger, activeController);
                            tractorAxisInputFiltered = Mathf.Lerp(tractorAxisInputFiltered, axisValue, tractorLerp);
                            onSecondarySelectDownAxis.Invoke(secondaryDown, pointer, tractorAxisInputFiltered);
                        }
                    }
                }
                else
                {
                    tractorBeaming = false;
                }

#if UNITY_ANDROID && !UNITY_EDITOR
                // Gaze pointer fallback
                else
                {
                    if (Input.GetMouseButtonDown(0))
                    {
                        triggerDown = lastHit;
                    }
                    else if (Input.GetMouseButtonUp(0))
                    {
                        if (triggerDown != null && triggerDown == lastHit)
                        {
                            if (onPrimarySelect != null)
                            {
                                onPrimarySelect.Invoke(triggerDown);
                            }
                        }
                    }
                    if (!Input.GetMouseButton(0))
                    {
                        triggerDown = null;
                    }
                }
#endif

                //REMOTE GRAB
                if (!remoteGrab)
                {
                    // remoteGrab not set - looking for candidate
                    if (lastHit)
                    {
                        if (primaryDown && secondaryDown)
                        {
                            if (lastHit == primaryDown && lastHit == secondaryDown)
                            {
                                // START remote grabbing
                                //Debug.Log(lastHit + " is candidate for remoteGrab");
                                remoteGrab = lastHit;
                                // initially set remoteGrabTargetDistance to hit.distance
                                remoteGrabTargetDistance = hit.distance;
                                remoteGrabHitOffset      = remoteGrab.position - hit.point;
                                //Debug.Log("   --->" + hit.distance);
                                remoteGrabStartPos  = hit.point;
                                approxMovingAvgPoke = 0f;
                                remoteGrabTime      = 0.0f;

                                remoteGrabObjectStartQ     = remoteGrab.gameObject.transform.rotation;
                                remoteGrabControllerStartQ = OVRInput.GetLocalControllerRotation(activeController);

                                BackboneUnit bu = (remoteGrab.gameObject.GetComponent("BackboneUnit") as BackboneUnit);
                                if (bu != null)
                                {
                                    bu.SetRemoteGrabSelect(true);
                                    //bu.remoteGrabSelectOn = true;
                                    //bu.UpdateRenderMode();
                                }

                                //Rigidbody hitRigidBody = lastHit.gameObject.GetComponent<Rigidbody>();
                                //remoteGrabOffset = hitRigidBody.position - hit.point;
                            }
                        }
                    }
                }
                else
                {
                }
            }
Beispiel #17
0
        void ProcessHandPinch(OVRInput.Controller activeController, Transform lastHit,
                              ref Transform triggerDown, ref Transform padDown, ref Transform tertiaryDown)
        {
            // Handle selection callbacks. An object is selected if the button selecting it was
            // pressed AND released while hovering over the object.
            if ((activeController & OVRInput.Controller.Hands) == OVRInput.Controller.None)
            {
                return;
            }

            if (!OVRPlugin.GetHandTrackingEnabled() || !HandsManager.Instance || !HandsManager.Instance.IsInitialized())
            {
                return;
            }

            if (OVRInputHelpers.IsFingerStartPinching(activeController, tertiaryPinchFinger))
            {
                tertiaryDown = lastHit;
            }
            else if (OVRInputHelpers.IsFingerStopPinching(activeController, tertiaryPinchFinger))
            {
                if (tertiaryDown != null && tertiaryDown == lastHit)
                {
                    if (onTertiarySelect != null)
                    {
                        onTertiarySelect.Invoke(tertiaryDown);
                    }
                }
            }
            else if (!OVRInputHelpers.IsFingerPinching(activeController, tertiaryPinchFinger))
            {
                tertiaryDown = null;
            }

            if (OVRInputHelpers.IsFingerStartPinching(activeController, secondaryPinchFinger))
            {
                padDown = lastHit;
            }
            else if (OVRInputHelpers.IsFingerStopPinching(activeController, secondaryPinchFinger))
            {
                if (padDown != null && padDown == lastHit)
                {
                    if (onSecondarySelect != null)
                    {
                        onSecondarySelect.Invoke(padDown);
                    }
                }
            }
            else if (!OVRInputHelpers.IsFingerPinching(activeController, secondaryPinchFinger))
            {
                padDown = null;
            }

            if (OVRInputHelpers.IsFingerStartPinching(activeController, primaryPinchFinger))
            {
                triggerDown = lastHit;
            }
            else if (OVRInputHelpers.IsFingerStopPinching(activeController, primaryPinchFinger))
            {
                if (triggerDown != null && triggerDown == lastHit)
                {
                    if (onPrimarySelect != null)
                    {
                        onPrimarySelect.Invoke(triggerDown);
                    }
                }
            }
            else if (!OVRInputHelpers.IsFingerPinching(activeController, primaryPinchFinger))
            {
                triggerDown = null;
            }
        }
        void Update()
        {
            activeController = OVRInputHelpers.GetControllerForButton(OVRInput.Button.PrimaryIndexTrigger, activeController);
            Ray pointer = OVRInputHelpers.GetSelectionRay(activeController, trackingSpace);

            RaycastHit hit; // Was anything hit?

            if (Physics.Raycast(pointer, out hit, raycastDistance, ~excludeLayers))
            {
                if (lastHit != null && lastHit != hit.transform) // if we hit a different object, exit hover for old object
                {
                    if (onHoverExit != null)
                    {
                        onHoverExit.Invoke(lastHit);
                    }
                    lastHit = null;
                }

                if (lastHit == null) // we hit something, enter hover
                {
                    if (onHoverEnter != null)
                    {
                        onHoverEnter.Invoke(hit.transform);
                    }
                }

                if (onHover != null) // hover (not enter hover, rather the callback called every time while hovering)
                {
                    onHover.Invoke(hit.transform);
                }

                lastHit = hit.transform;


                if (activeController != OVRInput.Controller.None) // Handle selection callbacks
                {
                    if (OVRInput.GetDown(primaryButton, activeController))
                    {
                        triggerDown = lastHit;

                        if (onSelect != null)
                        {
                            onSelect.Invoke(triggerDown);
                        }
                    }
                }
            }

            else if (lastHit != null) // Nothing was hit, handle exit callback
            {
                if (onHoverExit != null)
                {
                    onHoverExit.Invoke(lastHit);
                }
                lastHit = null;
            }

            if (OVRInput.GetUp(primaryButton, activeController)) // handle deselect
            {
                if (onDeselect != null && triggerDown != null)
                {
                    onDeselect.Invoke(triggerDown);
                    triggerDown = null;
                }
            }
        }
        void Update()
        {
            activeController = OVRInputHelpers.GetControllerForButton(OVRInput.Button.PrimaryIndexTrigger, activeController);
            if (leftPress)
            {
                activeController = OVRInput.Controller.RTouch;
            }
            if (rightPress)
            {
                activeController = OVRInput.Controller.LTouch;
            }
            VisualizerScript.setController(activeController);
            Debug.Log("active controller " + activeController);
            Debug.Log("lpress " + leftPress + ", rightPres " + rightPress);


            Ray pointer = OVRInputHelpers.GetSelectionRay(activeController, trackingSpace);

            RaycastHit hit; // Was anything hit?

            if (Physics.Raycast(pointer, out hit, raycastDistance, ~excludeLayers))
            {
                if (lastHit != null && lastHit != hit.transform) // if we hit a different object, exit hover for old object
                {
                    if (onHoverExit != null)
                    {
                        onHoverExit.Invoke(lastHit, isLeftController(activeController));
                    }
                    lastHit = null;
                }

                if (lastHit == null) // we hit something, enter hover
                {
                    if (onHoverEnter != null)
                    {
                        onHoverEnter.Invoke(hit.transform, isLeftController(activeController));
                    }
                }

                if (onHover != null) // hover (not enter hover, rather the callback called every time while hovering)
                {
                    onHover.Invoke(hit.transform, isLeftController(activeController));
                }

                lastHit = hit.transform;


                if (activeController != OVRInput.Controller.None) // Handle selection callbacks
                {
                    if (OVRInput.GetDown(primaryButton, activeController))
                    {
                        if (isLeftController(activeController))
                        {
                            leftPress             = true;
                            leftSelectedTransform = lastHit;
                        }
                        else
                        {
                            rightPress             = true;
                            rightSelectedTransform = lastHit;
                        }

                        if (onSelect != null && lastHit != null)
                        {
                            onSelect.Invoke(lastHit, isLeftController(activeController));
                        }
                    }
                }
            }

            else if (lastHit != null) // Nothing was hit, handle exit callback
            {
                if (onHoverExit != null)
                {
                    onHoverExit.Invoke(lastHit, isLeftController(activeController));
                }
                lastHit = null;
            }

            if (OVRInput.GetUp(primaryButton, OVRInput.Controller.LTouch)) // handle deselect
            {
                if (onDeselect != null && leftSelectedTransform != null)
                {
                    onDeselect.Invoke(leftSelectedTransform, true);
                    leftSelectedTransform = null;
                    leftPress             = false;
                }
            }
            if (OVRInput.GetUp(primaryButton, OVRInput.Controller.RTouch)) // handle deselect
            {
                if (onDeselect != null && rightSelectedTransform != null)
                {
                    onDeselect.Invoke(rightSelectedTransform, false);
                    rightSelectedTransform = null;
                    rightPress             = false;
                }
            }
        }
Beispiel #20
0
        void Update()
        {
            activeController = OVRInputHelpers.GetControllerForButton(OVRInput.Button.PrimaryIndexTrigger, activeController);
            Ray pointer = OVRInputHelpers.GetSelectionRay(activeController, trackingSpace);

            RaycastHit hit; // Was anything hit?

            if (Physics.Raycast(pointer, out hit, raycastDistance, ~excludeLayers))
            {
                if (lastHit != null && lastHit != hit.transform)
                {
                    if (onHoverExit != null)
                    {
                        onHoverExit.Invoke(lastHit);
                    }
                    lastHit = null;
                }

                if (lastHit == null)
                {
                    if (onHoverEnter != null)
                    {
                        onHoverEnter.Invoke(hit.transform);
                    }
                }

                if (onHover != null)
                {
                    onHover.Invoke(hit.transform);
                    if (OVRInput.Get(OVRInput.Button.Two))
                    {
                        print("Terrain touche !");
                        tempFile = hit.transform.GetComponent <createTerrain>();

                        if (_outils == OutilsChoix.MONTER)
                        {
                            tempFile.ModifPosY(hit.point, forcePointer, sizePointer);
                        }
                        else if (_outils == OutilsChoix.DESCENDRE)
                        {
                            tempFile.ModifPosY(hit.point, -forcePointer, sizePointer);
                        }
                    }
                }

                lastHit = hit.transform;

                // Handle selection callbacks. An object is selected if the button selecting it was
                // pressed AND released while hovering over the object.
                if (activeController != OVRInput.Controller.None)
                {
                    if (OVRInput.GetDown(secondaryButton, activeController))
                    {
                        padDown = lastHit;
                    }
                    else if (OVRInput.GetUp(secondaryButton, activeController))
                    {
                        if (padDown != null && padDown == lastHit)
                        {
                            if (onSecondarySelect != null)
                            {
                                onSecondarySelect.Invoke(padDown);
                            }
                        }
                    }
                    if (!OVRInput.Get(secondaryButton, activeController))
                    {
                        padDown = null;
                    }

                    if (OVRInput.GetDown(primaryButton, activeController))
                    {
                        triggerDown = lastHit;
                    }
                    else if (OVRInput.GetUp(primaryButton, activeController))
                    {
                        if (triggerDown != null && triggerDown == lastHit)
                        {
                            if (onPrimarySelect != null)
                            {
                                onPrimarySelect.Invoke(triggerDown);
                            }
                        }
                    }
                    if (!OVRInput.Get(primaryButton, activeController))
                    {
                        triggerDown = null;
                    }
                }
#if UNITY_ANDROID && !UNITY_EDITOR
                // Gaze pointer fallback
                else
                {
                    if (Input.GetMouseButtonDown(0))
                    {
                        triggerDown = lastHit;
                    }
                    else if (Input.GetMouseButtonUp(0))
                    {
                        if (triggerDown != null && triggerDown == lastHit)
                        {
                            if (onPrimarySelect != null)
                            {
                                onPrimarySelect.Invoke(triggerDown);
                            }
                        }
                    }
                    if (!Input.GetMouseButton(0))
                    {
                        triggerDown = null;
                    }
                }
#endif
            }
            // Nothing was hit, handle exit callback
            else if (lastHit != null)
            {
                if (onHoverExit != null)
                {
                    onHoverExit.Invoke(lastHit);
                }
                lastHit = null;
            }
        }