-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGamepadMap.cs
90 lines (73 loc) · 2.96 KB
/
GamepadMap.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
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
90
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class GamepadMap_DataType
{
/// <summary>
/// gamepadAndroid itu gamepad bluetooth biasa dengan 2 joystick, sedangkan VRBox gamepad yang dipegang cuma pakai 1 tangan hanya dengan 1 joystick
/// </summary>
public enum GamepadType
{
gamepadAndroid, VRBox
}
}
public class GamepadMap : MonoBehaviour
{
public static GamepadMap_DataType.GamepadType usedGamepadType;
//=============================================start
public static bool activatePanel1 = false;
public static bool activatePanel2 = false;
public static bool activatePanel3 = false;
public static bool trigger = false;
public static bool draw = false;
public static bool dirUp = false;
public static bool dirLeft = false;
public static bool dirRight = false;
public static bool dirDown = false;
public static Vector2 leftStick = Vector2.zero;
//=============================================end
protected void OnEnable()
{
InputSystem.EnableDevice(Gamepad.current);
}
protected void OnDisable()
{
InputSystem.DisableDevice(Gamepad.current);
}
// Start is called before the first frame update
void Start()
{
usedGamepadType = (GamepadMap_DataType.GamepadType)PlayerPrefs.GetInt("usedGamepadType", 0);
}
// Update is called once per frame
void Update()
{
var currentData = Gamepad.current;
leftStick = currentData.leftStick.ReadValue();
if (usedGamepadType == GamepadMap_DataType.GamepadType.gamepadAndroid)
{
activatePanel1 = currentData.xButton.wasPressedThisFrame;
activatePanel2 = currentData.bButton.wasPressedThisFrame;
activatePanel3 = currentData.aButton.wasPressedThisFrame;
trigger = currentData.rightTrigger.wasReleasedThisFrame;
draw = currentData.leftShoulder.wasPressedThisFrame;
dirUp = currentData.dpad.up.wasPressedThisFrame;
dirLeft = currentData.dpad.left.wasPressedThisFrame;
dirRight = currentData.dpad.right.wasPressedThisFrame;
dirDown = currentData.dpad.down.wasPressedThisFrame;
}
else if (usedGamepadType == GamepadMap_DataType.GamepadType.VRBox)
{
activatePanel1 = currentData.xButton.wasPressedThisFrame;
activatePanel2 = currentData.bButton.wasPressedThisFrame;
activatePanel3 = currentData.yButton.wasPressedThisFrame;
trigger = currentData.leftShoulder.wasReleasedThisFrame;
draw = currentData.rightShoulder.wasPressedThisFrame;
dirUp = currentData.leftStick.up.wasPressedThisFrame;
dirLeft = currentData.leftStick.left.wasPressedThisFrame;
dirRight = currentData.leftStick.right.wasPressedThisFrame;
dirDown = currentData.leftStick.down.wasPressedThisFrame;
}
}
}