private static void InvokeTrackingEvent(InputTracking.TrackingStateEventType eventType, VRNode nodeType, long uniqueID, bool tracked) { VRNodeState obj = default(VRNodeState); obj.uniqueID = (ulong)uniqueID; obj.nodeType = nodeType; obj.tracked = tracked; Action <VRNodeState> action; switch (eventType) { case InputTracking.TrackingStateEventType.NodeAdded: action = InputTracking.nodeAdded; break; case InputTracking.TrackingStateEventType.NodeRemoved: action = InputTracking.nodeRemoved; break; case InputTracking.TrackingStateEventType.TrackingAcquired: action = InputTracking.trackingAcquired; break; case InputTracking.TrackingStateEventType.TrackingLost: action = InputTracking.trackingLost; break; default: throw new ArgumentException("TrackingEventHandler - Invalid EventType: " + eventType); } if (action != null) { action(obj); } }
static public int constructor(IntPtr l) { try { UnityEngine.VR.VRNodeState o; o = new UnityEngine.VR.VRNodeState(); pushValue(l, true); pushValue(l, o); return(2); } catch (Exception e) { return(error(l, e)); } }
private bool IsTrackingDeviceNode(XRNodeState nodeState) { switch (nodeState.nodeType) { case XRNode.Head: case XRNode.RightHand: case XRNode.LeftHand: case XRNode.GameController: case XRNode.HardwareTracker: case XRNode.TrackingReference: return(true); default: return(false); } }
private bool TryGetAndTouchNodeDeviceIndex(XRNodeState nodeState, out uint deviceIndex) { // only tracking certain type of node (some nodes share same uniqueID) if (!IsTrackingDeviceNode(nodeState)) { deviceIndex = INVALID_DEVICE_INDEX; return(false); } //Debug.Log(Time.frameCount + " TryGetNodeDeviceIndex " + nodeState.nodeType + " tracked=" + nodeState.tracked + " id=" + nodeState.uniqueID + " name=" + (InputTracking.GetNodeName(nodeState.uniqueID) ?? string.Empty)); if (!m_node2Index.TryGetValue(nodeState.uniqueID, out deviceIndex)) { // FIXME: 0ul is invalid id? if (nodeState.uniqueID == 0ul) { return(false); } var validIndexFound = false; if (nodeState.nodeType == XRNode.Head) { if (m_index2nodeValidity[0]) { //Debug.LogWarning("[" + Time.frameCount + "] Multiple Head node found! drop node id:" + nodeState.uniqueID.ToString("X8") + " type:" + nodeState.nodeType + " name:" + InputTracking.GetNodeName(nodeState.uniqueID) + " tracked=" + nodeState.tracked); deviceIndex = INVALID_DEVICE_INDEX; return(false); } validIndexFound = true; m_index2nodeID[0] = nodeState.uniqueID; m_index2nodeValidity[0] = true; m_node2Index.Add(nodeState.uniqueID, 0u); deviceIndex = 0; } else { for (uint i = 1u, imax = (uint)m_index2nodeValidity.Length; i < imax; ++i) { if (!m_index2nodeValidity[i]) { validIndexFound = true; m_index2nodeID[i] = nodeState.uniqueID; m_index2nodeValidity[i] = true; m_node2Index.Add(nodeState.uniqueID, i); deviceIndex = i; break; } } } if (!validIndexFound) { Debug.LogWarning("[" + Time.frameCount + "] XRNode added, but device index out of range, drop the node id:" + nodeState.uniqueID.ToString("X8") + " type:" + nodeState.nodeType + " name:" + InputTracking.GetNodeName(nodeState.uniqueID) + " tracked=" + nodeState.tracked); deviceIndex = INVALID_DEVICE_INDEX; return(false); } //Debug.Log("[" + Time.frameCount + "] Add node device index [" + deviceIndex + "] id=" + nodeState.uniqueID.ToString("X8") + " type=" + nodeState.nodeType + " tracked=" + nodeState.tracked); } m_index2nodeTouched[deviceIndex] = true; return(true); }
private bool TryGetNodeDeviceIndex(XRNodeState nodeState, out uint deviceIndex) { // only tracking certain type of node (some nodes share same uniqueID) if (!IsTrackingDeviceNode(nodeState)) { deviceIndex = 0; return(false); } //Debug.Log(Time.frameCount + " TryGetNodeDeviceIndex " + nodeState.nodeType + " tracked=" + nodeState.tracked + " id=" + nodeState.uniqueID + " name=" + (InputTracking.GetNodeName(nodeState.uniqueID) ?? string.Empty)); if (!m_node2Index.TryGetValue(nodeState.uniqueID, out deviceIndex)) { // FIXME: 0ul is invalid id? if (nodeState.uniqueID == 0ul) { return(false); } var validIndexFound = false; if (nodeState.nodeType == XRNode.Head) { if (m_nodeStatesValid[0]) { //Debug.LogWarning("[" + Time.frameCount + "] Multiple Head node found! drop node id:" + nodeState.uniqueID.ToString("X8") + " type:" + nodeState.nodeType + " name:" + InputTracking.GetNodeName(nodeState.uniqueID) + " tracked=" + nodeState.tracked); return(false); } validIndexFound = true; m_nodeStatesValid[0] = true; m_node2Index.Add(nodeState.uniqueID, 0u); deviceIndex = 0; } else { for (uint i = 1; i < MAX_DEVICE_COUNT; ++i) { if (!m_nodeStatesValid[i]) { validIndexFound = true; m_nodeStatesValid[i] = true; m_node2Index.Add(nodeState.uniqueID, i); switch (nodeState.nodeType) { case XRNode.RightHand: m_rightIndex = i; break; case XRNode.LeftHand: m_leftIndex = i; break; } deviceIndex = i; break; } } } if (!validIndexFound) { Debug.LogWarning("[" + Time.frameCount + "] XRNode added, but device index out of range, drop the node id:" + nodeState.uniqueID.ToString("X8") + " type:" + nodeState.nodeType + " name:" + InputTracking.GetNodeName(nodeState.uniqueID) + " tracked=" + nodeState.tracked); return(false); } //Debug.Log("[" + Time.frameCount + "] Add node device index [" + deviceIndex + "] id=" + nodeState.uniqueID.ToString("X8") + " type=" + nodeState.nodeType + " tracked=" + nodeState.tracked); } return(true); }