Input() public static method

public static Input ( int deviceIndex ) : Device,
deviceIndex int
return Device,
Exemplo n.º 1
0
    void Update()
    {
#if UNITY_EDITOR
        if (!Application.isPlaying)
        {
            // See if anything has changed since this gets called whenever anything gets touched.
            var fields = GetType().GetFields(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public);

            bool modified = false;

            if (values == null)
            {
                modified = true;
            }
            else
            {
                foreach (var f in fields)
                {
                    if (!values.Contains(f) || !f.GetValue(this).Equals(values[f]))
                    {
                        modified = true;
                        break;
                    }
                }
            }

            if (modified)
            {
                SetModel(modelOverride);

                values = new Hashtable();
                foreach (var f in fields)
                {
                    values[f] = f.GetValue(this);
                }
            }

            return;             // Do not update transforms (below) when not playing in Editor (to avoid keeping OpenVR running all the time).
        }
#endif
        // Update component transforms dynamically.
        if (updateDynamically)
        {
            using (var holder = new RenderModelInterfaceHolder())
            {
                var controllerState = SteamVR_Controller.Input((int)index).GetState();

                var t             = transform;
                var baseTransform = new SteamVR_Utils.RigidTransform(t);

                for (int i = 0; i < t.childCount; i++)
                {
                    var child = t.GetChild(i);

                    var renderModels = holder.instance;
                    if (renderModels == null)
                    {
                        break;
                    }

                    var componentState = new RenderModel_ComponentState_t();
                    if (!renderModels.GetComponentState(renderModelName, child.name, ref controllerState, ref componentState))
                    {
                        continue;
                    }

                    var componentTransform = new SteamVR_Utils.RigidTransform(componentState.mTrackingToComponentRenderModel);
                    child.localPosition = componentTransform.pos;
                    child.localRotation = componentTransform.rot;

                    var attach = child.FindChild(k_localTransformName);
                    if (attach != null)
                    {
                        var attachTransform = baseTransform * new SteamVR_Utils.RigidTransform(componentState.mTrackingToComponentLocal);
                        attach.position = attachTransform.pos;
                        attach.rotation = attachTransform.rot;
                    }

                    bool visible = (componentState.uProperties & (uint)EVRComponentProperty.VRComponentProperty_IsVisible) != 0;
                    if (visible != child.gameObject.activeSelf)
                    {
                        child.gameObject.SetActive(visible);
                    }
                }
            }
        }
    }
Exemplo n.º 2
0
    // Corourtine to handle all the steps across loading boundaries.
    IEnumerator LoadLevel()
    {
        // Optionally rotate loading screen transform around the camera into view.
        // We assume here that the loading screen is already facing toward the origin,
        // and that the progress bar transform (if any) is a child and will follow along.
        if (loadingScreen != null && loadingScreenDistance > 0.0f)
        {
            // Wait until we have tracking.
            var hmd = SteamVR_Controller.Input((int)OpenVR.k_unTrackedDeviceIndex_Hmd);
            while (!hmd.hasTracking)
            {
                yield return(null);
            }

            var tloading = hmd.transform;
            tloading.rot  = Quaternion.Euler(0.0f, tloading.rot.eulerAngles.y, 0.0f);
            tloading.pos += tloading.rot * new Vector3(0.0f, 0.0f, loadingScreenDistance);

            var t = loadingScreenTransform != null ? loadingScreenTransform : transform;
            t.position = tloading.pos;
            t.rotation = tloading.rot;
        }

        _active = this;

        SteamVR_Events.Loading.Send(true);

        // Calculate rate for fading in loading screen and progress bar.
        if (loadingScreenFadeInTime > 0.0f)
        {
            fadeRate = 1.0f / loadingScreenFadeInTime;
        }
        else
        {
            alpha = 1.0f;
        }

        var overlay = OpenVR.Overlay;

        // Optionally create our loading screen overlay.
        if (loadingScreen != null && overlay != null)
        {
            loadingScreenOverlayHandle = GetOverlayHandle("loadingScreen", loadingScreenTransform != null ? loadingScreenTransform : transform, loadingScreenWidthInMeters);
            if (loadingScreenOverlayHandle != OpenVR.k_ulOverlayHandleInvalid)
            {
                var texture = new Texture_t();
                texture.handle      = loadingScreen.GetNativeTexturePtr();
                texture.eType       = SteamVR.instance.textureType;
                texture.eColorSpace = EColorSpace.Auto;
                overlay.SetOverlayTexture(loadingScreenOverlayHandle, ref texture);
            }
        }

        bool fadedForeground = false;

        // Fade out to compositor
        SteamVR_Events.LoadingFadeOut.Send(fadeOutTime);

        // Optionally set a skybox to use as a backdrop in the compositor.
        var compositor = OpenVR.Compositor;

        if (compositor != null)
        {
            if (front != null)
            {
                SteamVR_Skybox.SetOverride(front, back, left, right, top, bottom);

                // Explicitly fade to the compositor since loading will cause us to stop rendering.
                compositor.FadeGrid(fadeOutTime, true);
                yield return(new WaitForSeconds(fadeOutTime));
            }
            else if (backgroundColor != Color.clear)
            {
                // Otherwise, use the specified background color.
                if (showGrid)
                {
                    // Set compositor background color immediately, and start fading to it.
                    compositor.FadeToColor(0.0f, backgroundColor.r, backgroundColor.g, backgroundColor.b, backgroundColor.a, true);
                    compositor.FadeGrid(fadeOutTime, true);
                    yield return(new WaitForSeconds(fadeOutTime));
                }
                else
                {
                    // Fade the foreground color in (which will blend on top of the scene), and then cut to the compositor.
                    compositor.FadeToColor(fadeOutTime, backgroundColor.r, backgroundColor.g, backgroundColor.b, backgroundColor.a, false);
                    yield return(new WaitForSeconds(fadeOutTime + 0.1f));

                    compositor.FadeGrid(0.0f, true);
                    fadedForeground = true;
                }
            }
        }

        // Now that we're fully faded out, we can stop submitting frames to the compositor.
        SteamVR_Render.pauseRendering = true;

        // Continue waiting for the overlays to fully fade in before continuing.
        while (alpha < 1.0f)
        {
            yield return(null);
        }

        // Keep us from getting destroyed when loading the new level, otherwise this coroutine will get stopped prematurely.
        transform.parent = null;
        DontDestroyOnLoad(gameObject);

        if (!string.IsNullOrEmpty(internalProcessPath))
        {
            Debug.Log("Launching external application...");
            var applications = OpenVR.Applications;
            if (applications == null)
            {
                Debug.Log("Failed to get OpenVR.Applications interface!");
            }
            else
            {
                var workingDirectory = Directory.GetCurrentDirectory();
                var fullPath         = Path.Combine(workingDirectory, internalProcessPath);
                Debug.Log("LaunchingInternalProcess");
                Debug.Log("ExternalAppPath = " + internalProcessPath);
                Debug.Log("FullPath = " + fullPath);
                Debug.Log("ExternalAppArgs = " + internalProcessArgs);
                Debug.Log("WorkingDirectory = " + workingDirectory);
                var error = applications.LaunchInternalProcess(fullPath, internalProcessArgs, workingDirectory);
                Debug.Log("LaunchInternalProcessError: " + error);
#if UNITY_EDITOR
                UnityEditor.EditorApplication.isPlaying = false;
#elif !UNITY_METRO
                System.Diagnostics.Process.GetCurrentProcess().Kill();
#endif
            }
        }
        else
        {
            var mode = loadAdditive ? UnityEngine.SceneManagement.LoadSceneMode.Additive : UnityEngine.SceneManagement.LoadSceneMode.Single;
            if (loadAsync)
            {
                Application.backgroundLoadingPriority = ThreadPriority.Low;
                async = UnityEngine.SceneManagement.SceneManager.LoadSceneAsync(levelName, mode);

                // Performing this in a while loop instead seems to help smooth things out.
                //yield return async;
                while (!async.isDone)
                {
                    yield return(null);
                }
            }
            else
            {
                UnityEngine.SceneManagement.SceneManager.LoadScene(levelName, mode);
            }
        }

        yield return(null);

        System.GC.Collect();

        yield return(null);

        Shader.WarmupAllShaders();

        // Optionally wait a short period of time after loading everything back in, but before we start rendering again
        // in order to give everything a change to settle down to avoid any hitching at the start of the new level.
        yield return(new WaitForSeconds(postLoadSettleTime));

        SteamVR_Render.pauseRendering = false;

        // Fade out loading screen.
        if (loadingScreenFadeOutTime > 0.0f)
        {
            fadeRate = -1.0f / loadingScreenFadeOutTime;
        }
        else
        {
            alpha = 0.0f;
        }

        // Fade out to compositor
        SteamVR_Events.LoadingFadeIn.Send(fadeInTime);

        if (compositor != null)
        {
            // Fade out foreground color if necessary.
            if (fadedForeground)
            {
                compositor.FadeGrid(0.0f, false);
                compositor.FadeToColor(fadeInTime, 0.0f, 0.0f, 0.0f, 0.0f, false);
                yield return(new WaitForSeconds(fadeInTime));
            }
            else
            {
                // Fade scene back in, and reset skybox once no longer visible.
                compositor.FadeGrid(fadeInTime, false);
                yield return(new WaitForSeconds(fadeInTime));

                if (front != null)
                {
                    SteamVR_Skybox.ClearOverride();
                }
            }
        }

        // Finally, stick around long enough for our overlays to fully fade out.
        while (alpha > 0.0f)
        {
            yield return(null);
        }

        if (overlay != null)
        {
            if (progressBarOverlayHandle != OpenVR.k_ulOverlayHandleInvalid)
            {
                overlay.HideOverlay(progressBarOverlayHandle);
            }
            if (loadingScreenOverlayHandle != OpenVR.k_ulOverlayHandleInvalid)
            {
                overlay.HideOverlay(loadingScreenOverlayHandle);
            }
        }

        Destroy(gameObject);

        _active = null;

        SteamVR_Events.Loading.Send(false);
    }
