/// <summary> /// Gets the current velocity of an XrNode source /// </summary> private Vector3 getVelocityOf(UnityEngine.XR.XRNode source) { List <UnityEngine.XR.XRNodeState> nodeStates = new List <UnityEngine.XR.XRNodeState>(); UnityEngine.XR.InputTracking.GetNodeStates(nodeStates); var sourceInfo = nodeStates.SingleOrDefault(s => s.nodeType == source); // handle the source node not existing if (sourceInfo.Equals(default(UnityEngine.XR.XRNodeState))) { return(Vector3.zero); } Vector3 velocity; if (sourceInfo.TryGetVelocity(out velocity)) { return(velocity); } else { Debug.Log("TryGetVelocity() failed on " + source.ToString()); return(Vector3.zero); } }
private Transform ConfigureEyeAnchor(Transform root, UnityEngine.XR.XRNode eye) { string eyeName = (eye == UnityEngine.XR.XRNode.CenterEye) ? "Center" : (eye == UnityEngine.XR.XRNode.LeftEye) ? "Left" : "Right"; string name = eyeName + eyeAnchorName; Transform anchor = transform.Find(root.name + "/" + name); if (anchor == null) { anchor = transform.Find(name); } if (anchor == null) { string legacyName = legacyEyeAnchorName + eye.ToString(); anchor = transform.Find(legacyName); } if (anchor == null) { anchor = new GameObject(name).transform; } anchor.name = name; anchor.parent = root; anchor.localScale = Vector3.one; anchor.localPosition = Vector3.zero; anchor.localRotation = Quaternion.identity; return(anchor); }
/// <summary> /// Gets the node of the AR tracking system. /// </summary> /// <returns>The AR camera node.</returns> /// <param name="node">Node.</param> public static Transform GetNode(UnityEngine.XR.XRNode node) { switch (node) { case UnityEngine.XR.XRNode.LeftEye: if (leftEye) { return(leftEye); } else { leftEye = ARCamera.Singleton.transform.Find("LeftEye"); return(leftEye); } case UnityEngine.XR.XRNode.RightEye: if (rightEye) { return(rightEye); } else { rightEye = ARCamera.Singleton.transform.Find("RightEye"); return(rightEye); } case UnityEngine.XR.XRNode.CenterEye: case UnityEngine.XR.XRNode.Head: return(ARCamera.Singleton.transform); case UnityEngine.XR.XRNode.TrackingReference: return(TagTracker.TrackingAnchor); default: Debug.LogErrorFormat("Unknown node: {0}", node.ToString()); return(null); } }