Home Game Development unity – Examine if OpenVR / SteamVR / OculusVR headset is mounted in your head

unity – Examine if OpenVR / SteamVR / OculusVR headset is mounted in your head

0
unity – Examine if OpenVR / SteamVR / OculusVR headset is mounted in your head

[ad_1]

The SteamVR enter has lately modified fully, it now makes use of Actions and here’s a step-by-step tutorial from valve on easy methods to set it up.

This is one of many (greatest) methods to ballot it in code:

    void Replace(){


    //NOTE: I may have used one-off occasions. However I used these fixed Replace() polls as a substitute as a result of if the VR Dashboard is on whereas the headset is taken off or placed on, 
    //then the OnDown and OnUp occasions get eaten by the dashboard and can by no means attain this code in unity. (github challenge right here: https://github.com/ValveSoftware/openvr/points/628)

    // m_inputSourceDevice must be Any - there is not any entry for "Headset", however the headset's sensors are reported underneath the Any "hand".
    SteamVR_Input_Sources m_inputSourceDevice = SteamVR_Input_Sources.Any;

    if(!m_isHeadsetOn && SteamVR_Input._default.inActions.Proximity_Sensor.GetState(m_inputSourceDevice)){
            Debug.Log("Headset On.");
            HeadsetOn();
    }
    else if(m_isHeadsetOn && !SteamVR_Input._default.inActions.Proximity_Sensor.GetState(m_inputSourceDevice)){
        Debug.Log("Headset Off (cancellable)");
        StartCoroutine(HeadsetOff());
    }

}

Word that as of proper now, there’s a bug that forestalls you from utilizing SteamVR to assign the Proximity Sensor to an motion when you have a HTC Vive or Vive Professional, regardless that sarcastically it really works as meant in case you’re utilizing it with an Oculus headset. There may be a straightforward repair on this steamvr github points web page.

Additionally notice that regardless that the builtin unity OpenVR often implements what SteamVR comes up with, for now it doesn’t allow you to entry the proximity sensor. The one factor you are able to do with OpenVR is to test the EDeviceActivityLevel as MichaelHouse defined in his reply. Nonetheless that’s ineffective as a result of the one degree that entails the prox sensor is the k_EDeviceActivityLevel_UserInteraction nevertheless it’s a union of each the prox and the gyro, so based on OpenVR the headset is at all times interacting with the consumer perpetually so long as a delicate breeze or vibration tilts the headset slightly bit as soon as each 10 seconds.

[EDIT]

Some issues bought fastened within the meantime. As an example now there may be an entry for the Hmd, as a substitute of Any; and OpenVR does have an XRDevice.userPresence worth (although it won’t explicitly be the proximity sensor).

[ad_2]

LEAVE A REPLY

Please enter your comment!
Please enter your name here