A game about forced loneliness, made by TACStudios
1#if UNITY_EDITOR || UNITY_STANDALONE_LINUX
2using System;
3
4namespace UnityEngine.InputSystem.Linux
5{
6 // These structures are not explicitly assigned, but they are filled in via JSON serialization coming from matching structs in native.
7#pragma warning disable 0649
8
9 internal enum JoystickFeatureType
10 {
11 Invalid = 0,
12 Axis,
13 Ball,
14 Button,
15 Hat,
16
17 Max
18 }
19
20 internal enum SDLAxisUsage
21 {
22 Unknown = 0,
23 X,
24 Y,
25 Z,
26 RotateX,
27 RotateY,
28 RotateZ,
29 Throttle,
30 Rudder,
31 Wheel,
32 Gas,
33 Brake,
34 Hat0X,
35 Hat0Y,
36 Hat1X,
37 Hat1Y,
38 Hat2X,
39 Hat2Y,
40 Hat3X,
41 Hat3Y,
42
43 Count
44 }
45
46 internal enum SDLButtonUsage
47 {
48 Unknown = 0,
49 Trigger,
50 Thumb,
51 Thumb2,
52 Top,
53 Top2,
54 Pinkie,
55 Base,
56 Base2,
57 Base3,
58 Base4,
59 Base5,
60 Base6,
61 Dead,
62
63 A,
64 B,
65 X,
66 Y,
67 Z,
68 TriggerLeft,
69 TriggerRight,
70 TriggerLeft2,
71 TriggerRight2,
72 Select,
73 Start,
74 Mode,
75 ThumbLeft,
76 ThumbRight,
77
78 Count
79 }
80
81 // JSON must match JoystickFeatureDefinition in native.
82 [Serializable]
83 internal struct SDLFeatureDescriptor
84 {
85 public JoystickFeatureType featureType;
86 public int usageHint;
87 public int featureSize;
88 public int offset;
89 public int bit;
90 public int min;
91 public int max;
92 }
93
94 [Serializable]
95 internal class SDLDeviceDescriptor
96 {
97 public SDLFeatureDescriptor[] controls;
98
99 internal string ToJson()
100 {
101 return JsonUtility.ToJson(this);
102 }
103
104 internal static SDLDeviceDescriptor FromJson(string json)
105 {
106 return JsonUtility.FromJson<SDLDeviceDescriptor>(json);
107 }
108 }
109
110#pragma warning restore 0649
111
112 /// <summary>
113 /// A small helper class to aid in initializing and registering SDL devices and layout builders.
114 /// </summary>
115#if UNITY_DISABLE_DEFAULT_INPUT_PLUGIN_INITIALIZATION
116 public
117#else
118 internal
119#endif
120 static class LinuxSupport
121 {
122 /// <summary>
123 /// The current interface code sent with devices to identify as Linux SDL devices.
124 /// </summary>
125 internal const string kInterfaceName = "Linux";
126
127 public static string GetAxisNameFromUsage(SDLAxisUsage usage)
128 {
129 return Enum.GetName(typeof(SDLAxisUsage), usage);
130 }
131
132 public static string GetButtonNameFromUsage(SDLButtonUsage usage)
133 {
134 return Enum.GetName(typeof(SDLButtonUsage), usage);
135 }
136
137 /// <summary>
138 /// Registers all initial templates and the generalized layout builder with the InputSystem.
139 /// </summary>
140 public static void Initialize()
141 {
142 InputSystem.onFindLayoutForDevice += SDLLayoutBuilder.OnFindLayoutForDevice;
143 }
144 }
145}
146#endif // UNITY_EDITOR || UNITY_STANDALONE_LINUX