-
Notifications
You must be signed in to change notification settings - Fork 2
/
DPad.cs
61 lines (49 loc) · 2.37 KB
/
DPad.cs
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
using UnityEngine;
namespace CaptainShotgunModes
{
enum DPadInput { Left, Right, Up, Down, Count }
enum DPadAxis { Horizontal, Vertical, Count }
class DPad
{
private static bool[] inputDownList = new bool [(int)DPadInput.Count];
private static bool[] inputUpList = new bool [(int)DPadInput.Count];
private static float[] axisValueList = new float [(int)DPadAxis.Count];
public static void Update()
{
// TODO: this might only work with xbox 360 and xbox one contollers
float horizontal = Input.GetAxis("Joy1Axis6");
float vertical = Input.GetAxis("Joy1Axis7");
inputDownList[(int)DPadInput.Left] = horizontal < 0f && axisValueList[(int)DPadAxis.Horizontal] == 0f;
inputDownList[(int)DPadInput.Right] = horizontal > 0f && axisValueList[(int)DPadAxis.Horizontal] == 0f;
inputDownList[(int)DPadInput.Up] = vertical > 0f && axisValueList[(int)DPadAxis.Vertical] == 0f;
inputDownList[(int)DPadInput.Down] = vertical < 0f && axisValueList[(int)DPadAxis.Vertical] == 0f;
inputUpList[(int)DPadInput.Left] = horizontal == 0f && axisValueList[(int)DPadAxis.Horizontal] < 0f;
inputUpList[(int)DPadInput.Right] = horizontal == 0f && axisValueList[(int)DPadAxis.Horizontal] > 0f;
inputUpList[(int)DPadInput.Up] = vertical == 0f && axisValueList[(int)DPadAxis.Vertical] > 0f;
inputUpList[(int)DPadInput.Down] = vertical == 0f && axisValueList[(int)DPadAxis.Vertical] < 0f;
axisValueList[(int)DPadAxis.Horizontal] = horizontal;
axisValueList[(int)DPadAxis.Vertical] = vertical;
}
public static bool GetInputDown(DPadInput input)
{
if (input < 0 || input >= DPadInput.Count) {
return false;
}
return inputDownList[(int)input];
}
public static bool GetInputUp(DPadInput input)
{
if (input < 0 || input >= DPadInput.Count) {
return false;
}
return inputUpList[(int)input];
}
public static float GetAxis(DPadAxis axis)
{
if (axis < 0 || axis >= DPadAxis.Count) {
return 0f;
}
return axisValueList[(int)axis];
}
}
}