summaryrefslogtreecommitdiff
path: root/Assets/Samples/OpenXR Plugin/1.14.3/Controller/Scripts/ActionToVector2.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Assets/Samples/OpenXR Plugin/1.14.3/Controller/Scripts/ActionToVector2.cs')
-rw-r--r--Assets/Samples/OpenXR Plugin/1.14.3/Controller/Scripts/ActionToVector2.cs21
1 files changed, 21 insertions, 0 deletions
diff --git a/Assets/Samples/OpenXR Plugin/1.14.3/Controller/Scripts/ActionToVector2.cs b/Assets/Samples/OpenXR Plugin/1.14.3/Controller/Scripts/ActionToVector2.cs
new file mode 100644
index 0000000..cb7e274
--- /dev/null
+++ b/Assets/Samples/OpenXR Plugin/1.14.3/Controller/Scripts/ActionToVector2.cs
@@ -0,0 +1,21 @@
+using UnityEngine.UI;
+using UnityEngine.InputSystem;
+
+namespace UnityEngine.XR.OpenXR.Samples.ControllerSample
+{
+ public class ActionToVector2 : ActionToControl
+ {
+ [SerializeField] public RectTransform _handle = null;
+
+ protected override void OnActionPerformed(InputAction.CallbackContext ctx) => UpdateHandle(ctx);
+
+ protected override void OnActionStarted(InputAction.CallbackContext ctx) => UpdateHandle(ctx);
+
+ protected override void OnActionCanceled(InputAction.CallbackContext ctx) => UpdateHandle(ctx);
+
+ private void UpdateHandle(InputAction.CallbackContext ctx)
+ {
+ _handle.anchorMin = _handle.anchorMax = (ctx.ReadValue<Vector2>() + Vector2.one) * 0.5f;
+ }
+ }
+}