Hi, I’m trying to update a script of mine that I use with GoogleVR. Not sure how GetNodeStates should work to replace XRNode.GetLocalRotation as I get a message it is now obsolete in Unity 2019… How would I get CenterEye rotation?
Thx
m_gyroscopeRotation = UnityEngine.XR.InputTracking.GetLocalRotation(UnityEngine.XR.XRNode.CenterEye);
//change to this...
m_gyroscopeRotation = UnityEngine.XR.InputTracking.GetNodeStates //???
Here is a simple script to get the center eye rotation:
// This is so you don't create garbage on every frame, reuse the same list
List<XRNodeState> nodeStatesCache = new List<XRNodeState>();
bool TryGetCenterEyeNodeStateRotation(out Quaternion rotation)
{
InputTracking.GetNodeStates(nodeStatesCache);
for (int i = 0; i < nodeStatesCache.Count; i++)
{
XRNodeState nodeState = nodeStatesCache[i];
if(nodeState.nodeType == XRNode.CenterEye)
{
if (nodeState.TryGetRotation(out rotation))
return true;
}
}
// This is the fail case, where there was no center eye was available.
rotation = Quaternion.identity;
return false;
}
However, if you are using 2019.x, then I would like to make another suggestion. We are fast moving to using the InputDevice API, which is more centered around devices, and should make this easier. So if you are using 2019.x then I would suggest something closer to this:
bool TryGetCenterEyeFeature(out Quaternion rotation)
{
InputDevice device = InputDevices.GetDeviceAtXRNode(XRNode.CenterEye);
if(device.isValid)
{
if (device.TryGetFeatureValue(CommonUsages.centerEyeRotation, out rotation))
return true;
}
// This is the fail case, where there was no center eye was available.
rotation = Quaternion.identity;
return false;
}