Exemplo n.º 3
0
 void FixedUpdate()
 {
     device = SteamVR_Controller.Input((int)trackedObj.index);
 }
 void FixedUpdate()
 {
     device = SteamVR_Controller.Input((int)trackedObj.index);
     animator.SetBool("isGrabbing", device.GetPress(SteamVR_Controller.ButtonMask.Trigger));
 }
Exemplo n.º 5
0
    // Update is called once per frame
    void Update()
    {
        device = SteamVR_Controller.Input((int)trackedObj.index);

        // Teleport Controls
        if (device.GetPress(SteamVR_Controller.ButtonMask.Touchpad))
        {
            laser.gameObject.SetActive(true);
            teleportAimerObject.SetActive(true);

            //set start pos of laser
            laser.SetPosition(0, gameObject.transform.position);
            RaycastHit hit;
            if (Physics.Raycast(transform.position, transform.forward, out hit, 15, laserMask))
            {
                if (hit.transform.gameObject.layer == 8) // if layer is "walkable"
                {
                    teleportLocation = hit.point;
                    laser.SetPosition(1, teleportLocation);
                    //aimer position
                    teleportAimerObject.transform.position = new Vector3(teleportLocation.x, teleportLocation.y + yNudgeAmount, teleportLocation.z);
                }
                else if (hit.transform.gameObject.layer == 9) // layer is "stopTeleporter"
                {
                    laser.SetPosition(1, hit.point);
                    teleportAimerObject.transform.position = new Vector3(hit.point.x, 0.0f, hit.point.z);
                    teleportLocation = Vector3.zero;
                }
            }
            else
            {
                teleportLocation = new Vector3(transform.forward.x * 15 + transform.position.x, transform.forward.y * 15 + transform.position.y, transform.forward.z * 15 + transform.position.z);
                RaycastHit groundRay;
                if (Physics.Raycast(teleportLocation, -Vector3.up, out groundRay, 17, laserMask))
                {
                    teleportLocation = new Vector3(transform.forward.x * 15 + transform.position.x, groundRay.point.y, transform.forward.z * 15 + transform.position.z);
                    //aimer position
                    teleportAimerObject.transform.position = teleportLocation + new Vector3(0, yNudgeAmount, 0);
                    laser.SetPosition(1, teleportAimerObject.transform.position);
                }
                else
                {
                    teleportLocation = Vector3.zero;
                }
            }
        }
        if (device.GetPressUp(SteamVR_Controller.ButtonMask.Touchpad))
        {
            if (teleportLocation != Vector3.zero)
            {
                laser.gameObject.SetActive(false);
                teleportAimerObject.SetActive(false);
                player.transform.position = teleportLocation;
            }
            else
            {
                laser.gameObject.SetActive(false);
                teleportAimerObject.SetActive(false);
                player.transform.position = player.transform.position;
            }
        }
    }
Exemplo n.º 6
0
 private void SetDeviceIndex(int index)
 {
     DeviceIndex = index;
     Controller  = SteamVR_Controller.Input(index);
     StartCoroutine(DoInitialize());
 }
Exemplo n.º 7
0
 protected override bool MenuClickPressedDown()
 {
     return(SteamVR_Controller.Input(PointerController.ControlIndex).GetPressDown(SteamVR_Controller.ButtonMask.Trigger));
 }
