A game about forced loneliness, made by TACStudios
1#if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN || UNITY_WSA
2using System.Runtime.InteropServices;
3using UnityEngine.InputSystem.Layouts;
4using UnityEngine.InputSystem.LowLevel;
5using UnityEngine.InputSystem.XInput.LowLevel;
6using UnityEngine.InputSystem.Utilities;
7using UnityEngine.Scripting;
8
9namespace UnityEngine.InputSystem.XInput.LowLevel
10{
11 // IMPORTANT: State layout is XINPUT_GAMEPAD
12 [StructLayout(LayoutKind.Explicit, Size = 4)]
13 internal struct XInputControllerWindowsState : IInputStateTypeInfo
14 {
15 public FourCC format => new FourCC('X', 'I', 'N', 'P');
16
17 [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1027:MarkEnumsWithFlags", Justification = "False positive")]
18 public enum Button
19 {
20 DPadUp = 0,
21 DPadDown = 1,
22 DPadLeft = 2,
23 DPadRight = 3,
24 Start = 4,
25 Select = 5,
26 LeftThumbstickPress = 6,
27 RightThumbstickPress = 7,
28 LeftShoulder = 8,
29 RightShoulder = 9,
30 A = 12,
31 B = 13,
32 X = 14,
33 Y = 15,
34 }
35
36 [InputControl(name = "dpad", layout = "Dpad", sizeInBits = 4, bit = 0)]
37 [InputControl(name = "dpad/up", bit = (uint)Button.DPadUp)]
38 [InputControl(name = "dpad/down", bit = (uint)Button.DPadDown)]
39 [InputControl(name = "dpad/left", bit = (uint)Button.DPadLeft)]
40 [InputControl(name = "dpad/right", bit = (uint)Button.DPadRight)]
41 [InputControl(name = "start", bit = (uint)Button.Start, displayName = "Start")]
42 [InputControl(name = "select", bit = (uint)Button.Select, displayName = "Select")]
43 [InputControl(name = "leftStickPress", bit = (uint)Button.LeftThumbstickPress)]
44 [InputControl(name = "rightStickPress", bit = (uint)Button.RightThumbstickPress)]
45 [InputControl(name = "leftShoulder", bit = (uint)Button.LeftShoulder)]
46 [InputControl(name = "rightShoulder", bit = (uint)Button.RightShoulder)]
47 [InputControl(name = "buttonSouth", bit = (uint)Button.A, displayName = "A")]
48 [InputControl(name = "buttonEast", bit = (uint)Button.B, displayName = "B")]
49 [InputControl(name = "buttonWest", bit = (uint)Button.X, displayName = "X")]
50 [InputControl(name = "buttonNorth", bit = (uint)Button.Y, displayName = "Y")]
51
52 [FieldOffset(0)]
53 public ushort buttons;
54
55 [InputControl(name = "leftTrigger", format = "BYTE")]
56 [FieldOffset(2)] public byte leftTrigger;
57 [InputControl(name = "rightTrigger", format = "BYTE")]
58 [FieldOffset(3)] public byte rightTrigger;
59
60 [InputControl(name = "leftStick", layout = "Stick", format = "VC2S")]
61 [InputControl(name = "leftStick/x", offset = 0, format = "SHRT", parameters = "clamp=false,invert=false,normalize=false")]
62 [InputControl(name = "leftStick/left", offset = 0, format = "SHRT")]
63 [InputControl(name = "leftStick/right", offset = 0, format = "SHRT")]
64 [InputControl(name = "leftStick/y", offset = 2, format = "SHRT", parameters = "clamp=false,invert=false,normalize=false")]
65 [InputControl(name = "leftStick/up", offset = 2, format = "SHRT")]
66 [InputControl(name = "leftStick/down", offset = 2, format = "SHRT")]
67 [FieldOffset(4)] public short leftStickX;
68 [FieldOffset(6)] public short leftStickY;
69
70 [InputControl(name = "rightStick", layout = "Stick", format = "VC2S")]
71 [InputControl(name = "rightStick/x", offset = 0, format = "SHRT", parameters = "clamp=false,invert=false,normalize=false")]
72 [InputControl(name = "rightStick/left", offset = 0, format = "SHRT")]
73 [InputControl(name = "rightStick/right", offset = 0, format = "SHRT")]
74 [InputControl(name = "rightStick/y", offset = 2, format = "SHRT", parameters = "clamp=false,invert=false,normalize=false")]
75 [InputControl(name = "rightStick/up", offset = 2, format = "SHRT")]
76 [InputControl(name = "rightStick/down", offset = 2, format = "SHRT")]
77 [FieldOffset(8)] public short rightStickX;
78 [FieldOffset(10)] public short rightStickY;
79
80 public XInputControllerWindowsState WithButton(Button button)
81 {
82 Debug.Assert((int)button < 16, $"Expected button < 16, so we fit into the 16 bit wide bitmask");
83 buttons |= (ushort)(1U << (int)button);
84 return this;
85 }
86 }
87}
88
89namespace UnityEngine.InputSystem.XInput
90{
91 /// <summary>
92 /// An <see cref="XInputController"/> compatible game controller connected to a Windows desktop machine.
93 /// </summary>
94 [InputControlLayout(stateType = typeof(XInputControllerWindowsState), hideInUI = true)]
95 public class XInputControllerWindows : XInputController
96 {
97 }
98}
99#endif // UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN || UNITY_WSA