Exemple #1
0
 private void Awake()
 {
     instance = this;
     _devices = new TBSteamVRDevice[OpenVR.k_unMaxTrackedDeviceCount];
     for (int i = 0; i < _devices.Length; i++)
     {
         _devices[i] = new TBSteamVRDevice();
     }
     _transformUtil = new SteamVR_Utils.RigidTransform();
     RefreshDeviceAssignments();
 }
Exemple #2
0
        void Update()
        {
            if (Input.GetKeyDown(KeyCode.Escape))   // Quit if the "X" button in the corner of the screen is tapped.
            {
                Application.Quit();
            }

            #if STEAM_VR
            // Early out from this update loop when if Steam VR mode if there are no Steam VR controllers and no controller emulators connected, since there is nothing to update.
            if (GvrController.State != GvrConnectionState.Connected)
            {
                if (!TBSteamVRDeviceManager.IsDeviceConnected(TBSteamVRDeviceManager.DeviceType.AnyController))
                {
                    return;
                }
                else if (!_controllerHasLoaded)
                {
                    if (TBSteamVRDeviceManager.GetFirstController().rotation == _calibrationOffset)    // this means we haven't received any poses from the controller yet.
                    {
                        return;
                    }
                    else
                    {
                        _calibrationOffset   = TBSteamVRDeviceManager.GetFirstController().rotation;
                        _controllerHasLoaded = true;
                        Debug.Log("TBDaydreamController: Steam VR emulation started with calibration offset " + _calibrationOffset);
                    }
                }
            }
            #endif

            // Touchpad click button events
            if (GetButtonDown(TBAVRInputType.ClickButton))
            {
                if (OnClickButtonDown != null)
                {
                    OnClickButtonDown();
                }
            }
            else if (GetButtonUp(TBAVRInputType.ClickButton))
            {
                if (OnClickButtonUp != null)
                {
                    OnClickButtonUp();
                }
            }

            // App button events
            if (GetButtonDown(TBAVRInputType.AppButton))
            {
                // Long press logging.
                _lastAppButtonPressTime = Time.realtimeSinceStartup;

                if (OnAppButtonDown != null)
                {
                    OnAppButtonDown();
                }
            }
            else if (GetButtonUp(TBAVRInputType.AppButton))
            {
                if (OnAppButtonUp != null)
                {
                    OnAppButtonUp();
                }

                // Long Press / short press events.
                if (Time.realtimeSinceStartup - _lastAppButtonPressTime > _longAppButtonPressTime)
                {
                    if (OnAppButtonLongPress != null)
                    {
                        OnAppButtonLongPress();
                    }
                    #if FAKE_DAYDREAM
                    if (_recalibrateOnAppButtonLongPress)    // Recalibrate on long press of app button.
                    {
                        CalibrateOrientation();
                    }
                    #endif
                }
                else
                {
                    if (OnAppButtonShortPress != null)
                    {
                        OnAppButtonShortPress();
                    }
                }
            }

            // Touchpad events
            if (GetButtonDown(TBAVRInputType.Touchpad))
            {
                if (OnTouchDown != null)
                {
                    OnTouchDown();
                }
            }
            else if (GetButtonUp(TBAVRInputType.Touchpad))
            {
                if (OnTouchUp != null)
                {
                    OnTouchUp();
                }
            }

            // Log input so we can detect swipes.
            LogTouchpadInput();

            #if FAKE_DAYDREAM
            if (GvrController.Recentered)
            {
                CalibrateOrientation();
            }
            #endif

            #if STEAM_VR
            // Update Steam VR device stuff.
            _steamControllerRotation = TBSteamVRDeviceManager.GetFirstController().rotation;
            _lastAccleration         = SteamVR_Controller.Input((int)TBSteamVRDeviceManager.GetFirstController().index).velocity;
            _lastAccleration         = new Vector3(_lastAccleration.x - _lastVelocity.x, _lastAccleration.y - _lastVelocity.y, _lastAccleration.z - _lastVelocity.z) / Time.unscaledDeltaTime;
            _lastVelocity            = SteamVR_Controller.Input((int)TBSteamVRDeviceManager.GetFirstController().index).velocity;
            _gyro = SteamVR_Controller.Input((int)TBSteamVRDeviceManager.GetFirstController().index).angularVelocity;
            _gyro = new Vector3(_gyro.x, _gyro.z, _gyro.y);
            #endif
        }