Exemplo n.º 8
0
    // Update is called once per frame
    void Update()
    {
        /* get Transform informations from [GameObject] */
        // left
        if (left != null)
        {
            leftControllerPosition = left.transform.position;
            leftControllerRotation = left.transform.rotation;
        }
        // right

        if (right != null)
        {
            rightControllerPosition = right.transform.position;
            rightControllerRotation = right.transform.rotation;
        }

        /*
         * get Active informations from [SteamVR_TrackedObject]
         * and if Active, get Device informations using index of [SteamVR_TrackedObject]
         */
        // left
        if (leftObject != null)
        {
            leftControllerActive = (leftObject.index != SteamVR_TrackedObject.EIndex.None);
            leftDevice           = leftControllerActive ? SteamVR_Controller.Input((int)leftObject.index) : null;
        }
        else
        {
            leftControllerActive = false;
            leftDevice           = null;
        }
        // right
        if (rightObject != null)
        {
            rightControllerActive = (rightObject.index != SteamVR_TrackedObject.EIndex.None);
            rightDevice           = rightControllerActive ? SteamVR_Controller.Input((int)rightObject.index) : null;
        }
        else
        {
            rightControllerActive = false;
            rightDevice           = null;
        }
        // get Buttom/Axis informations from [SteamVR_TrackedObject]
        // left
        if (leftDevice != null)
        {
            Debug.Log("test");
            leftControllerTouchDown.applicationMenu = GetTouchDown(leftDevice, SteamVR_Controller.ButtonMask.ApplicationMenu);
            leftControllerTouchDown.touchpad        = GetTouchDown(leftDevice, SteamVR_Controller.ButtonMask.Touchpad);
            leftControllerTouchDown.system          = GetTouchDown(leftDevice, SteamVR_Controller.ButtonMask.System);
            leftControllerTouchDown.trigger         = GetTouchDown(leftDevice, SteamVR_Controller.ButtonMask.Trigger);
            leftControllerTouchDown.grip            = leftDevice.GetPress(SteamVR_Controller.ButtonMask.Grip);  //GetTouchDown(leftDevice, SteamVR_Controller.ButtonMask.Grip);
            leftTouchpadAxis = GetAxis(leftDevice, Valve.VR.EVRButtonId.k_EButton_Axis0);
            leftTriggerAxis  = GetAxis(leftDevice, Valve.VR.EVRButtonId.k_EButton_SteamVR_Trigger);
        }
        else
        {
            leftControllerTouchDown.applicationMenu = false;
            leftControllerTouchDown.touchpad        = false;
            leftControllerTouchDown.system          = false;
            leftControllerTouchDown.trigger         = false;
            leftControllerTouchDown.grip            = false;
            leftTouchpadAxis = new Vector2(0, 0);
            leftTriggerAxis  = new Vector2(0, 0);
        }
        // right
        if (rightDevice != null)
        {
            rightControllerTouchDown.applicationMenu = GetTouchDown(rightDevice, SteamVR_Controller.ButtonMask.ApplicationMenu);
            rightControllerTouchDown.touchpad        = GetTouchDown(rightDevice, SteamVR_Controller.ButtonMask.Touchpad);
            rightControllerTouchDown.system          = GetTouchDown(rightDevice, SteamVR_Controller.ButtonMask.System);
            rightControllerTouchDown.trigger         = GetTouchDown(rightDevice, SteamVR_Controller.ButtonMask.Trigger);
            rightControllerTouchDown.grip            = GetTouchDown(rightDevice, SteamVR_Controller.ButtonMask.Grip);
            rightTouchpadAxis = GetAxis(rightDevice, Valve.VR.EVRButtonId.k_EButton_Axis0);
            rightTriggerAxis  = GetAxis(rightDevice, Valve.VR.EVRButtonId.k_EButton_SteamVR_Trigger);
        }
        else
        {
            rightControllerTouchDown.applicationMenu = false;
            rightControllerTouchDown.touchpad        = false;
            rightControllerTouchDown.system          = false;
            rightControllerTouchDown.trigger         = false;
            rightControllerTouchDown.grip            = false;
            rightTouchpadAxis = new Vector2(0, 0);
            rightTriggerAxis  = new Vector2(0, 0);
        }
    }
Exemplo n.º 9
0
 private bool trigger(int index)
 {
     return(index > 0 && SteamVR_Controller.Input(index).GetPress(SteamVR_Controller.ButtonMask.Trigger));
 }
Exemplo n.º 10
0
    // Update is called once per frame
    void Update()
    {
        var device = SteamVR_Controller.Input((int)trackedObj.index);

        // Touch down, possible chance for a swipe
        if ((int)trackedObj.index != -1 && device.GetTouchDown(Valve.VR.EVRButtonId.k_EButton_Axis0))
        {
            trackingSwipe = true;
            // Record start time and position
            mStartPosition = new Vector2(device.GetAxis(Valve.VR.EVRButtonId.k_EButton_Axis0).x,
                                         device.GetAxis(Valve.VR.EVRButtonId.k_EButton_Axis0).y);
            mSwipeStartTime = Time.time;
        }
        // Touch up , possible chance for a swipe
        else if (device.GetTouchUp(Valve.VR.EVRButtonId.k_EButton_Axis0))
        {
            trackingSwipe = false;
            trackingSwipe = true;
            checkSwipe    = true;
            //Debug.Log("Tracking Finish");
        }
        else if (trackingSwipe)
        {
            endPosition = new Vector2(device.GetAxis(Valve.VR.EVRButtonId.k_EButton_Axis0).x,
                                      device.GetAxis(Valve.VR.EVRButtonId.k_EButton_Axis0).y);
        }

        if (checkSwipe)
        {
            checkSwipe = false;

            float   deltaTime   = Time.time - mSwipeStartTime;
            Vector2 swipeVector = endPosition - mStartPosition;

            float velocity = swipeVector.magnitude / deltaTime;

            if (velocity > mMinVelocity &&
                swipeVector.magnitude > mMinSwipeDist)
            {
                swipeVector.Normalize();

                float angleOfSwipe = Vector2.Dot(swipeVector, mXAxis);
                angleOfSwipe = Mathf.Acos(angleOfSwipe) * Mathf.Rad2Deg;

                SwipeEventArgs eventArgs = new SwipeEventArgs();
                eventArgs.velocity  = velocity;
                eventArgs.magnitude = swipeVector.magnitude;
                eventArgs.angle     = angleOfSwipe;

                if (angleOfSwipe < mAngleRange)
                {
                    SwipedRight(this, new SwipeEventArgs());
                }
                else if ((180.0f - angleOfSwipe) < mAngleRange)
                {
                    SwipedLeft(this, new SwipeEventArgs());
                }
                else
                {
                    angleOfSwipe = Vector2.Dot(swipeVector, mYAxis);
                    angleOfSwipe = Mathf.Acos(angleOfSwipe) * Mathf.Rad2Deg;
                    if (angleOfSwipe < mAngleRange)
                    {
                        //SwipedUp(this, new SwipeEventArgs());
                    }
                    else if ((180.0f - angleOfSwipe) < mAngleRange)
                    {
                        //SwipedDown(this, new SwipeEventArgs());
                    }
                }
            }
        }
    }
