summaryrefslogtreecommitdiff
path: root/Assets/Samples/OpenXR Plugin/1.14.3/Controller/Scripts/ActionToDeviceInfo.cs
blob: 7679092443c15a6d2f6a298f9e170cad82f5747f (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
using System;
using System.Linq;
using UnityEngine.UI;
using UnityEngine.InputSystem;

namespace UnityEngine.XR.OpenXR.Samples.ControllerSample
{
    public class ActionToDeviceInfo : MonoBehaviour
    {
        [SerializeField] private InputActionReference _actionReference = null;

        [SerializeField] private Text _text = null;

        private void OnEnable()
        {
            UpdateText();
        }

        private void UpdateText()
        {
            if (null == _actionReference || null == _actionReference.action || _actionReference.action.controls.Count == 0 || _text == null)
                return;

            var device = _actionReference.action.controls[0].device;
            _text.text = $"{device.name}\n{device.deviceId}\n{string.Join(",", device.usages.Select(u => u.ToString()))}";
        }
    }
}