private bool TryGetAndTouchDeviceIndexByType(WVR_DeviceType type, out uint deviceIndex) { if (type < 0 || (int)type >= s_type2index.Length) { deviceIndex = INVALID_DEVICE_INDEX; return(false); } deviceIndex = s_type2index[(int)type]; if (VRModule.IsValidDeviceIndex(deviceIndex)) { m_index2deviceTouched[deviceIndex] = true; return(true); } else { return(false); } }
public override void BeforeRenderUpdate() { var roleChanged = false; var rightIndex = INVALID_DEVICE_INDEX; var leftIndex = INVALID_DEVICE_INDEX; FlushDeviceState(); if (XRSettings.isDeviceActive && XRDevice.isPresent) { InputTracking.GetNodeStates(m_nodeStateList); } for (int i = 0, imax = m_nodeStateList.Count; i < imax; ++i) { uint deviceIndex; if (!TryGetAndTouchNodeDeviceIndex(m_nodeStateList[i], out deviceIndex)) { continue; } switch (m_nodeStateList[i].nodeType) { case XRNode.RightHand: rightIndex = deviceIndex; break; case XRNode.LeftHand: leftIndex = deviceIndex; break; } IVRModuleDeviceState prevState; IVRModuleDeviceStateRW currState; EnsureValidDeviceState(deviceIndex, out prevState, out currState); if (m_rightIndex != rightIndex || m_leftIndex != leftIndex) { m_rightIndex = rightIndex; m_leftIndex = leftIndex; roleChanged = true; } if (!prevState.isConnected) { currState.isConnected = true; currState.deviceClass = s_nodeType2DeviceClass[(int)m_nodeStateList[i].nodeType]; // FIXME: getting wrong name in Unity 2017.1f1 //currDeviceState.serialNumber = InputTracking.GetNodeName(m_nodeStateList[i].uniqueID) ?? string.Empty; //Debug.Log("connected " + InputTracking.GetNodeName(m_nodeStateList[i].uniqueID)); if (!XRDevice.model.Equals("None")) { currState.serialNumber = XRDevice.model + " " + m_nodeStateList[i].uniqueID.ToString("X8"); currState.modelNumber = XRDevice.model + " " + m_nodeStateList[i].nodeType; currState.renderModelName = XRDevice.model + " " + m_nodeStateList[i].nodeType; } else { currState.serialNumber = XRSettings.loadedDeviceName + " " + m_nodeStateList[i].uniqueID.ToString("X8"); currState.modelNumber = XRSettings.loadedDeviceName + " " + m_nodeStateList[i].nodeType; currState.renderModelName = XRSettings.loadedDeviceName + " " + m_nodeStateList[i].nodeType; } SetupKnownDeviceModel(currState); } // update device status currState.isPoseValid = m_nodeStateList[i].tracked; var velocity = default(Vector3); if (m_nodeStateList[i].TryGetVelocity(out velocity)) { currState.velocity = velocity; } var position = default(Vector3); if (m_nodeStateList[i].TryGetPosition(out position)) { currState.position = position; } var rotation = default(Quaternion); if (m_nodeStateList[i].TryGetRotation(out rotation)) { currState.rotation = rotation; } } m_nodeStateList.Clear(); // update right hand input if (VRModule.IsValidDeviceIndex(rightIndex)) { IVRModuleDeviceState rightPrevState; IVRModuleDeviceStateRW rightCurrState; EnsureValidDeviceState(rightIndex, out rightPrevState, out rightCurrState); UpdateRightControllerInput(rightPrevState, rightCurrState); } //// update left hand input if (VRModule.IsValidDeviceIndex(leftIndex)) { IVRModuleDeviceState leftPrevState; IVRModuleDeviceStateRW leftCurrState; EnsureValidDeviceState(leftIndex, out leftPrevState, out leftCurrState); UpdateLeftControllerInput(leftPrevState, leftCurrState); } TrimUntouchedNodes(trimmedIndex => { IVRModuleDeviceState ps; IVRModuleDeviceStateRW cs; if (TryGetValidDeviceState(trimmedIndex, out ps, out cs)) { cs.Reset(); } }); ProcessConnectedDeviceChanged(); if (roleChanged) { InvokeControllerRoleChangedEvent(); } ProcessDevicePoseChanged(); ProcessDeviceInputChanged(); }
private bool IsDeviceSelected() { return(VRModule.IsValidDeviceIndex(selectedDeviceIndex)); }
public void InternalUpdateDeviceState(IVRModuleDeviceState[] prevState, IVRModuleDeviceStateRW[] currState) { if (VIUSettings.enableSimulatorKeyboardMouseControl && hasControlFocus) { if (IsEscapeKeyDown()) { if (IsDeviceSelected()) { DeselectDevice(); } else { //SetSimulatorActive(false); hasControlFocus = false; } } // reset to default state if (m_resetDevices || IsResetAllKeyDown()) { m_resetDevices = false; foreach (var state in currState) { switch (state.deviceIndex) { case VRModule.HMD_DEVICE_INDEX: case RIGHT_INDEX: case LEFT_INDEX: InitializeDevice(currState[VRModule.HMD_DEVICE_INDEX], state); break; default: if (state.isConnected) { state.Reset(); } break; } } DeselectDevice(); } // align devices with hmd if (IsResetDevicesKeyDown()) { foreach (var state in currState) { switch (state.deviceIndex) { case VRModule.HMD_DEVICE_INDEX: break; case RIGHT_INDEX: state.pose = currState[VRModule.HMD_DEVICE_INDEX].pose * s_offsetRightController; break; case LEFT_INDEX: state.pose = currState[VRModule.HMD_DEVICE_INDEX].pose * s_offsetLeftController; break; default: if (state.isConnected) { state.pose = currState[VRModule.HMD_DEVICE_INDEX].pose * s_offsetTracker; } break; } } } // select/deselect device IVRModuleDeviceStateRW keySelectDevice; if (GetDeviceByInputDownKeyCode(currState, out keySelectDevice)) { if (IsShiftKeyPressed()) { // remove device if (keySelectDevice.isConnected && keySelectDevice.deviceIndex != VRModule.HMD_DEVICE_INDEX) { if (IsSelectedDevice(keySelectDevice)) { DeselectDevice(); } keySelectDevice.Reset(); } } else { if (IsSelectedDevice(keySelectDevice)) { DeselectDevice(); } else { // select device if (!keySelectDevice.isConnected) { InitializeDevice(currState[VRModule.HMD_DEVICE_INDEX], keySelectDevice); } SelectDevice(keySelectDevice); } } } var selectedDevice = VRModule.IsValidDeviceIndex(selectedDeviceIndex) && currState[selectedDeviceIndex].isConnected ? currState[selectedDeviceIndex] : null; if (selectedDevice != null) { // control selected device ControlDevice(selectedDevice); if (selectedDevice.deviceClass == VRModuleDeviceClass.Controller || selectedDevice.deviceClass == VRModuleDeviceClass.GenericTracker) { HandleDeviceInput(selectedDevice); } } else if (hasControlFocus) { // control device group ControlDeviceGroup(currState); } // control camera (TFGH) if (currState[VRModule.HMD_DEVICE_INDEX].isConnected) { ControlCamera(currState[VRModule.HMD_DEVICE_INDEX]); } } else if (IsDeviceSelected()) { DeselectDevice(); } if (onUpdateDeviceState != null) { onUpdateDeviceState(prevState, currState); } UpdateMainCamTracking(); }
public override void UpdateDeviceState(IVRModuleDeviceState[] prevState, IVRModuleDeviceStateRW[] currState) { if (WaveVR.Instance == null) { return; } // FIXME: WVR_IsInputFocusCapturedBySystem currently not implemented yet //m_hasInputFocus = Interop.WVR_IsInputFocusCapturedBySystem(); Interop.WVR_GetSyncPose(m_poseOrigin, m_poses, DEVICE_COUNT); for (int i = 0; i < DEVICE_COUNT; ++i) { var deviceType = m_poses[i].type; if (deviceType < 0 || (int)deviceType >= s_type2index.Length) { continue; } var deviceIndex = s_type2index[(int)deviceType]; if (!VRModule.IsValidDeviceIndex(deviceIndex)) { continue; } var cState = currState[deviceIndex]; var pState = prevState[deviceIndex]; cState.isConnected = Interop.WVR_IsDeviceConnected(deviceType); if (cState.isConnected) { if (!pState.isConnected) { cState.deviceClass = s_type2class[(int)deviceType]; cState.deviceModel = s_type2model[(int)deviceType]; } // fetch tracking data cState.isOutOfRange = false; cState.isCalibrating = false; cState.isUninitialized = false; var devicePose = m_poses[i].pose; cState.velocity = new Vector3(devicePose.Velocity.v0, devicePose.Velocity.v1, -devicePose.Velocity.v2); cState.angularVelocity = new Vector3(-devicePose.AngularVelocity.v0, -devicePose.AngularVelocity.v1, devicePose.AngularVelocity.v2); var rigidTransform = new WaveVR_Utils.RigidTransform(devicePose.PoseMatrix); cState.position = rigidTransform.pos; cState.rotation = rigidTransform.rot; cState.isPoseValid = cState.pose != RigidPose.identity; // fetch buttons input var buttons = 0u; var touches = 0u; // FIXME: What does WVR_GetInputTypeCount means? var analogCount = Interop.WVR_GetInputTypeCount(deviceType, WVR_InputType.WVR_InputType_Analog); if (m_analogStates == null || m_analogStates.Length < analogCount) { m_analogStates = new WVR_AnalogState_t[analogCount]; } const uint inputType = (uint)(WVR_InputType.WVR_InputType_Button | WVR_InputType.WVR_InputType_Touch | WVR_InputType.WVR_InputType_Analog); #if VIU_WAVEVR_2_0_32_OR_NEWER if (Interop.WVR_GetInputDeviceState(deviceType, inputType, ref buttons, ref touches, m_analogStates, (uint)analogCount)) #else if (Interop.WVR_GetInputDeviceState(deviceType, inputType, ref buttons, ref touches, m_analogStates, analogCount)) #endif { const uint dpadMask = (1 << (int)(WVR_InputId.WVR_InputId_Alias1_Touchpad)) | (1 << (int)(WVR_InputId.WVR_InputId_Alias1_DPad_Left)) | (1 << (int)(WVR_InputId.WVR_InputId_Alias1_DPad_Up)) | (1 << (int)(WVR_InputId.WVR_InputId_Alias1_DPad_Right)) | (1 << (int)(WVR_InputId.WVR_InputId_Alias1_DPad_Down)); const uint triggerBumperMask = (1 << (int)(WVR_InputId.WVR_InputId_Alias1_Trigger)) | #if VIU_WAVEVR_2_1_0_OR_NEWER (1 << (int)(WVR_InputId.WVR_InputId_Alias1_Digital_Trigger)); #else (1 << (int)(WVR_InputId.WVR_InputId_Alias1_Bumper)); #endif cState.SetButtonPress(VRModuleRawButton.System, (buttons & (1 << (int)WVR_InputId.WVR_InputId_Alias1_System)) != 0u); cState.SetButtonPress(VRModuleRawButton.ApplicationMenu, (buttons & (1 << (int)WVR_InputId.WVR_InputId_Alias1_Menu)) != 0u); cState.SetButtonPress(VRModuleRawButton.Touchpad, (buttons & dpadMask) != 0u); cState.SetButtonPress(VRModuleRawButton.Trigger, (buttons & triggerBumperMask) != 0u); cState.SetButtonPress(VRModuleRawButton.Grip, (buttons & (1 << (int)WVR_InputId.WVR_InputId_Alias1_Grip)) != 0u); cState.SetButtonPress(VRModuleRawButton.DPadLeft, (buttons & (1 << (int)WVR_InputId.WVR_InputId_Alias1_DPad_Left)) != 0u); cState.SetButtonPress(VRModuleRawButton.DPadUp, (buttons & (1 << (int)WVR_InputId.WVR_InputId_Alias1_DPad_Up)) != 0u); cState.SetButtonPress(VRModuleRawButton.DPadRight, (buttons & (1 << (int)WVR_InputId.WVR_InputId_Alias1_DPad_Right)) != 0u); cState.SetButtonPress(VRModuleRawButton.DPadDown, (buttons & (1 << (int)WVR_InputId.WVR_InputId_Alias1_DPad_Down)) != 0u); cState.SetButtonTouch(VRModuleRawButton.System, (touches & (1 << (int)WVR_InputId.WVR_InputId_Alias1_System)) != 0u); cState.SetButtonTouch(VRModuleRawButton.ApplicationMenu, (touches & (1 << (int)WVR_InputId.WVR_InputId_Alias1_Menu)) != 0u); cState.SetButtonTouch(VRModuleRawButton.Touchpad, (touches & dpadMask) != 0u); cState.SetButtonTouch(VRModuleRawButton.Trigger, (touches & triggerBumperMask) != 0u); cState.SetButtonTouch(VRModuleRawButton.Grip, (touches & (1 << (int)WVR_InputId.WVR_InputId_Alias1_Grip)) != 0u); cState.SetButtonTouch(VRModuleRawButton.DPadLeft, (touches & (1 << (int)WVR_InputId.WVR_InputId_Alias1_DPad_Left)) != 0u); cState.SetButtonTouch(VRModuleRawButton.DPadUp, (touches & (1 << (int)WVR_InputId.WVR_InputId_Alias1_DPad_Up)) != 0u); cState.SetButtonTouch(VRModuleRawButton.DPadRight, (touches & (1 << (int)WVR_InputId.WVR_InputId_Alias1_DPad_Right)) != 0u); cState.SetButtonTouch(VRModuleRawButton.DPadDown, (touches & (1 << (int)WVR_InputId.WVR_InputId_Alias1_DPad_Down)) != 0u); for (int j = 0, jmax = m_analogStates.Length; j < jmax; ++j) { switch (m_analogStates[j].id) { case WVR_InputId.WVR_InputId_Alias1_Trigger: if (m_analogStates[j].type == WVR_AnalogType.WVR_AnalogType_Trigger) { cState.SetAxisValue(VRModuleRawAxis.Trigger, m_analogStates[j].axis.x); } break; case WVR_InputId.WVR_InputId_Alias1_Touchpad: if (m_analogStates[j].type == WVR_AnalogType.WVR_AnalogType_TouchPad && cState.GetButtonTouch(VRModuleRawButton.Touchpad)) { cState.SetAxisValue(VRModuleRawAxis.TouchpadX, m_analogStates[j].axis.x); cState.SetAxisValue(VRModuleRawAxis.TouchpadY, m_analogStates[j].axis.y); } else { cState.SetAxisValue(VRModuleRawAxis.TouchpadX, 0f); cState.SetAxisValue(VRModuleRawAxis.TouchpadY, 0f); } break; } } } else { cState.buttonPressed = 0u; cState.buttonTouched = 0u; for (int j = 0, jmax = cState.axisValue.Length; j < jmax; ++j) { cState.axisValue[j] = 0f; } } } else { if (pState.isConnected) { cState.Reset(); } } } var headState = currState[s_type2index[(int)WVR_DeviceType.WVR_DeviceType_HMD]]; var rightState = currState[s_type2index[(int)WVR_DeviceType.WVR_DeviceType_Controller_Right]]; var leftState = currState[s_type2index[(int)WVR_DeviceType.WVR_DeviceType_Controller_Left]]; ApplyVirtualArmAndSimulateInput(rightState, headState, RIGHT_ARM_MULTIPLIER); ApplyVirtualArmAndSimulateInput(leftState, headState, LEFT_ARM_MULTIPLIER); }
public override void UpdateDeviceState(IVRModuleDeviceState[] prevState, IVRModuleDeviceStateRW[] currState) { if (VRSettings.isDeviceActive && VRDevice.isPresent) { InputTracking.GetNodeStates(m_nodeStateList); } var rightIndex = INVALID_DEVICE_INDEX; var leftIndex = INVALID_DEVICE_INDEX; for (int i = 0, imax = m_nodeStateList.Count; i < imax; ++i) { uint deviceIndex; if (!TryGetNodeDeviceIndex(m_nodeStateList[i], out deviceIndex)) { continue; } m_prevExistNodeUids.Remove(m_nodeStateList[i].uniqueID); m_currExistNodeUids.Add(m_nodeStateList[i].uniqueID); var prevDeviceState = prevState[deviceIndex]; var currDeviceState = currState[deviceIndex]; currDeviceState.isConnected = true; switch (m_nodeStateList[i].nodeType) { case VRNode.Head: currDeviceState.deviceClass = VRModuleDeviceClass.HMD; break; case VRNode.RightHand: currDeviceState.deviceClass = VRModuleDeviceClass.Controller; rightIndex = deviceIndex; break; case VRNode.LeftHand: currDeviceState.deviceClass = VRModuleDeviceClass.Controller; leftIndex = deviceIndex; break; case VRNode.GameController: currDeviceState.deviceClass = VRModuleDeviceClass.Controller; break; case VRNode.HardwareTracker: currDeviceState.deviceClass = VRModuleDeviceClass.GenericTracker; break; case VRNode.TrackingReference: currDeviceState.deviceClass = VRModuleDeviceClass.TrackingReference; break; default: currDeviceState.deviceClass = VRModuleDeviceClass.Invalid; break; } if (!prevDeviceState.isConnected) { // FIXME: getting wrong name in Unity 2017.1f1 //currDeviceState.serialNumber = InputTracking.GetNodeName(m_nodeStateList[i].uniqueID) ?? string.Empty; currDeviceState.serialNumber = VRDevice.model + " " + m_nodeStateList[i].uniqueID.ToString("X8"); currDeviceState.modelNumber = VRDevice.model + " " + m_nodeStateList[i].nodeType; currDeviceState.renderModelName = VRDevice.model + " " + m_nodeStateList[i].nodeType; SetupKnownDeviceModel(currDeviceState); } // update device status currDeviceState.isPoseValid = m_nodeStateList[i].tracked; var velocity = default(Vector3); if (m_nodeStateList[i].TryGetVelocity(out velocity)) { currDeviceState.velocity = velocity; } var position = default(Vector3); if (m_nodeStateList[i].TryGetPosition(out position)) { currDeviceState.position = position; } var rotation = default(Quaternion); if (m_nodeStateList[i].TryGetRotation(out rotation)) { currDeviceState.rotation = rotation; } } m_nodeStateList.Clear(); if (VRModule.IsValidDeviceIndex(rightIndex)) { var rightCurrState = currState[m_rightIndex]; var rightPrevState = prevState[m_rightIndex]; var rightMenuPress = Input.GetKey(ButtonKeyCode.RMenuPress); var rightAButtonPress = Input.GetKey(ButtonKeyCode.RAKeyPress); var rightPadPress = Input.GetKey(ButtonKeyCode.RPadPress); var rightMenuTouch = Input.GetKey(ButtonKeyCode.RMenuTouch); var rightAButtonTouch = Input.GetKey(ButtonKeyCode.RAKeyTouch); var rightPadTouch = Input.GetKey(ButtonKeyCode.RPadTouch); var rightTriggerTouch = Input.GetKey(ButtonKeyCode.RTriggerTouch); var rightTrackpadX = Input.GetAxisRaw(ButtonAxisName.RPadX); var rightTrackpadY = Input.GetAxisRaw(ButtonAxisName.RPadY); var rightTrigger = Input.GetAxisRaw(ButtonAxisName.RTrigger); var rightGrip = Input.GetAxisRaw(ButtonAxisName.RGrip); rightCurrState.SetButtonPress(VRModuleRawButton.ApplicationMenu, rightMenuPress); rightCurrState.SetButtonPress(VRModuleRawButton.A, rightAButtonPress); rightCurrState.SetButtonPress(VRModuleRawButton.Touchpad, rightPadPress); rightCurrState.SetButtonPress(VRModuleRawButton.Trigger, AxisToPress(rightPrevState.GetButtonPress(VRModuleRawButton.Trigger), rightTrigger, 0.55f, 0.45f)); rightCurrState.SetButtonPress(VRModuleRawButton.Grip, AxisToPress(rightPrevState.GetButtonPress(VRModuleRawButton.Grip), rightGrip, 0.55f, 0.45f)); rightCurrState.SetButtonPress(VRModuleRawButton.CapSenseGrip, AxisToPress(rightPrevState.GetButtonPress(VRModuleRawButton.CapSenseGrip), rightGrip, 0.55f, 0.45f)); rightCurrState.SetButtonTouch(VRModuleRawButton.ApplicationMenu, rightMenuTouch); rightCurrState.SetButtonTouch(VRModuleRawButton.A, rightAButtonTouch); rightCurrState.SetButtonTouch(VRModuleRawButton.Touchpad, rightPadTouch); rightCurrState.SetButtonTouch(VRModuleRawButton.Trigger, rightTriggerTouch); rightCurrState.SetButtonTouch(VRModuleRawButton.CapSenseGrip, AxisToPress(rightPrevState.GetButtonTouch(VRModuleRawButton.CapSenseGrip), rightGrip, 0.25f, 0.20f)); rightCurrState.SetAxisValue(VRModuleRawAxis.TouchpadX, rightTrackpadX); rightCurrState.SetAxisValue(VRModuleRawAxis.TouchpadY, rightTrackpadY); rightCurrState.SetAxisValue(VRModuleRawAxis.Trigger, rightTrigger); rightCurrState.SetAxisValue(VRModuleRawAxis.CapSenseGrip, rightGrip); } if (VRModule.IsValidDeviceIndex(leftIndex)) { var leftCurrState = currState[m_leftIndex]; var leftPrevState = prevState[m_leftIndex]; var leftMenuPress = Input.GetKey(ButtonKeyCode.LMenuPress); var leftAButtonPress = Input.GetKey(ButtonKeyCode.LAKeyPress); var leftPadPress = Input.GetKey(ButtonKeyCode.LPadPress); var leftMenuTouch = Input.GetKey(ButtonKeyCode.LMenuTouch); var leftAButtonTouch = Input.GetKey(ButtonKeyCode.LAKeyTouch); var leftPadTouch = Input.GetKey(ButtonKeyCode.LPadTouch); var leftTriggerTouch = Input.GetKey(ButtonKeyCode.LTriggerTouch); var leftTrackpadX = Input.GetAxisRaw(ButtonAxisName.LPadX); var leftTrackpadY = Input.GetAxisRaw(ButtonAxisName.LPadY); var leftTrigger = Input.GetAxisRaw(ButtonAxisName.LTrigger); var leftGrip = Input.GetAxisRaw(ButtonAxisName.LGrip); leftCurrState.SetButtonPress(VRModuleRawButton.ApplicationMenu, leftMenuPress); leftCurrState.SetButtonPress(VRModuleRawButton.A, leftAButtonPress); leftCurrState.SetButtonPress(VRModuleRawButton.Touchpad, leftPadPress); leftCurrState.SetButtonPress(VRModuleRawButton.Trigger, AxisToPress(leftPrevState.GetButtonPress(VRModuleRawButton.Trigger), leftTrigger, 0.55f, 0.45f)); leftCurrState.SetButtonPress(VRModuleRawButton.Grip, AxisToPress(leftPrevState.GetButtonPress(VRModuleRawButton.Grip), leftGrip, 0.55f, 0.45f)); leftCurrState.SetButtonPress(VRModuleRawButton.CapSenseGrip, AxisToPress(leftPrevState.GetButtonPress(VRModuleRawButton.CapSenseGrip), leftGrip, 0.55f, 0.45f)); leftCurrState.SetButtonTouch(VRModuleRawButton.ApplicationMenu, leftMenuTouch); leftCurrState.SetButtonTouch(VRModuleRawButton.A, leftAButtonTouch); leftCurrState.SetButtonTouch(VRModuleRawButton.Touchpad, leftPadTouch); leftCurrState.SetButtonTouch(VRModuleRawButton.Trigger, leftTriggerTouch); leftCurrState.SetButtonTouch(VRModuleRawButton.CapSenseGrip, AxisToPress(leftPrevState.GetButtonTouch(VRModuleRawButton.CapSenseGrip), leftGrip, 0.25f, 0.20f)); leftCurrState.SetAxisValue(VRModuleRawAxis.TouchpadX, leftTrackpadX); leftCurrState.SetAxisValue(VRModuleRawAxis.TouchpadY, leftTrackpadY); leftCurrState.SetAxisValue(VRModuleRawAxis.Trigger, leftTrigger); leftCurrState.SetAxisValue(VRModuleRawAxis.CapSenseGrip, leftGrip); } // remove disconnected nodes for (int i = m_prevExistNodeUids.Count - 1; i >= 0; --i) { if (currState[i].isConnected) { currState[i].Reset(); } RemoveNodeDeviceIndex(m_prevExistNodeUids[i]); } var temp = m_prevExistNodeUids; m_prevExistNodeUids = m_currExistNodeUids; m_currExistNodeUids = temp; m_currExistNodeUids.Clear(); if (m_rightIndex != rightIndex || m_leftIndex != leftIndex) { m_rightIndex = rightIndex; m_leftIndex = leftIndex; InvokeControllerRoleChangedEvent(); } }
// update connected devices private void UpdateConnectedDevices() { IVRModuleDeviceState prevState; IVRModuleDeviceStateRW currState; EnsureValidDeviceState(HEAD_INDEX, out prevState, out currState); if (!XRDevice.isPresent) { if (prevState.isConnected) { currState.Reset(); } } else { if (!prevState.isConnected) { currState.isConnected = true; currState.deviceClass = VRModuleDeviceClass.HMD; currState.serialNumber = XRDevice.model + " HMD"; currState.modelNumber = XRDevice.model + " HMD"; currState.deviceModel = VRModuleDeviceModel.DaydreamHMD; currState.renderModelName = string.Empty; } } var controllerRoleChanged = false; EnsureValidDeviceState(CONTROLLER_INDEX, out prevState, out currState); if (GvrControllerInput.State != GvrConnectionState.Connected) { if (prevState.isConnected) { currState.Reset(); } } else { if (!prevState.isConnected) { currState.isConnected = true; currState.deviceClass = VRModuleDeviceClass.Controller; currState.serialNumber = XRDevice.model + " Controller"; currState.modelNumber = XRDevice.model + " Controller"; currState.deviceModel = VRModuleDeviceModel.DaydreamController; currState.renderModelName = string.Empty; } switch (GvrSettings.Handedness) { case GvrSettings.UserPrefsHandedness.Right: controllerRoleChanged = !VRModule.IsValidDeviceIndex(m_rightIndex) && m_leftIndex == CONTROLLER_INDEX; m_rightIndex = CONTROLLER_INDEX; m_leftIndex = INVALID_DEVICE_INDEX; break; case GvrSettings.UserPrefsHandedness.Left: controllerRoleChanged = m_rightIndex == CONTROLLER_INDEX && !VRModule.IsValidDeviceIndex(m_leftIndex); m_rightIndex = INVALID_DEVICE_INDEX; m_leftIndex = CONTROLLER_INDEX; break; case GvrSettings.UserPrefsHandedness.Error: default: Debug.LogError("GvrSettings.Handedness error"); break; } } if (controllerRoleChanged) { InvokeControllerRoleChangedEvent(); } }
public override void UpdateDeviceState(IVRModuleDeviceState[] prevState, IVRModuleDeviceStateRW[] currState) { if (VIUSettings.enableSimulatorKeyboardMouseControl) { // Reset to default state if (m_resetDevices) { m_resetDevices = false; foreach (var state in currState) { switch (state.deviceIndex) { case VRModule.HMD_DEVICE_INDEX: case RIGHT_INDEX: case LEFT_INDEX: InitializeDevice(currState[VRModule.HMD_DEVICE_INDEX], state); break; default: if (state.isConnected) { state.Reset(); } break; } } SelectDevice(currState[VRModule.HMD_DEVICE_INDEX]); } // select/deselect device var keySelectDevice = default(IVRModuleDeviceStateRW); if (GetDeviceByInputDownKeyCode(currState, out keySelectDevice)) { if (IsShiftKeyPressed()) { if (keySelectDevice.isConnected && keySelectDevice.deviceIndex != VRModule.HMD_DEVICE_INDEX) { if (IsSelectedDevice(keySelectDevice)) { DeselectDevice(); } keySelectDevice.Reset(); } } else { if (!IsSelectedDevice(keySelectDevice)) { // select if (!keySelectDevice.isConnected) { InitializeDevice(currState[VRModule.HMD_DEVICE_INDEX], keySelectDevice); } SelectDevice(keySelectDevice); } else { // deselect DeselectDevice(); } } } // control selected device var selectedDevice = VRModule.IsValidDeviceIndex(m_selectedDeviceIndex) && currState[m_selectedDeviceIndex].isConnected ? currState[m_selectedDeviceIndex] : null; if (selectedDevice != null) { ControlDevice(selectedDevice); if (selectedDevice.deviceClass != VRModuleDeviceClass.HMD) { HandleDeviceInput(selectedDevice); } } // control camera if (currState[VRModule.HMD_DEVICE_INDEX].isConnected) { ControlCamera(currState[VRModule.HMD_DEVICE_INDEX]); } } else if (IsDeviceSelected()) { DeselectDevice(); } if (onUpdateDeviceState != null) { onUpdateDeviceState(prevState, currState); } UpdateMainCamTracking(); }