Exemplo n.º 11
0
 public void SetDeviceIndex(int index)
 {
     this.index = index;
     controller = SteamVR_Controller.Input((int)index);
 }
    // Update is called once per frame
    void FixedUpdate()
    {
        device = SteamVR_Controller.Input((int)trackedObject.index);

        if (tollary.GetComponent <Tmove>().touch == 0)
        {
            if (controller.padPressed)
            {
                float x = device.GetAxis().x;
                float y = device.GetAxis().y;

                Vector3 forward;

                if (x != 0 || y != 0)
                {
                    int areaTag = area(x, y);

                    if (areaTag == 1 || areaTag == 3)
                    {
                        forward = controller.transform.TransformDirection(Vector3.forward);
                        float curSpeed = m_Speed * y;
                        player.SimpleMove(forward * curSpeed);
                    }
                    else if (areaTag == 2 || areaTag == 4)
                    {
                        player.transform.Rotate(0, x * m_TurnSpeed, 0);
                    }
                }

                step = 1;
                if (record == false)
                {
                    //time = System.DateTime.Now;
                    elapsedTime = new TimeSpan(DateTime.Now.Ticks);
                    record      = true;
                }
                TimeSpan ts2 = new TimeSpan(DateTime.Now.Ticks);
                TimeSpan ts  = ts2.Subtract(elapsedTime).Duration();

                if (record == true && ts.Seconds >= 1)
                {
                    if (tollary.GetComponent <Tmove>().touch == 0)
                    {
                        if (HistoryPos.Count > 5)
                        {
                            HistoryPos.RemoveAt(0);
                            HistoryRot.RemoveAt(0);
                        }

                        position = controller.GetComponent <Transform>().position;
                        //position.y = 0.5f;
                        Quaternion rot = transform.rotation;

                        HistoryPos.Add(position);
                        HistoryRot.Add(rot);
                        Debug.Log("记录在位置 " + HistoryPos.Count);

                        record = false;
                    }
                }
            }
        }
        else
        {
            if (HistoryPos.Count > 0)
            {
                Debug.Log("循环论多少遍啊" + step);
                int index = HistoryPos.Count - step;
                if (index < 0)
                {
                    step = 1; index = HistoryPos.Count - step;
                }
                Vector3 temp = HistoryPos[index];
                temp.y = -0.3f;
                player.GetComponent <Transform>().position = temp;
            }
            if (HistoryRot.Count > 0)
            {
                int index = HistoryRot.Count - step;
                this.transform.rotation = HistoryRot[index];
            }
            //Debug.Log("循环多少遍啊" + step);
            if (step < 5)
            {
                step++;
            }
        }
    }
Exemplo n.º 13
0
        private void Update()
        {
            controllerIndex = (uint)trackedController.index;
            //Only continue if the controller index has been set to a sensible number
            //SteamVR seems to put the index to the uint max value if it can't find the controller
            if (controllerIndex >= uint.MaxValue)
            {
                return;
            }

            device = SteamVR_Controller.Input((int)controllerIndex);

            Vector2 currentTriggerAxis  = device.GetAxis(Valve.VR.EVRButtonId.k_EButton_SteamVR_Trigger);
            Vector2 currentTouchpadAxis = device.GetAxis();

            //Trigger Pressed
            if (device.GetPressDown(SteamVR_Controller.ButtonMask.Trigger))
            {
                OnTriggerPressed(SetButtonEvent(ref triggerPressed, true, currentTriggerAxis.x));
                EmitAlias(ButtonAlias.Trigger_Press, true, currentTriggerAxis.x, ref triggerPressed);
            }
            else if (device.GetPressUp(SteamVR_Controller.ButtonMask.Trigger))
            {
                OnTriggerReleased(SetButtonEvent(ref triggerPressed, false, 0f));
                EmitAlias(ButtonAlias.Trigger_Press, false, 0f, ref triggerPressed);
            }

            //Trigger Touched
            if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Trigger))
            {
                OnTriggerTouchStart(SetButtonEvent(ref triggerTouched, true, currentTriggerAxis.x));
                EmitAlias(ButtonAlias.Trigger_Touch, true, currentTriggerAxis.x, ref triggerTouched);
            }
            else if (device.GetTouchUp(SteamVR_Controller.ButtonMask.Trigger))
            {
                OnTriggerTouchEnd(SetButtonEvent(ref triggerTouched, false, 0f));
                EmitAlias(ButtonAlias.Trigger_Touch, false, 0f, ref triggerTouched);
            }

            //Trigger Hairline
            if (device.GetHairTriggerDown())
            {
                OnTriggerHairlineStart(SetButtonEvent(ref triggerHairlinePressed, true, currentTriggerAxis.x));
                EmitAlias(ButtonAlias.Trigger_Hairline, true, currentTriggerAxis.x, ref triggerHairlinePressed);
            }
            else if (device.GetHairTriggerUp())
            {
                OnTriggerHairlineEnd(SetButtonEvent(ref triggerHairlinePressed, false, 0f));
                EmitAlias(ButtonAlias.Trigger_Hairline, false, 0f, ref triggerHairlinePressed);
            }

            //Trigger Clicked
            if (!triggerClicked && currentTriggerAxis.x == 1f)
            {
                OnTriggerClicked(SetButtonEvent(ref triggerClicked, true, currentTriggerAxis.x));
                EmitAlias(ButtonAlias.Trigger_Click, true, currentTriggerAxis.x, ref triggerClicked);
            }
            else if (triggerClicked && currentTriggerAxis.x < 1f)
            {
                OnTriggerUnclicked(SetButtonEvent(ref triggerClicked, false, 0f));
                EmitAlias(ButtonAlias.Trigger_Click, false, 0f, ref triggerClicked);
            }

            //Trigger Axis
            if (Vector2ShallowEquals(triggerAxis, currentTriggerAxis))
            {
                triggerAxisChanged = false;
            }
            else
            {
                OnTriggerAxisChanged(SetButtonEvent(ref triggerAxisChanged, true, currentTriggerAxis.x));
            }

            //ApplicationMenu
            if (device.GetPressDown(SteamVR_Controller.ButtonMask.ApplicationMenu))
            {
                OnApplicationMenuPressed(SetButtonEvent(ref applicationMenuPressed, true, 1f));
                EmitAlias(ButtonAlias.Application_Menu, true, 1f, ref applicationMenuPressed);
            }
            else if (device.GetPressUp(SteamVR_Controller.ButtonMask.ApplicationMenu))
            {
                OnApplicationMenuReleased(SetButtonEvent(ref applicationMenuPressed, false, 0f));
                EmitAlias(ButtonAlias.Application_Menu, false, 0f, ref applicationMenuPressed);
            }

            //Grip
            if (device.GetPressDown(SteamVR_Controller.ButtonMask.Grip))
            {
                OnGripPressed(SetButtonEvent(ref gripPressed, true, 1f));
                EmitAlias(ButtonAlias.Grip, true, 1f, ref gripPressed);
            }
            else if (device.GetPressUp(SteamVR_Controller.ButtonMask.Grip))
            {
                OnGripReleased(SetButtonEvent(ref gripPressed, false, 0f));
                EmitAlias(ButtonAlias.Grip, false, 0f, ref gripPressed);
            }

            //Touchpad Pressed
            if (device.GetPressDown(SteamVR_Controller.ButtonMask.Touchpad))
            {
                OnTouchpadPressed(SetButtonEvent(ref touchpadPressed, true, 1f));
                EmitAlias(ButtonAlias.Touchpad_Press, true, 1f, ref touchpadPressed);
            }
            else if (device.GetPressUp(SteamVR_Controller.ButtonMask.Touchpad))
            {
                OnTouchpadReleased(SetButtonEvent(ref touchpadPressed, false, 0f));
                EmitAlias(ButtonAlias.Touchpad_Press, false, 0f, ref touchpadPressed);
            }

            //Touchpad Touched
            if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Touchpad))
            {
                OnTouchpadTouchStart(SetButtonEvent(ref touchpadTouched, true, 1f));
                EmitAlias(ButtonAlias.Touchpad_Touch, true, 1f, ref touchpadTouched);
            }
            else if (device.GetTouchUp(SteamVR_Controller.ButtonMask.Touchpad))
            {
                OnTouchpadTouchEnd(SetButtonEvent(ref touchpadTouched, false, 0f));
                EmitAlias(ButtonAlias.Touchpad_Touch, false, 0f, ref touchpadTouched);
            }

            if (Vector2ShallowEquals(touchpadAxis, currentTouchpadAxis))
            {
                touchpadAxisChanged = false;
            }
            else
            {
                OnTouchpadAxisChanged(SetButtonEvent(ref touchpadTouched, true, 1f));
                touchpadAxisChanged = true;
            }

            // Save current touch and trigger settings to detect next change.
            touchpadAxis     = new Vector2(currentTouchpadAxis.x, currentTouchpadAxis.y);
            triggerAxis      = new Vector2(currentTriggerAxis.x, currentTriggerAxis.y);
            hairTriggerDelta = device.hairTriggerDelta;
        }
