summaryrefslogtreecommitdiff
path: root/Assets/Samples/OpenXR Plugin/1.14.3/Controller/Scripts/ActionToButton.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Assets/Samples/OpenXR Plugin/1.14.3/Controller/Scripts/ActionToButton.cs')
-rw-r--r--Assets/Samples/OpenXR Plugin/1.14.3/Controller/Scripts/ActionToButton.cs45
1 files changed, 45 insertions, 0 deletions
diff --git a/Assets/Samples/OpenXR Plugin/1.14.3/Controller/Scripts/ActionToButton.cs b/Assets/Samples/OpenXR Plugin/1.14.3/Controller/Scripts/ActionToButton.cs
new file mode 100644
index 0000000..f537800
--- /dev/null
+++ b/Assets/Samples/OpenXR Plugin/1.14.3/Controller/Scripts/ActionToButton.cs
@@ -0,0 +1,45 @@
+using System;
+using System.Collections;
+using UnityEngine.InputSystem;
+using UnityEngine.UI;
+using UnityEngine.XR.Management;
+using UnityEngine.XR.OpenXR.Input;
+
+namespace UnityEngine.XR.OpenXR.Samples.ControllerSample
+{
+ public class ActionToButton : ActionToControl
+ {
+ [SerializeField] private Image _image = null;
+
+ [SerializeField] private Color _normalColor = Color.red;
+
+ [SerializeField] private Color _pressedColor = Color.green;
+
+ private void Awake()
+ {
+ if (_image != null)
+ {
+ _image.enabled = false;
+ _image.color = _normalColor;
+ }
+ }
+
+ protected override void OnActionStarted(InputAction.CallbackContext ctx)
+ {
+ if (_image != null)
+ _image.color = _pressedColor;
+ }
+
+ protected override void OnActionCanceled(InputAction.CallbackContext ctx)
+ {
+ if (_image != null)
+ _image.color = _normalColor;
+ }
+
+ protected override void OnActionBound()
+ {
+ if (_image != null)
+ _image.enabled = true;
+ }
+ }
+}