//========= Copyright 2016-2023, HTC Corporation. All rights reserved. =========== using HTC.UnityPlugin.Utility; using HTC.UnityPlugin.VRModuleManagement; using System; using System.Collections.Generic; using UnityEngine; namespace HTC.UnityPlugin.Vive { /// /// To provide static APIs to retrieve controller's button status /// [DisallowMultipleComponent] public partial class ViveInput : SingletonBehaviour { #region origin /// /// Returns true while the button on the controller identified by role is held down /// public static bool GetPress(HandRole role, ControllerButton button) { return GetPressEx(role, button); } public static ulong GetPress(HandRole role, bool usePrevState = false) { return usePrevState ? GetState(role).PreviousButtonPressed : GetState(role).CurrentButtonPressed; } /// /// Returns true during the frame the user pressed down the button on the controller identified by role /// public static bool GetPressDown(HandRole role, ControllerButton button) { return GetPressDownEx(role, button); } /// /// Returns true during the frame the user releases the button on the controller identified by role /// public static bool GetPressUp(HandRole role, ControllerButton button) { return GetPressUpEx(role, button); } /// /// Returns time of the last frame that user pressed down the button on the controller identified by role /// public static float LastPressDownTime(HandRole role, ControllerButton button) { return LastPressDownTimeEx(role, button); } /// /// Return amount of clicks in a row for the button on the controller identified by role /// Set ViveInput.clickInterval to configure click interval /// public static int ClickCount(HandRole role, ControllerButton button) { return ClickCountEx(role, button); } public static float GetAxis(HandRole role, ControllerAxis axis, bool usePrevState = false) { return GetAxisEx(role, axis, usePrevState); } /// /// Returns raw analog value of the trigger button on the controller identified by role /// public static float GetTriggerValue(HandRole role, bool usePrevState = false) { return GetTriggerValueEx(role, usePrevState); } /// /// Returns raw analog value of the touch pad on the controller identified by role /// public static Vector2 GetPadAxis(HandRole role, bool usePrevState = false) { return GetPadAxisEx(role, usePrevState); } /// /// Returns raw analog value of the touch pad on the controller identified by role if pressed, /// otherwise, returns Vector2.zero /// public static Vector2 GetPadPressAxis(HandRole role) { return GetPadPressAxisEx(role); } /// /// Returns raw analog value of the touch pad on the controller identified by role if touched, /// otherwise, returns Vector2.zero /// public static Vector2 GetPadTouchAxis(HandRole role) { return GetPadTouchAxisEx(role); } public static Vector2 GetPadPressVector(HandRole role) { return GetPadPressVectorEx(role); } public static Vector2 GetPadTouchVector(HandRole role) { return GetPadTouchVectorEx(role); } public static Vector2 GetPadPressDelta(HandRole role) { return GetPadPressDeltaEx(role); } public static Vector2 GetPadTouchDelta(HandRole role) { return GetPadTouchDeltaEx(role); } public static Vector2 GetScrollDelta(HandRole role, ScrollType scrollType, Vector2 scale, ControllerAxis xAxis = ControllerAxis.PadX, ControllerAxis yAxis = ControllerAxis.PadY) { return GetScrollDeltaEx(role, scrollType, scale, xAxis, yAxis); } /// /// Add press handler for the button on the controller identified by role /// public static void AddPress(HandRole role, ControllerButton button, Action callback) { AddListenerEx(role, button, ButtonEventType.Press, callback); } /// /// Add press down handler for the button on the controller identified by role /// public static void AddPressDown(HandRole role, ControllerButton button, Action callback) { AddListenerEx(role, button, ButtonEventType.Down, callback); } /// /// Add press up handler for the button on the controller identified by role /// public static void AddPressUp(HandRole role, ControllerButton button, Action callback) { AddListenerEx(role, button, ButtonEventType.Up, callback); } /// /// Add click handler for the button on the controller identified by role /// Use ViveInput.ClickCount to get click count /// public static void AddClick(HandRole role, ControllerButton button, Action callback) { AddListenerEx(role, button, ButtonEventType.Click, callback); } /// /// Remove press handler for the button on the controller identified by role /// public static void RemovePress(HandRole role, ControllerButton button, Action callback) { RemoveListenerEx(role, button, ButtonEventType.Press, callback); } /// /// Remove press down handler for the button on the controller identified by role /// public static void RemovePressDown(HandRole role, ControllerButton button, Action callback) { RemoveListenerEx(role, button, ButtonEventType.Down, callback); } /// /// Remove press up handler for the button on the controller identified by role /// public static void RemovePressUp(HandRole role, ControllerButton button, Action callback) { RemoveListenerEx(role, button, ButtonEventType.Up, callback); } /// /// Remove click handler for the button on the controller identified by role /// public static void RemoveClick(HandRole role, ControllerButton button, Action callback) { RemoveListenerEx(role, button, ButtonEventType.Click, callback); } /// /// Trigger vibration of the controller identified by role /// public static void TriggerHapticPulse(HandRole role, ushort durationMicroSec = 500) { TriggerHapticPulseEx(role, durationMicroSec); } /// /// Trigger vibration of the controller identified by role /// public static void TriggerHapticVibration(HandRole role, float durationSeconds = 0.01f, float frequency = 85f, float amplitude = 0.125f, float startSecondsFromNow = 0f) { TriggerHapticVibrationEx(role, durationSeconds, frequency, amplitude, startSecondsFromNow); } #endregion origin #region general role property /// /// Returns true while the button on the controller identified by role is held down /// public static bool GetPress(ViveRoleProperty role, ControllerButton button) { return GetPressEx(role.roleType, role.roleValue, button); } public static ulong GetPress(ViveRoleProperty role, bool usePrevState = false) { return usePrevState ? GetState(role.roleType, role.roleValue).PreviousButtonPressed : GetState(role.roleType, role.roleValue).CurrentButtonPressed; } /// /// Returns true during the frame the user pressed down the button on the controller identified by role /// public static bool GetPressDown(ViveRoleProperty role, ControllerButton button) { return GetPressDownEx(role.roleType, role.roleValue, button); } /// /// Returns true during the frame the user releases the button on the controller identified by role /// public static bool GetPressUp(ViveRoleProperty role, ControllerButton button) { return GetPressUpEx(role.roleType, role.roleValue, button); } /// /// Returns time of the last frame that user pressed down the button on the controller identified by role /// public static float LastPressDownTime(ViveRoleProperty role, ControllerButton button) { return LastPressDownTimeEx(role.roleType, role.roleValue, button); } /// /// Return amount of clicks in a row for the button on the controller identified by role /// Set ViveInput.clickInterval to configure click interval /// public static int ClickCount(ViveRoleProperty role, ControllerButton button) { return ClickCountEx(role.roleType, role.roleValue, button); } public static float GetAxis(ViveRoleProperty role, ControllerAxis axis, bool usePrevState = false) { return GetAxisEx(role.roleType, role.roleValue, axis, usePrevState); } /// /// Returns raw analog value of the trigger button on the controller identified by role /// public static float GetTriggerValue(ViveRoleProperty role, bool usePrevState = false) { return GetTriggerValueEx(role.roleType, role.roleValue, usePrevState); } /// /// Returns raw analog value of the touch pad on the controller identified by role /// public static Vector2 GetPadAxis(ViveRoleProperty role, bool usePrevState = false) { return GetPadAxisEx(role.roleType, role.roleValue, usePrevState); } /// /// Returns raw analog value of the touch pad on the controller identified by role if pressed, /// otherwise, returns Vector2.zero /// public static Vector2 GetPadPressAxis(ViveRoleProperty role) { return GetPadPressAxisEx(role.roleType, role.roleValue); } /// /// Returns raw analog value of the touch pad on the controller identified by role if touched, /// otherwise, returns Vector2.zero /// public static Vector2 GetPadTouchAxis(ViveRoleProperty role) { return GetPadTouchAxisEx(role.roleType, role.roleValue); } public static Vector2 GetPadPressVector(ViveRoleProperty role) { return GetPadPressVectorEx(role.roleType, role.roleValue); } public static Vector2 GetPadTouchVector(ViveRoleProperty role) { return GetPadTouchVectorEx(role.roleType, role.roleValue); } public static Vector2 GetPadPressDelta(ViveRoleProperty role) { return GetPadPressDeltaEx(role.roleType, role.roleValue); } public static Vector2 GetPadTouchDelta(ViveRoleProperty role) { return GetPadTouchDeltaEx(role.roleType, role.roleValue); } public static Vector2 GetScrollDelta(ViveRoleProperty role, ScrollType scrollType, Vector2 scale, ControllerAxis xAxis = ControllerAxis.PadX, ControllerAxis yAxis = ControllerAxis.PadY) { return GetScrollDeltaEx(role.roleType, role.roleValue, scrollType, scale, xAxis, yAxis); } public static void AddListener(ViveRoleProperty role, ControllerButton button, ButtonEventType eventType, Action callback) { AddListenerEx(role.roleType, role.roleValue, button, eventType, callback); } public static void RemoveListener(ViveRoleProperty role, ControllerButton button, ButtonEventType eventType, Action callback) { RemoveListenerEx(role.roleType, role.roleValue, button, eventType, callback); } public static void AddListener(ViveRoleProperty role, ControllerButton button, ButtonEventType eventType, RoleValueEventListener callback) { AddListenerEx(role.roleType, role.roleValue, button, eventType, callback); } public static void RemoveListener(ViveRoleProperty role, ControllerButton button, ButtonEventType eventType, RoleValueEventListener callback) { RemoveListenerEx(role.roleType, role.roleValue, button, eventType, callback); } /// /// Trigger vibration of the controller identified by role /// public static void TriggerHapticPulse(ViveRoleProperty role, ushort durationMicroSec = 500) { TriggerHapticPulseEx(role.roleType, role.roleValue, durationMicroSec); } /// /// Trigger vibration of the controller identified by role /// public static void TriggerHapticVibration(ViveRoleProperty role, float durationSeconds = 0.01f, float frequency = 85f, float amplitude = 0.125f, float startSecondsFromNow = 0f) { TriggerHapticVibrationEx(role.roleType, role.roleValue, durationSeconds, frequency, amplitude, startSecondsFromNow); } #endregion #region extend generic role /// /// Can be DeviceRole, TrackerRole or any other enum type that have ViveRoleEnumAttribute. /// Use ViveRole.ValidateViveRoleEnum() to validate role type /// /// /// TRole can be DeviceRole, TrackerRole or any other enum type that have ViveRoleEnumAttribute. /// Use ViveRole.ValidateViveRoleEnum() to validate role type /// public static bool GetPressEx(TRole role, ControllerButton button) { return GetState(role).GetPress(button); } public static ulong GetPressEx(TRole role, bool usePrevState = false) { return usePrevState ? GetState(role).PreviousButtonPressed : GetState(role).CurrentButtonPressed; } /// /// Can be DeviceRole, TrackerRole or any other enum type that have ViveRoleEnumAttribute. /// Use ViveRole.ValidateViveRoleEnum() to validate role type /// /// /// TRole can be DeviceRole, TrackerRole or any other enum type that have ViveRoleEnumAttribute. /// Use ViveRole.ValidateViveRoleEnum() to validate role type /// public static bool GetPressDownEx(TRole role, ControllerButton button) { return GetState(role).GetPressDown(button); } /// /// Can be DeviceRole, TrackerRole or any other enum type that have ViveRoleEnumAttribute. /// Use ViveRole.ValidateViveRoleEnum() to validate role type /// /// /// TRole can be DeviceRole, TrackerRole or any other enum type that have ViveRoleEnumAttribute. /// Use ViveRole.ValidateViveRoleEnum() to validate role type /// public static bool GetPressUpEx(TRole role, ControllerButton button) { return GetState(role).GetPressUp(button); } /// /// Can be DeviceRole, TrackerRole or any other enum type that have ViveRoleEnumAttribute. /// Use ViveRole.ValidateViveRoleEnum() to validate role type /// /// /// TRole can be DeviceRole, TrackerRole or any other enum type that have ViveRoleEnumAttribute. /// Use ViveRole.ValidateViveRoleEnum() to validate role type /// public static float LastPressDownTimeEx(TRole role, ControllerButton button) { return GetState(role).LastPressDownTime(button); } /// /// Can be DeviceRole, TrackerRole or any other enum type that have ViveRoleEnumAttribute. /// Use ViveRole.ValidateViveRoleEnum() to validate role type /// /// /// TRole can be DeviceRole, TrackerRole or any other enum type that have ViveRoleEnumAttribute. /// Use ViveRole.ValidateViveRoleEnum() to validate role type /// public static int ClickCountEx(TRole role, ControllerButton button) { return GetState(role).ClickCount(button); } public static float GetAxisEx(TRole role, ControllerAxis axis, bool usePrevState = false) { return GetState(role).GetAxis(axis, usePrevState); } /// /// Can be DeviceRole, TrackerRole or any other enum type that have ViveRoleEnumAttribute. /// Use ViveRole.ValidateViveRoleEnum() to validate role type /// /// /// TRole can be DeviceRole, TrackerRole or any other enum type that have ViveRoleEnumAttribute. /// Use ViveRole.ValidateViveRoleEnum() to validate role type /// public static float GetTriggerValueEx(TRole role, bool usePrevState = false) { return GetState(role).GetAxis(ControllerAxis.Trigger, usePrevState); } /// /// Can be DeviceRole, TrackerRole or any other enum type that have ViveRoleEnumAttribute. /// Use ViveRole.ValidateViveRoleEnum() to validate role type /// /// /// TRole can be DeviceRole, TrackerRole or any other enum type that have ViveRoleEnumAttribute. /// Use ViveRole.ValidateViveRoleEnum() to validate role type /// public static Vector2 GetPadAxisEx(TRole role, bool usePrevState = false) { return GetState(role).GetPadAxis(usePrevState); } /// /// Can be DeviceRole, TrackerRole or any other enum type that have ViveRoleEnumAttribute. /// Use ViveRole.ValidateViveRoleEnum() to validate role type /// /// /// TRole can be DeviceRole, TrackerRole or any other enum type that have ViveRoleEnumAttribute. /// Use ViveRole.ValidateViveRoleEnum() to validate role type /// public static Vector2 GetPadPressAxisEx(TRole role) { var handState = GetState(role); return handState.GetPress(ControllerButton.Pad) ? handState.GetPadAxis() : Vector2.zero; } /// /// Can be DeviceRole, TrackerRole or any other enum type that have ViveRoleEnumAttribute. /// Use ViveRole.ValidateViveRoleEnum() to validate role type /// /// /// TRole can be DeviceRole, TrackerRole or any other enum type that have ViveRoleEnumAttribute. /// Use ViveRole.ValidateViveRoleEnum() to validate role type /// public static Vector2 GetPadTouchAxisEx(TRole role) { var handState = GetState(role); return handState.GetPress(ControllerButton.PadTouch) ? handState.GetPadAxis() : Vector2.zero; } /// /// Can be DeviceRole, TrackerRole or any other enum type that have ViveRoleEnumAttribute. /// Use ViveRole.ValidateViveRoleEnum() to validate role type /// /// /// TRole can be DeviceRole, TrackerRole or any other enum type that have ViveRoleEnumAttribute. /// Use ViveRole.ValidateViveRoleEnum() to validate role type /// public static Vector2 GetPadPressVectorEx(TRole role) { return GetState(role).GetPadPressVector(); } /// /// Can be DeviceRole, TrackerRole or any other enum type that have ViveRoleEnumAttribute. /// Use ViveRole.ValidateViveRoleEnum() to validate role type /// /// /// TRole can be DeviceRole, TrackerRole or any other enum type that have ViveRoleEnumAttribute. /// Use ViveRole.ValidateViveRoleEnum() to validate role type /// public static Vector2 GetPadTouchVectorEx(TRole role) { return GetState(role).GetPadTouchVector(); } /// /// Can be DeviceRole, TrackerRole or any other enum type that have ViveRoleEnumAttribute. /// Use ViveRole.ValidateViveRoleEnum() to validate role type /// /// /// TRole can be DeviceRole, TrackerRole or any other enum type that have ViveRoleEnumAttribute. /// Use ViveRole.ValidateViveRoleEnum() to validate role type /// public static Vector2 GetPadPressDeltaEx(TRole role) { var handState = GetState(role); if (handState.GetPress(ControllerButton.Pad) && !handState.GetPressDown(ControllerButton.Pad)) { return handState.GetPadAxis() - handState.GetPadAxis(true); } return Vector2.zero; } /// /// Can be DeviceRole, TrackerRole or any other enum type that have ViveRoleEnumAttribute. /// Use ViveRole.ValidateViveRoleEnum() to validate role type /// /// /// TRole can be DeviceRole, TrackerRole or any other enum type that have ViveRoleEnumAttribute. /// Use ViveRole.ValidateViveRoleEnum() to validate role type /// public static Vector2 GetPadTouchDeltaEx(TRole role) { var handState = GetState(role); if (handState.GetPress(ControllerButton.PadTouch) && !handState.GetPressDown(ControllerButton.PadTouch)) { return handState.GetPadAxis() - handState.GetPadAxis(true); } return Vector2.zero; } /// /// Can be DeviceRole, TrackerRole or any other enum type that have ViveRoleEnumAttribute. /// Use ViveRole.ValidateViveRoleEnum() to validate role type /// /// /// TRole can be DeviceRole, TrackerRole or any other enum type that have ViveRoleEnumAttribute. /// Use ViveRole.ValidateViveRoleEnum() to validate role type /// public static Vector2 GetScrollDeltaEx(TRole role, ScrollType scrollType, Vector2 scale, ControllerAxis xAxis = ControllerAxis.PadX, ControllerAxis yAxis = ControllerAxis.PadY) { return GetState(role).GetScrollDelta(scrollType, scale, xAxis, yAxis); } /// /// Can be DeviceRole, TrackerRole or any other enum type that have ViveRoleEnumAttribute. /// Use ViveRole.ValidateViveRoleEnum() to validate role type /// /// /// TRole can be DeviceRole, TrackerRole or any other enum type that have ViveRoleEnumAttribute. /// Use ViveRole.ValidateViveRoleEnum() to validate role type /// public static void AddListenerEx(TRole role, ControllerButton button, ButtonEventType eventType, Action callback) { GetState(role).AddListener(button, callback, eventType); } /// /// Can be DeviceRole, TrackerRole or any other enum type that have ViveRoleEnumAttribute. /// Use ViveRole.ValidateViveRoleEnum() to validate role type /// /// /// TRole can be DeviceRole, TrackerRole or any other enum type that have ViveRoleEnumAttribute. /// Use ViveRole.ValidateViveRoleEnum() to validate role type /// public static void RemoveListenerEx(TRole role, ControllerButton button, ButtonEventType eventType, Action callback) { GetState(role).RemoveListener(button, callback, eventType); } /// /// Can be DeviceRole, TrackerRole or any other enum type that have ViveRoleEnumAttribute. /// Use ViveRole.ValidateViveRoleEnum() to validate role type /// /// /// TRole can be DeviceRole, TrackerRole or any other enum type that have ViveRoleEnumAttribute. /// Use ViveRole.ValidateViveRoleEnum() to validate role type /// public static void AddListenerEx(TRole role, ControllerButton button, ButtonEventType eventType, RoleValueEventListener callback) { GetState(role).AddListener(button, callback, eventType); } /// /// Can be DeviceRole, TrackerRole or any other enum type that have ViveRoleEnumAttribute. /// Use ViveRole.ValidateViveRoleEnum() to validate role type /// /// /// TRole can be DeviceRole, TrackerRole or any other enum type that have ViveRoleEnumAttribute. /// Use ViveRole.ValidateViveRoleEnum() to validate role type /// public static void RemoveListenerEx(TRole role, ControllerButton button, ButtonEventType eventType, RoleValueEventListener callback) { GetState(role).RemoveListener(button, callback, eventType); } /// /// Can be DeviceRole, TrackerRole or any other enum type that have ViveRoleEnumAttribute. /// Use ViveRole.ValidateViveRoleEnum() to validate role type /// /// /// TRole can be DeviceRole, TrackerRole or any other enum type that have ViveRoleEnumAttribute. /// Use ViveRole.ValidateViveRoleEnum() to validate role type /// public static void AddListenerEx(TRole role, ControllerButton button, ButtonEventType eventType, RoleEventListener callback) { GetState(role).AddListener(button, callback, eventType); } /// /// Can be DeviceRole, TrackerRole or any other enum type that have ViveRoleEnumAttribute. /// Use ViveRole.ValidateViveRoleEnum() to validate role type /// /// /// TRole can be DeviceRole, TrackerRole or any other enum type that have ViveRoleEnumAttribute. /// Use ViveRole.ValidateViveRoleEnum() to validate role type /// public static void RemoveListenerEx(TRole role, ControllerButton button, ButtonEventType eventType, RoleEventListener callback) { GetState(role).RemoveListener(button, callback, eventType); } /// /// Can be DeviceRole, TrackerRole or any other enum type that have ViveRoleEnumAttribute. /// Use ViveRole.ValidateViveRoleEnum() to validate role type /// /// /// TRole can be DeviceRole, TrackerRole or any other enum type that have ViveRoleEnumAttribute. /// Use ViveRole.ValidateViveRoleEnum() to validate role type /// public static void TriggerHapticPulseEx(TRole role, ushort durationMicroSec = 500) { VRModule.TriggerViveControllerHaptic(ViveRole.GetDeviceIndexEx(role), durationMicroSec); } /// /// Can be DeviceRole, TrackerRole or any other enum type that have ViveRoleEnumAttribute. /// Use ViveRole.ValidateViveRoleEnum() to validate role type /// /// /// TRole can be DeviceRole, TrackerRole or any other enum type that have ViveRoleEnumAttribute. /// Use ViveRole.ValidateViveRoleEnum() to validate role type /// public static void TriggerHapticVibrationEx(TRole role, float durationSeconds = 0.01f, float frequency = 85f, float amplitude = 0.125f, float startSecondsFromNow = 0f) { VRModule.TriggerHapticVibration(ViveRole.GetDeviceIndexEx(role), durationSeconds, frequency, amplitude, startSecondsFromNow); } #endregion extend generic #region extend property role type & value /// /// Can be DeviceRole, TrackerRole or any other enum type that have ViveRoleEnumAttribute. /// Use ViveRole.ValidateViveRoleEnum() to validate role type /// public static bool GetPressEx(Type roleType, int roleValue, ControllerButton button) { return GetState(roleType, roleValue).GetPress(button); } public static ulong GetPressEx(Type roleType, int roleValue, bool usePrevState = false) { return usePrevState ? GetState(roleType, roleValue).PreviousButtonPressed : GetState(roleType, roleValue).CurrentButtonPressed; } /// /// Can be DeviceRole, TrackerRole or any other enum type that have ViveRoleEnumAttribute. /// Use ViveRole.ValidateViveRoleEnum() to validate role type /// public static bool GetPressDownEx(Type roleType, int roleValue, ControllerButton button) { return GetState(roleType, roleValue).GetPressDown(button); } /// /// Can be DeviceRole, TrackerRole or any other enum type that have ViveRoleEnumAttribute. /// Use ViveRole.ValidateViveRoleEnum() to validate role type /// public static bool GetPressUpEx(Type roleType, int roleValue, ControllerButton button) { return GetState(roleType, roleValue).GetPressUp(button); } /// /// Can be DeviceRole, TrackerRole or any other enum type that have ViveRoleEnumAttribute. /// Use ViveRole.ValidateViveRoleEnum() to validate role type /// public static float LastPressDownTimeEx(Type roleType, int roleValue, ControllerButton button) { return GetState(roleType, roleValue).LastPressDownTime(button); } /// /// Can be DeviceRole, TrackerRole or any other enum type that have ViveRoleEnumAttribute. /// Use ViveRole.ValidateViveRoleEnum() to validate role type /// public static int ClickCountEx(Type roleType, int roleValue, ControllerButton button) { return GetState(roleType, roleValue).ClickCount(button); } public static float GetAxisEx(Type roleType, int roleValue, ControllerAxis axis, bool usePrevState = false) { return GetState(roleType, roleValue).GetAxis(axis, usePrevState); } /// /// Can be DeviceRole, TrackerRole or any other enum type that have ViveRoleEnumAttribute. /// Use ViveRole.ValidateViveRoleEnum() to validate role type /// public static float GetTriggerValueEx(Type roleType, int roleValue, bool usePrevState = false) { return GetState(roleType, roleValue).GetAxis(ControllerAxis.Trigger, usePrevState); } /// /// Can be DeviceRole, TrackerRole or any other enum type that have ViveRoleEnumAttribute. /// Use ViveRole.ValidateViveRoleEnum() to validate role type /// public static Vector2 GetPadAxisEx(Type roleType, int roleValue, bool usePrevState = false) { return GetState(roleType, roleValue).GetPadAxis(usePrevState); } /// /// Can be DeviceRole, TrackerRole or any other enum type that have ViveRoleEnumAttribute. /// Use ViveRole.ValidateViveRoleEnum() to validate role type /// public static Vector2 GetPadPressAxisEx(Type roleType, int roleValue) { var handState = GetState(roleType, roleValue); return handState.GetPress(ControllerButton.Pad) ? handState.GetPadAxis() : Vector2.zero; } /// /// Can be DeviceRole, TrackerRole or any other enum type that have ViveRoleEnumAttribute. /// Use ViveRole.ValidateViveRoleEnum() to validate role type /// public static Vector2 GetPadTouchAxisEx(Type roleType, int roleValue) { var handState = GetState(roleType, roleValue); return handState.GetPress(ControllerButton.PadTouch) ? handState.GetPadAxis() : Vector2.zero; } /// /// Can be DeviceRole, TrackerRole or any other enum type that have ViveRoleEnumAttribute. /// Use ViveRole.ValidateViveRoleEnum() to validate role type /// public static Vector2 GetPadPressVectorEx(Type roleType, int roleValue) { return GetState(roleType, roleValue).GetPadPressVector(); } /// /// Can be DeviceRole, TrackerRole or any other enum type that have ViveRoleEnumAttribute. /// Use ViveRole.ValidateViveRoleEnum() to validate role type /// public static Vector2 GetPadTouchVectorEx(Type roleType, int roleValue) { return GetState(roleType, roleValue).GetPadTouchVector(); } /// /// Can be DeviceRole, TrackerRole or any other enum type that have ViveRoleEnumAttribute. /// Use ViveRole.ValidateViveRoleEnum() to validate role type /// public static Vector2 GetPadPressDeltaEx(Type roleType, int roleValue) { var handState = GetState(roleType, roleValue); if (handState.GetPress(ControllerButton.Pad) && !handState.GetPressDown(ControllerButton.Pad)) { return handState.GetPadAxis() - handState.GetPadAxis(true); } return Vector2.zero; } /// /// Can be DeviceRole, TrackerRole or any other enum type that have ViveRoleEnumAttribute. /// Use ViveRole.ValidateViveRoleEnum() to validate role type /// public static Vector2 GetPadTouchDeltaEx(Type roleType, int roleValue) { var handState = GetState(roleType, roleValue); if (handState.GetPress(ControllerButton.PadTouch) && !handState.GetPressDown(ControllerButton.PadTouch)) { return handState.GetPadAxis() - handState.GetPadAxis(true); } return Vector2.zero; } public static Vector2 GetScrollDeltaEx(Type roleType, int roleValue, ScrollType scrollType, Vector2 scale, ControllerAxis xAxis = ControllerAxis.PadX, ControllerAxis yAxis = ControllerAxis.PadY) { return GetState(roleType, roleValue).GetScrollDelta(scrollType, scale, xAxis, yAxis); } /// /// Can be DeviceRole, TrackerRole or any other enum type that have ViveRoleEnumAttribute. /// Use ViveRole.ValidateViveRoleEnum() to validate role type /// public static void AddListenerEx(Type roleType, int roleValue, ControllerButton button, ButtonEventType eventType, Action callback) { GetState(roleType, roleValue).AddListener(button, callback, eventType); } /// /// Can be DeviceRole, TrackerRole or any other enum type that have ViveRoleEnumAttribute. /// Use ViveRole.ValidateViveRoleEnum() to validate role type /// public static void RemoveListenerEx(Type roleType, int roleValue, ControllerButton button, ButtonEventType eventType, Action callback) { GetState(roleType, roleValue).RemoveListener(button, callback, eventType); } /// /// Can be DeviceRole, TrackerRole or any other enum type that have ViveRoleEnumAttribute. /// Use ViveRole.ValidateViveRoleEnum() to validate role type /// public static void AddListenerEx(Type roleType, int roleValue, ControllerButton button, ButtonEventType eventType, RoleValueEventListener callback) { GetState(roleType, roleValue).AddListener(button, callback, eventType); } /// /// Can be DeviceRole, TrackerRole or any other enum type that have ViveRoleEnumAttribute. /// Use ViveRole.ValidateViveRoleEnum() to validate role type /// public static void RemoveListenerEx(Type roleType, int roleValue, ControllerButton button, ButtonEventType eventType, RoleValueEventListener callback) { GetState(roleType, roleValue).RemoveListener(button, callback, eventType); } /// /// Can be DeviceRole, TrackerRole or any other enum type that have ViveRoleEnumAttribute. /// Use ViveRole.ValidateViveRoleEnum() to validate role type /// public static void TriggerHapticPulseEx(Type roleType, int roleValue, ushort durationMicroSec = 500) { VRModule.TriggerViveControllerHaptic(ViveRole.GetDeviceIndexEx(roleType, roleValue), durationMicroSec); } /// /// Can be DeviceRole, TrackerRole or any other enum type that have ViveRoleEnumAttribute. /// Use ViveRole.ValidateViveRoleEnum() to validate role type /// public static void TriggerHapticVibrationEx(Type roleType, int roleValue, float durationSeconds = 0.01f, float frequency = 85f, float amplitude = 0.125f, float startSecondsFromNow = 0f) { VRModule.TriggerHapticVibration(ViveRole.GetDeviceIndexEx(roleType, roleValue), durationSeconds, frequency, amplitude, startSecondsFromNow); } #endregion extend general } }