From 8263edd59284aba390aca011d25b79efecef4c48 Mon Sep 17 00:00:00 2001 From: pryazha Date: Wed, 2 Jul 2025 08:46:23 -0700 Subject: init --- .../Controller/Scripts/ActionToVector2SliderISX.cs | 60 ++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 Assets/Samples/OpenXR Plugin/1.14.3/Controller/Scripts/ActionToVector2SliderISX.cs (limited to 'Assets/Samples/OpenXR Plugin/1.14.3/Controller/Scripts/ActionToVector2SliderISX.cs') diff --git a/Assets/Samples/OpenXR Plugin/1.14.3/Controller/Scripts/ActionToVector2SliderISX.cs b/Assets/Samples/OpenXR Plugin/1.14.3/Controller/Scripts/ActionToVector2SliderISX.cs new file mode 100644 index 0000000..60fce5b --- /dev/null +++ b/Assets/Samples/OpenXR Plugin/1.14.3/Controller/Scripts/ActionToVector2SliderISX.cs @@ -0,0 +1,60 @@ +using UnityEngine.UI; +using UnityEngine.InputSystem; + +namespace UnityEngine.XR.OpenXR.Samples.ControllerSample +{ + public class ActionToVector2SliderISX : MonoBehaviour + { + [SerializeField] + private InputActionReference m_ActionReference; + public InputActionReference actionReference { get => m_ActionReference; set => m_ActionReference = value; } + + [SerializeField] + public Slider xAxisSlider = null; + + [SerializeField] + public Slider yAxisSlider = null; + + + private void OnEnable() + { + if (xAxisSlider == null) + Debug.LogWarning("ActionToSlider Monobehaviour started without any associated X-axis slider. This input won't be reported.", this); + + if (yAxisSlider == null) + Debug.LogWarning("ActionToSlider Monobehaviour started without any associated Y-axis slider. This input won't be reported.", this); + } + + void Update() + { + if (actionReference != null && actionReference.action != null && xAxisSlider != null && yAxisSlider != null) + { + if (actionReference.action.enabled) + { + SetVisible(gameObject, true); + } + + Vector2 value = actionReference.action.ReadValue(); + xAxisSlider.value = value.x; + yAxisSlider.value = value.y; + } + else + { + SetVisible(gameObject, false); + } + } + + void SetVisible(GameObject go, bool visible) + { + Graphic graphic = go.GetComponent(); + if (graphic != null) + graphic.enabled = visible; + + Graphic[] graphics = go.GetComponentsInChildren(); + for (int i = 0; i < graphics.Length; i++) + { + graphics[i].enabled = visible; + } + } + } +} -- cgit v1.2.3-70-g09d2