diff options
author | pryazha <pryadeiniv@mail.ru> | 2025-07-02 08:46:23 -0700 |
---|---|---|
committer | pryazha <pryadeiniv@mail.ru> | 2025-07-02 08:46:23 -0700 |
commit | 8263edd59284aba390aca011d25b79efecef4c48 (patch) | |
tree | 6346e2afaaabd32156601cafaf20d4ee813befaf /Assets/Samples/OpenXR Plugin/1.14.3/Controller/Scripts/ActionToSliderISX.cs |
Diffstat (limited to 'Assets/Samples/OpenXR Plugin/1.14.3/Controller/Scripts/ActionToSliderISX.cs')
-rw-r--r-- | Assets/Samples/OpenXR Plugin/1.14.3/Controller/Scripts/ActionToSliderISX.cs | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/Assets/Samples/OpenXR Plugin/1.14.3/Controller/Scripts/ActionToSliderISX.cs b/Assets/Samples/OpenXR Plugin/1.14.3/Controller/Scripts/ActionToSliderISX.cs new file mode 100644 index 0000000..02a1e88 --- /dev/null +++ b/Assets/Samples/OpenXR Plugin/1.14.3/Controller/Scripts/ActionToSliderISX.cs @@ -0,0 +1,56 @@ +using UnityEngine.UI; +using UnityEngine.InputSystem; + +namespace UnityEngine.XR.OpenXR.Samples.ControllerSample +{ + public class ActionToSliderISX : MonoBehaviour + { + [SerializeField] + private InputActionReference m_ActionReference; + public InputActionReference actionReference { get => m_ActionReference; set => m_ActionReference = value; } + + [SerializeField] + Slider slider = null; + + Graphic graphic = null; + Graphic[] graphics = new Graphic[] { }; + + private void OnEnable() + { + if (slider == null) + Debug.LogWarning("ActionToSlider Monobehaviour started without any associated slider. This input will not be reported.", this); + + graphic = gameObject.GetComponent<Graphic>(); + graphics = gameObject.GetComponentsInChildren<Graphic>(); + } + + void Update() + { + if (actionReference != null && actionReference.action != null && slider != null) + { + if (actionReference.action.enabled) + { + SetVisible(true); + } + + float value = actionReference.action.ReadValue<float>(); + slider.value = value; + } + else + { + SetVisible(false); + } + } + + void SetVisible(bool visible) + { + if (graphic != null) + graphic.enabled = visible; + + for (int i = 0; i < graphics.Length; i++) + { + graphics[i].enabled = visible; + } + } + } +} |