Exemplo n.º 14
0
        private void DisableEvents()
        {
            if (triggerPressed)
            {
                OnTriggerReleased(SetButtonEvent(ref triggerPressed, false, 0f));
                EmitAlias(ButtonAlias.Trigger_Press, false, 0f, ref triggerPressed);
            }

            if (triggerTouched)
            {
                OnTriggerTouchEnd(SetButtonEvent(ref triggerTouched, false, 0f));
                EmitAlias(ButtonAlias.Trigger_Touch, false, 0f, ref triggerTouched);
            }

            if (triggerHairlinePressed)
            {
                OnTriggerHairlineEnd(SetButtonEvent(ref triggerHairlinePressed, false, 0f));
                EmitAlias(ButtonAlias.Trigger_Hairline, false, 0f, ref triggerHairlinePressed);
            }

            if (triggerClicked)
            {
                OnTriggerUnclicked(SetButtonEvent(ref triggerClicked, false, 0f));
                EmitAlias(ButtonAlias.Trigger_Click, false, 0f, ref triggerClicked);
            }

            if (applicationMenuPressed)
            {
                OnApplicationMenuReleased(SetButtonEvent(ref applicationMenuPressed, false, 0f));
                EmitAlias(ButtonAlias.Application_Menu, false, 0f, ref applicationMenuPressed);
            }

            if (gripPressed)
            {
                OnGripReleased(SetButtonEvent(ref gripPressed, false, 0f));
                EmitAlias(ButtonAlias.Grip, false, 0f, ref gripPressed);
            }

            if (touchpadPressed)
            {
                OnTouchpadReleased(SetButtonEvent(ref touchpadPressed, false, 0f));
                EmitAlias(ButtonAlias.Touchpad_Press, false, 0f, ref touchpadPressed);
            }

            if (touchpadTouched)
            {
                OnTouchpadTouchEnd(SetButtonEvent(ref touchpadTouched, false, 0f));
                EmitAlias(ButtonAlias.Touchpad_Touch, false, 0f, ref touchpadTouched);
            }

            triggerAxisChanged  = false;
            touchpadAxisChanged = false;

            controllerIndex = (uint)trackedController.index;
            if (controllerIndex < uint.MaxValue)
            {
                device = SteamVR_Controller.Input((int)controllerIndex);

                Vector2 currentTriggerAxis  = device.GetAxis(Valve.VR.EVRButtonId.k_EButton_SteamVR_Trigger);
                Vector2 currentTouchpadAxis = device.GetAxis();

                // Save current touch and trigger settings to detect next change.
                touchpadAxis     = new Vector2(currentTouchpadAxis.x, currentTouchpadAxis.y);
                triggerAxis      = new Vector2(currentTriggerAxis.x, currentTriggerAxis.y);
                hairTriggerDelta = device.hairTriggerDelta;
            }
        }
