private static VRInputDevice CreateVRInputDevice(GameObject go, XRNodeState state) { InputDevice device = InputDevices.GetDeviceAtXRNode(state.nodeType); if (device != null) { VRInputDevice vrInputDevice = go.AddComponent <VRInputDevice>(); vrInputDevice.Device = device; return(vrInputDevice); } return(null); }
protected override void AwakeOverride() { base.AwakeOverride(); m_nullDevice = gameObject.AddComponent <VRInputDevice>(); m_nullDevice.enabled = false; m_leftHand = m_nullDevice; m_rightHand = m_nullDevice; IOC.RegisterFallback <IVRTracker>(this); InputTracking.trackingAcquired += OnTrackingAquired; InputTracking.trackingLost += OnTrackingLost; }
private void OnTrackingAquired(XRNodeState state) { Debug.Log("Tracking Aquired " + state.nodeType); if (state.nodeType == XRNode.LeftHand) { if (m_leftHand == m_nullDevice) { m_leftHand = CreateVRInputDevice(gameObject, state); RaiseTrackingAcquired(m_leftHand); } } else if (state.nodeType == XRNode.RightHand) { if (m_rightHand == m_nullDevice) { m_rightHand = CreateVRInputDevice(gameObject, state); RaiseTrackingAcquired(m_rightHand); } } }
private void OnTrackingLost(XRNode nodeType) { if (nodeType == XRNode.LeftHand) { if (m_leftHand != m_nullDevice) { RaiseTrackingLost(m_leftHand); Destroy(m_leftHand); m_leftHand = m_nullDevice; } } else if (nodeType == XRNode.RightHand) { if (m_rightHand != m_nullDevice) { RaiseTrackingLost(m_rightHand); Destroy(m_rightHand); m_rightHand = m_nullDevice; } } }