summaryrefslogtreecommitdiff
path: root/Assets/Samples/OpenXR Plugin/1.14.3/Controller/Scripts/ActionToButton.cs
blob: f5378004f85ef89604cccf700db26ae144af65ce (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
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;
        }
    }
}