Exemplo n.º 15
0
    void Update()
    {
        // If we are currently teleporting (ie handling the fade in/out transition)...
        if (CurrentTeleportState == TeleportState.Teleporting)
        {
            // Wait until half of the teleport time has passed before the next event (note: both the switch from fade
            // out to fade in and the switch from fade in to stop the animation is half of the fade duration)
            if (Time.time - TeleportTimeMarker >= TeleportFadeDuration / 2)
            {
                if (FadingIn)
                {
                    // We have finished fading in
                    CurrentTeleportState = TeleportState.None;
                }
                else
                {
                    // We have finished fading out - time to teleport!
                    Vector3 offset = OriginTransform.position - HeadTransform.position;
                    offset.y = 0;
                    OriginTransform.position = Pointer.SelectedPoint + offset;
                }

                TeleportTimeMarker = Time.time;
                FadingIn           = !FadingIn;
            }
        }
        // At this point, we are NOT actively teleporting.  So now we care about controller input.
        else if (CurrentTeleportState == TeleportState.Selecting)
        {
            Debug.Assert(ActiveController != null);

            // Here, there is an active controller - that is, the user is holding down on the trackpad.
            // Poll controller for pertinent button data
            int  index          = (int)ActiveController.index;
            var  device         = SteamVR_Controller.Input(index);
            bool shouldTeleport = device.GetPressUp(SteamVR_Controller.ButtonMask.Touchpad);
            bool shouldCancel   = device.GetPressUp(SteamVR_Controller.ButtonMask.Grip);
            if (shouldTeleport || shouldCancel)
            {
                // If the user has decided to teleport (ie lets go of touchpad) then remove all visual indicators
                // related to selecting things and actually teleport
                // If the user has decided to cancel (ie squeezes grip button) then remove visual indicators and do nothing
                if (shouldTeleport && Pointer.PointOnNavMesh)
                {
                    // Begin teleport sequence
                    CurrentTeleportState = TeleportState.Teleporting;
                    TeleportTimeMarker   = Time.time;
                }
                else
                {
                    CurrentTeleportState = TeleportState.None;
                }

                // Reset active controller, disable pointer, disable visual indicators
                ActiveController   = null;
                Pointer.enabled    = false;
                RoomBorder.enabled = false;
                //RoomBorder.Transpose = Matrix4x4.TRS(OriginTransform.position, Quaternion.identity, Vector3.one);
                if (NavmeshAnimator != null)
                {
                    NavmeshAnimator.SetBool(EnabledAnimatorID, false);
                }

                Pointer.transform.parent     = null;
                Pointer.transform.position   = Vector3.zero;
                Pointer.transform.rotation   = Quaternion.identity;
                Pointer.transform.localScale = Vector3.one;
            }
            else
            {
                // The user is still deciding where to teleport and has the touchpad held down.
                // Note: rendering of the parabolic pointer / marker is done in ParabolicPointer
                Vector3 offset = HeadTransform.position - OriginTransform.position;
                offset.y = 0;

                // Render representation of where the chaperone bounds will be after teleporting
                RoomBorder.enabled   = Pointer.PointOnNavMesh;
                RoomBorder.Transpose = Matrix4x4.TRS(Pointer.SelectedPoint - offset, Quaternion.identity, Vector3.one);

                // Haptic feedback click every [HaptickClickAngleStep] degrees
                if (Pointer.CurrentParabolaAngleY >= 45) // Don't click when at max degrees
                {
                    LastClickAngle = Pointer.CurrentPointVector;
                }

                float angleClickDiff = Vector3.Angle(LastClickAngle, Pointer.CurrentPointVector);
                if (IsClicking && Mathf.Abs(angleClickDiff) > HapticClickAngleStep)
                {
                    LastClickAngle = Pointer.CurrentPointVector;
                    if (Pointer.PointOnNavMesh)
                    {
                        device.TriggerHapticPulse();
                    }
                }

                // Trigger a stronger haptic pulse when "entering" a teleportable surface
                if (Pointer.PointOnNavMesh && !IsClicking)
                {
                    IsClicking = true;
                    device.TriggerHapticPulse(750);
                    LastClickAngle = Pointer.CurrentPointVector;
                }
                else if (!Pointer.PointOnNavMesh && IsClicking)
                {
                    IsClicking = false;
                }
            }
        }
        else //CurrentTeleportState == TeleportState.None
        {
            // At this point the user is not holding down on the touchpad at all or has canceled a teleport and hasn't
            // let go of the touchpad.  So we wait for the user to press the touchpad and enable visual indicators
            // if necessary.
            foreach (SteamVR_TrackedObject obj in Controllers)
            {
                int index = (int)obj.index;
                if (index == -1)
                {
                    continue;
                }

                var device = SteamVR_Controller.Input(index);
                if (device.GetPadDown(SteamVR_Controller.ButtonMask.Touchpad))
                {
                    // Set active controller to this controller, and enable the parabolic pointer and visual indicators
                    // that the user can use to determine where they are able to teleport.
                    ActiveController = obj;

                    Pointer.transform.parent        = obj.transform;
                    Pointer.transform.localPosition = Vector3.zero;
                    Pointer.transform.localRotation = Quaternion.identity;
                    Pointer.transform.localScale    = Vector3.one;
                    Pointer.enabled = true;

                    CurrentTeleportState = TeleportState.Selecting;

                    if (NavmeshAnimator != null)
                    {
                        NavmeshAnimator.SetBool(EnabledAnimatorID, true);
                    }

                    Pointer.ForceUpdateCurrentAngle();
                    LastClickAngle = Pointer.CurrentPointVector;
                    IsClicking     = Pointer.PointOnNavMesh;
                }
            }
        }
    }
Exemplo n.º 16
0
 private static bool OpenVRLeftGrip()
 {
     return(SteamVR_Controller.Input(SteamVR_Controller.GetDeviceIndex(SteamVR_Controller.DeviceRelation.Leftmost)).GetPress(Valve.VR.EVRButtonId.k_EButton_Grip));
 }
Exemplo n.º 17
0
    private IEnumerator Overlay()
    {
        yield return(null);

#if VRTK_DEFINE_SDK_STEAMVR
        if (VRTK_SDK_Bridge.GetSystemSDK() is SDK_SteamVRSystem)
        {
            // Wait until we have tracking.
            var hmd = SteamVR_Controller.Input((int)Valve.VR.OpenVR.k_unTrackedDeviceIndex_Hmd);
            while (!hmd.hasTracking)
            {
                yield return(null);
            }
        }
#endif

        yield return(new WaitForSecondsRealtime(0.5f));

        Transform headset = null;
        do
        {
            yield return(null);

            headset = VRTK_DeviceFinder.HeadsetTransform();
        }while (headset == null);

        // pos and orientation
        var headPos    = headset.position;
        var pos        = headPos;
        var lookVector = Vector3.ProjectOnPlane(headset.forward, Vector3.up).normalized;
        pos += lookVector * distance;
        transform.position = pos;
        transform.forward  = pos - headPos;

        // logos
        for (int i = 0; i < logos.Count; ++i)
        {
            spriteRend.sprite = logos[i].sprite;
            Vector3 rendScale = spriteRend.transform.localScale;
            spriteRend.transform.localScale = logos[i].scale * rendScale;

            float alpha     = 0;
            float fadeStart = Time.time;
            while (alpha < 1)
            {
                alpha            = 1 - GetFadeAlpha(logos[i].fadeIn, fadeStart, Time.time);
                spriteRend.color = logos[i].color * new Color(1, 1, 1, alpha);
                yield return(null);
            }

            float dur = logos[i].duration;
            if (includeFadesInDuration)
            {
                dur -= logos[i].fadeIn + logos[i].fadeOut;
            }
            dur = Mathf.Max(0, dur);
            yield return(new WaitForSeconds(dur));

            fadeStart = Time.time;
            while (alpha > 0)
            {
                alpha            = GetFadeAlpha(logos[i].fadeOut, fadeStart, Time.time);
                spriteRend.color = logos[i].color * new Color(1, 1, 1, alpha);
                yield return(null);
            }

            spriteRend.transform.localScale = rendScale;
        }

        onFinished.Invoke();
    }
