blob: 1bab59e09988eec37df5ca1f9870d54e437c543b (
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
using UnityEngine;
using UnityEngine.UI;
public class UIGamePad : MonoBehaviour
{
public KeyCode m_keyCode;
public string m_zinputKey;
public GameObject m_hint;
private Button m_button;
private Toggle m_toggle;
private UIGroupHandler m_group;
private static int m_lastInteractFrame;
private void Start()
{
m_group = GetComponentInParent<UIGroupHandler>();
m_button = GetComponent<Button>();
m_toggle = GetComponent<Toggle>();
if ((bool)m_hint)
{
m_hint.SetActive(value: false);
}
}
private bool IsInteractive()
{
if (m_button != null && !m_button.IsInteractable())
{
return false;
}
if ((bool)m_toggle)
{
if (!m_toggle.IsInteractable())
{
return false;
}
if ((bool)m_toggle.group && !m_toggle.group.allowSwitchOff && m_toggle.isOn)
{
return false;
}
}
if ((bool)m_group && !m_group.IsActive())
{
return false;
}
return true;
}
private void Update()
{
bool flag = IsInteractive();
if ((bool)m_hint)
{
m_hint.SetActive(flag && ZInput.IsGamepadActive());
}
if (flag && Time.frameCount - m_lastInteractFrame >= 2 && ButtonPressed())
{
m_lastInteractFrame = Time.frameCount;
ZLog.Log("Button pressed " + base.gameObject.name + " frame:" + Time.frameCount);
if (m_button != null)
{
m_button.OnSubmit(null);
}
if (m_toggle != null)
{
m_toggle.OnSubmit(null);
}
}
}
private bool ButtonPressed()
{
if (!string.IsNullOrEmpty(m_zinputKey) && ZInput.GetButtonDown(m_zinputKey))
{
return true;
}
if (m_keyCode != 0 && Input.GetKeyDown(m_keyCode))
{
return true;
}
return false;
}
}
|