blob: 60fce5b1e29c275ced28610af577836e7e3b0861 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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<Vector2>();
xAxisSlider.value = value.x;
yAxisSlider.value = value.y;
}
else
{
SetVisible(gameObject, false);
}
}
void SetVisible(GameObject go, bool visible)
{
Graphic graphic = go.GetComponent<Graphic>();
if (graphic != null)
graphic.enabled = visible;
Graphic[] graphics = go.GetComponentsInChildren<Graphic>();
for (int i = 0; i < graphics.Length; i++)
{
graphics[i].enabled = visible;
}
}
}
}
|