Exemplo n.º 18
0
        void Update()
        {
            controllerIndex = (uint)trackedController.index;
            device          = SteamVR_Controller.Input((int)controllerIndex);

            Vector2 currentTriggerAxis  = device.GetAxis(Valve.VR.EVRButtonId.k_EButton_SteamVR_Trigger);
            Vector2 currentTouchpadAxis = device.GetAxis();

            //haptic feedback
            if (hapticPulseCountdown > 0)
            {
                device.TriggerHapticPulse(hapticPulseStrength);
                hapticPulseCountdown -= 1;
            }

            //check for changes in trigger press
            if (Vector2ShallowEquals(triggerAxis, currentTriggerAxis))
            {
                triggerAxisChanged = false;
            }
            else
            {
                OnTriggerAxisChanged(SetButtonEvent(ref triggerPressed, true, currentTriggerAxis.x));
                triggerAxisChanged = true;
            }

            //check for changes in finger pos on touchpad
            if (Vector2ShallowEquals(touchpadAxis, currentTouchpadAxis))
            {
                touchpadAxisChanged = false;
            }
            else
            {
                OnTouchpadAxisChanged(SetButtonEvent(ref touchpadTouched, true, 1f));
                touchpadAxisChanged = true;
            }

            touchpadAxis = new Vector2(currentTouchpadAxis.x, currentTouchpadAxis.y);
            triggerAxis  = new Vector2(currentTriggerAxis.x, currentTriggerAxis.y);

            //Trigger
            if (device.GetPressDown(SteamVR_Controller.ButtonMask.Trigger))
            {
                OnTriggerClicked(SetButtonEvent(ref triggerPressed, true, currentTriggerAxis.x));
                triggerDown = true;
            }
            else
            {
                triggerDown = false;
            }

            if (device.GetPressUp(SteamVR_Controller.ButtonMask.Trigger))
            {
                OnTriggerUnclicked(SetButtonEvent(ref triggerPressed, false, 0f));
                triggerUp = true;
            }
            else
            {
                triggerUp = false;
            }

            //ApplicationMenu
            if (device.GetTouchDown(SteamVR_Controller.ButtonMask.ApplicationMenu))
            {
                OnApplicationMenuClicked(SetButtonEvent(ref applicationMenuPressed, true, 1f));
            }
            else if (device.GetTouchUp(SteamVR_Controller.ButtonMask.ApplicationMenu))
            {
                OnApplicationMenuUnclicked(SetButtonEvent(ref applicationMenuPressed, false, 0f));
            }

            //Grip
            if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Grip))
            {
                OnGripClicked(SetButtonEvent(ref gripPressed, true, 1f));
            }
            else if (device.GetTouchUp(SteamVR_Controller.ButtonMask.Grip))
            {
                OnGripUnclicked(SetButtonEvent(ref gripPressed, false, 0f));
            }

            //Touchpad Clicked
            if (device.GetPressDown(SteamVR_Controller.ButtonMask.Touchpad))
            {
                OnTouchpadClicked(SetButtonEvent(ref touchpadPressed, true, 1f));
            }
            else if (device.GetPressUp(SteamVR_Controller.ButtonMask.Touchpad))
            {
                OnTouchpadUnclicked(SetButtonEvent(ref touchpadPressed, false, 0f));
            }

            //Touchpad Touched
            if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Touchpad))
            {
                OnTouchpadTouched(SetButtonEvent(ref touchpadTouched, true, 1f));
            }
            else if (device.GetTouchUp(SteamVR_Controller.ButtonMask.Touchpad))
            {
                OnTouchpadUntouched(SetButtonEvent(ref touchpadTouched, false, 0f));
            }
        }
Exemplo n.º 19
0
 protected override bool MenuTriggerPressedDown()
 {
     return(SteamVR_Controller.Input(MenuController.ControlIndex).GetPressDown(SteamVR_Controller.ButtonMask.Grip));
 }
Exemplo n.º 20
0
    /// <summary>
    /// Colours the hit target supplied
    /// </summary>
    /// <param name="bcolor">What colour to colour with.</param>
    /// <param name="hit">A raycast target from laser pointer.</param>
    void DoColor(Color bcolor, LaserPointer.PointerEventArgs hit)
    {
        // While saving brush strokes onto the texture, don't allow coloring
        if (saving)
        {
            return;
        }

        Vector3 uvWorldPosition = Vector3.zero;

        if (HitTestUVPosition(ref uvWorldPosition, hit))
        {
            GameObject brushObj;

            brushObj = (GameObject)Instantiate(Resources.Load("BrushEntity")); //Paint a brush

            //TODO: Replace this with public properties and assignable brushes
            if (hit.angle < 130)
            {
                brushSize = 0.25f;
                bcolor.a  = brushSize * 2.0f; // Brushes have alpha to have a merging effect when painted over.
            }
            else if (hit.angle < 140)
            {
                brushSize = 0.2f;
                bcolor.a  = brushSize * 2.0f; // Brushes have alpha to have a merging effect when painted over.
            }
            else if (hit.angle < 150)
            {
                brushSize = 0.10f;
                bcolor.a  = 0.6f; // Brushes have alpha to have a merging effect when painted over.
            }
            else
            {
                brushSize = 0.05f;
                bcolor.a  = 1f;                                      // Brushes have alpha to have a merging effect when painted over.
            }
            brushObj.GetComponent <SpriteRenderer>().color = bcolor; //Set the brush color

            AudioSource audio = GetComponent <AudioSource>();
            if (!audio.isPlaying)
            {
                audio.Play();
            }

            SteamVR_Controller.Input((int)hit.controllerIndex).TriggerHapticPulse(100);

            brushObj.transform.parent        = brushContainer.transform; //Add the brushstroke to our container to be wiped later
            brushObj.transform.localPosition = uvWorldPosition;          //The position of the brush (in the UVMap)
            brushObj.transform.localScale    = Vector3.one * brushSize;  //The size of the brush

            brushCounter++;                                              //Add to the max brushes

            //If we reach the max brushes available, flatten the texture and clear the brushes
            if (brushCounter >= MAX_BRUSH_COUNT)
            {
                saving = true;
                Invoke("SaveTexture", 0.1f);
            }
        }
    }
Exemplo n.º 21
0
 protected override void GiveMenuOpenFeedback()
 {
     SteamVR_Controller.Input(MenuController.ControlIndex).TriggerHapticPulse(1000);
 }
Exemplo n.º 22
0
 public void TriggerPulse(int controllerIdx, ushort vibrationTime)
 {
     SteamVR_Controller.Input(controllerIdx).TriggerHapticPulse(vibrationTime);
 }
