//デジタルボタンの状態を取得する(生データ) private void GetDigitalActionDataRaw(string ActionPath, out InputDigitalActionData_t data, string RestrictToDevicePath = "") { ReadyCheck(); //実行可能な状態かチェック EVRInputError inputError = EVRInputError.None; data = new InputDigitalActionData_t(); var size = (uint)System.Runtime.InteropServices.Marshal.SizeOf(typeof(InputDigitalActionData_t)); ulong handle = GetActionHandle(ActionPath); //無効なハンドルならthrowされる //制約デバイス指定されていれば適用 ulong DeviceHandle = OpenVR.k_ulInvalidInputValueHandle; if (RestrictToDevicePath != "") { DeviceHandle = GetInputSourceHandle(RestrictToDevicePath); //無効なハンドルならthrowされる } //取得処理 inputError = vrinput.GetDigitalActionData(handle, ref data, size, DeviceHandle); if (inputError == EVRInputError.WrongType) { //デジタルボタンではない throw new ArgumentException(inputError.ToString()); } if (inputError != EVRInputError.None) { //致命的エラー throw new IOException(inputError.ToString()); } return; }
private EVRInputError TryGetDigitalValue(CVRInput vrInput, ulong actionHandle, ulong devicePathHandle, out bool value) { var data = default(InputDigitalActionData_t); var error = vrInput.GetDigitalActionData(actionHandle, ref data, m_digitalDataSize, devicePathHandle); value = data.bState; return(error); }
private bool GetButtonState(ulong handle, ulong hand) { var dataSize = Marshal.SizeOf <InputDigitalActionData_t>(); var data = new InputDigitalActionData_t(); var error = input.GetDigitalActionData(handle, ref data, (uint)dataSize, hand); #if UNITY_EDITOR if (error != EVRInputError.None && error != EVRInputError.NoData) { Debug.LogError("GetDigitalActionData: " + error.ToString()); return(false); } #endif return(data.bState); }
public bool TryGetCurrentDigitalData(CVRInput vrInput, out IVRModuleDeviceState prevState, out IVRModuleDeviceStateRW currState, ref InputDigitalActionData_t data) { ulong originDevicePath; if (!TryGetCurrentOriginDataAndDeviceState(vrInput, out prevState, out currState, out originDevicePath)) { return(false); } var error = vrInput.GetDigitalActionData(CurrentHandle, ref data, s_moduleInstance.m_digitalDataSize, originDevicePath); if (error != EVRInputError.None) { Debug.LogError("GetDigitalActionData failed! action=" + CurrentPath + " error=" + error); return(false); } return(true); }
public void Run() { var ev = new VREvent_t(); var evSize = (uint)Marshal.SizeOf(typeof(VREvent_t)); var actionSets = new VRActiveActionSet_t[] { new VRActiveActionSet_t { ulActionSet = inputSet, }, }; var actionSetSize = (uint)Marshal.SizeOf(typeof(VRActiveActionSet_t)); var actionData = new InputDigitalActionData_t(); var actionDataSize = (uint)Marshal.SizeOf(typeof(InputDigitalActionData_t)); Console.WriteLine("Brightness panic button is running. Input bindings may be changed through SteamVR's input bindings."); var sleepTime = (int)Math.Round(1000 * DT); while (running) { while (vrSystem.PollNextEvent(ref ev, evSize)) { switch ((EVREventType)ev.eventType) { case EVREventType.VREvent_DriverRequestedQuit: case EVREventType.VREvent_Quit: vrSystem.AcknowledgeQuit_Exiting(); running = false; break; } } var inputError = vrInput.UpdateActionState(actionSets, actionSetSize); if (inputError != EVRInputError.None) { var message = inputError.ToString(); throw new Exception($"Failed to update action state: {message}"); } inputError = vrInput.GetDigitalActionData(inputActivate, ref actionData, actionDataSize, 0); if (inputError != EVRInputError.None) { var message = inputError.ToString(); throw new Exception($"Failed to get Activate action state: {message}"); } var activatePressed = actionData.bChanged && actionData.bState; inputError = vrInput.GetDigitalActionData(inputResetAuto, ref actionData, actionDataSize, 0); if (inputError != EVRInputError.None) { var message = inputError.ToString(); throw new Exception($"Failed to get Reset (Auto) action state: {message}"); } var resetAutoPressed = actionData.bChanged && actionData.bState; inputError = vrInput.GetDigitalActionData(inputResetHold, ref actionData, actionDataSize, 0); if (inputError != EVRInputError.None) { var message = inputError.ToString(); throw new Exception($"Failed to get Reset (Hold) action state: {message}"); } var resetHoldChanged = actionData.bChanged; var resetHoldHeld = actionData.bState; if (activatePressed) { TriggerActivate(); } if (initialBrightness.HasValue && resetAutoPressed) { resetting = !resetting; if (resetting) { Console.WriteLine("Starting automatic reset."); } else { Console.WriteLine("Cancelling automatic reset."); } } if (initialBrightness.HasValue && resetHoldChanged) { resetting = resetHoldHeld; if (resetting) { Console.WriteLine("Starting held reset."); } else { Console.WriteLine("Cancelling held reset."); } } if (resetting) { resetting = TriggerReset(DT * RESET_SPEED); if (resetting && (resetAutoPressed || resetHoldChanged)) { try { resetSound.Play(); } catch (FileNotFoundException) {} } } Thread.Sleep(sleepTime); } }