Exemplo n.º 23
0
        //-------------------------------------------------
        private IEnumerator Start()
        {
            // save off player instance
            playerInstance = Player.instance;
            if (!playerInstance)
            {
                Debug.LogError("No player instance found in Hand Start()");
            }

            // allocate array for colliders
            overlappingColliders = new Collider[ColliderArraySize];

            // We are a "no SteamVR fallback hand" if we have this camera set
            // we'll use the right mouse to look around and left mouse to interact
            // - don't need to find the device
            if (noSteamVRFallbackCamera)
            {
                yield break;
            }

            //Debug.Log( "Hand - initializing connection routine" );

            // Acquire the correct device index for the hand we want to be
            // Also for the other hand if we get there first
            while (true)
            {
                // Don't need to run this every frame
                yield return(new WaitForSeconds(1.0f));

                // We have a controller now, break out of the loop!
                if (controller != null)
                {
                    break;
                }

                //Debug.Log( "Hand - checking controllers..." );

                // Initialize both hands simultaneously
                if (startingHandType == HandType.Left || startingHandType == HandType.Right)
                {
                    // Left/right relationship.
                    // Wait until we have a clear unique left-right relationship to initialize.
                    int leftIndex  = SteamVR_Controller.GetDeviceIndex(SteamVR_Controller.DeviceRelation.Leftmost);
                    int rightIndex = SteamVR_Controller.GetDeviceIndex(SteamVR_Controller.DeviceRelation.Rightmost);
                    if (leftIndex == -1 || rightIndex == -1 || leftIndex == rightIndex)
                    {
                        //Debug.Log( string.Format( "...Left/right hand relationship not yet established: leftIndex={0}, rightIndex={1}", leftIndex, rightIndex ) );
                        continue;
                    }

                    int myIndex    = (startingHandType == HandType.Right) ? rightIndex : leftIndex;
                    int otherIndex = (startingHandType == HandType.Right) ? leftIndex : rightIndex;

                    InitController(myIndex);
                    if (otherHand)
                    {
                        otherHand.InitController(otherIndex);
                    }
                }
                else
                {
                    // No left/right relationship. Just wait for a connection

                    var vr = SteamVR.instance;
                    for (int i = 0; i < OpenVR.k_unMaxTrackedDeviceCount; i++)
                    {
                        if (vr.hmd.GetTrackedDeviceClass((uint)i) != ETrackedDeviceClass.Controller)
                        {
                            //Debug.Log( string.Format( "Hand - device {0} is not a controller", i ) );
                            continue;
                        }

                        var device = SteamVR_Controller.Input(i);
                        if (!device.valid)
                        {
                            //Debug.Log( string.Format( "Hand - device {0} is not valid", i ) );
                            continue;
                        }

                        if ((otherHand != null) && (otherHand.controller != null))
                        {
                            // Other hand is using this index, so we cannot use it.
                            if (i == (int)otherHand.controller.index)
                            {
                                //Debug.Log( string.Format( "Hand - device {0} is owned by the other hand", i ) );
                                continue;
                            }
                        }

                        InitController(i);
                    }
                }
            }
        }
Exemplo n.º 24
0
 private SteamVR_Controller.Device GetDevice(Controller controller)
 {
     return(SteamVR_Controller.Input((int)controller.Tracking.index));
 }
Exemplo n.º 25
0
 void FixedUpdate()
 {
     device = SteamVR_Controller.Input((int)controller.controllerIndex);
 }
 void Start()
 {
     // Get the controller input object relating to this TrackedObject
     SteamVR_TrackedObject to = gameObject.GetComponent<SteamVR_TrackedObject>();
     device = SteamVR_Controller.Input((int)to.index);
 }
Exemplo n.º 27
0
 public void SetupLocal(SteamVR_TrackedController controller)
 {
     device = SteamVR_Controller.Input((int)controller.controllerIndex);
     ViveBridge_Inited(this, EventArgs.Empty);
 }
    // Update is called once per frame
    void Update()
    {
        // catching confirmations commands from mouse and controller
        confirmationStatus._MouseLeftClick   = Input.GetMouseButton(0);
        confirmationStatus._MouseRightClick  = Input.GetMouseButton(1);
        confirmationStatus._MouseMiddleClick = Input.GetMouseButton(2);


        try{
            // We don't care about right and left here
            bool leftTrigger  = SteamVR_Controller.Input(SteamVR_Controller.GetDeviceIndex(SteamVR_Controller.DeviceRelation.Leftmost)).GetHairTrigger();
            bool rightTrigger = SteamVR_Controller.Input(SteamVR_Controller.GetDeviceIndex(SteamVR_Controller.DeviceRelation.Rightmost)).GetHairTrigger();
            confirmationStatus._TriggerPressed = leftTrigger | rightTrigger;
        }
        catch (Exception e)
        {}

        // Dwell
        if (pointingStatus._GazeIn)
        {
            _Gaze_FrameLossCount = 0;
            //progress dwell timer
            float prog = (Environment.TickCount - _Gaze_Starttime) / confirmationStatus._Gaze_DwellTime;
            confirmationStatus._Gaze_DwellProgress = Mathf.Clamp(prog, 0, 1);
        }
        else
        {
            if (_Gaze_FrameLossCount < AcceptableFrameLossCount)
            {
                //progress dwell timer
                float prog = (Environment.TickCount - _Gaze_Starttime) / confirmationStatus._Gaze_DwellTime;
                confirmationStatus._Gaze_DwellProgress = Mathf.Clamp(prog, 0, 1);
                _Gaze_FrameLossCount++;
            }
            else
            {
                _Gaze_Starttime = Environment.TickCount;
                confirmationStatus._Gaze_DwellProgress = 0;
            }
        }

        if (pointingStatus._LaserIn)
        {
            _Laser_FrameLossCount = 0;
            //progress dwell timer
            float prog = (Environment.TickCount - _Laser_Starttime) / confirmationStatus._Laser_DwellTime;
            confirmationStatus._Laser_DwellProgress = Mathf.Clamp(prog, 0, 1);
        }
        else
        {
            if (_Laser_FrameLossCount < AcceptableFrameLossCount)
            {
                //progress dwell timer
                float prog = (Environment.TickCount - _Laser_Starttime) / confirmationStatus._Laser_DwellTime;
                confirmationStatus._Laser_DwellProgress = Mathf.Clamp(prog, 0, 1);
                _Laser_FrameLossCount++;
            }
            else
            {
                _Laser_Starttime = Environment.TickCount;
                confirmationStatus._Laser_DwellProgress = 0;
            }
        }

        if (pointingStatus._ReticleIn)
        {
            _Reticle_FrameLossCount = 0;
            //progress dwell timer
            float prog = (Environment.TickCount - _Reticle_Starttime) / confirmationStatus._Reticle_DwellTime;
            confirmationStatus._Reticle_DwellProgress = Mathf.Clamp(prog, 0, 1);
        }
        else
        {
            if (_Reticle_FrameLossCount < AcceptableFrameLossCount)
            {
                //progress dwell timer
                float prog = (Environment.TickCount - _Reticle_Starttime) / confirmationStatus._Reticle_DwellTime;
                confirmationStatus._Reticle_DwellProgress = Mathf.Clamp(prog, 0, 1);
                _Reticle_FrameLossCount++;
            }
            else
            {
                _Reticle_Starttime = Environment.TickCount;
                confirmationStatus._Reticle_DwellProgress = 0;
            }
        }
    }
Exemplo n.º 29
0
 // Use this for initialization
 void Start()
 {
     HMD         = SteamVR_Controller.Input((int)SteamVR_TrackedObject.EIndex.Hmd);
     controller  = SteamVR_Controller.Input(SteamVR_Controller.GetDeviceIndex(SteamVR_Controller.DeviceRelation.Leftmost));
     controller2 = SteamVR_Controller.Input(SteamVR_Controller.GetDeviceIndex(SteamVR_Controller.DeviceRelation.Rightmost));
 }
Exemplo n.º 30
0
 protected override bool GrabTriggerPressedUp()
 {
     return(SteamVR_Controller.Input(Controller.ControlIndex).GetPressUp(SteamVR_Controller.ButtonMask.Trigger));
 }