A game about forced loneliness, made by TACStudios
1#if UNITY_EDITOR || UNITY_IOS || UNITY_TVOS || UNITY_VISIONOS || PACKAGE_DOCS_GENERATION
2using System.Runtime.InteropServices;
3using UnityEngine.InputSystem.DualShock;
4using UnityEngine.InputSystem.Layouts;
5using UnityEngine.InputSystem.LowLevel;
6using UnityEngine.InputSystem.iOS.LowLevel;
7using UnityEngine.InputSystem.Utilities;
8
9namespace UnityEngine.InputSystem.iOS.LowLevel
10{
11 internal enum iOSButton
12 {
13 DpadUp,
14 DpadDown,
15 DpadLeft,
16 DpadRight,
17 LeftStick,
18 RightStick,
19 LeftShoulder,
20 RightShoulder,
21 LeftTrigger,
22 RightTrigger,
23 X,
24 Y,
25 A,
26 B,
27 Start,
28 Select
29
30 // Note: If you'll add an element here, be sure to update kMaxButtons const below
31 };
32
33 internal enum iOSAxis
34 {
35 LeftStickX,
36 LeftStickY,
37 RightStickX,
38 RightStickY
39
40 // Note: If you'll add an element here, be sure to update kMaxAxis const below
41 };
42
43 [StructLayout(LayoutKind.Sequential)]
44 internal unsafe struct iOSGameControllerState : IInputStateTypeInfo
45 {
46 public static FourCC kFormat = new FourCC('I', 'G', 'C', ' ');
47 public const int MaxButtons = (int)iOSButton.Select + 1;
48 public const int MaxAxis = (int)iOSAxis.RightStickY + 1;
49
50 [InputControl(name = "dpad")]
51 [InputControl(name = "dpad/up", bit = (uint)iOSButton.DpadUp)]
52 [InputControl(name = "dpad/right", bit = (uint)iOSButton.DpadRight)]
53 [InputControl(name = "dpad/down", bit = (uint)iOSButton.DpadDown)]
54 [InputControl(name = "dpad/left", bit = (uint)iOSButton.DpadLeft)]
55 [InputControl(name = "buttonSouth", bit = (uint)iOSButton.A)]
56 [InputControl(name = "buttonWest", bit = (uint)iOSButton.X)]
57 [InputControl(name = "buttonNorth", bit = (uint)iOSButton.Y)]
58 [InputControl(name = "buttonEast", bit = (uint)iOSButton.B)]
59 [InputControl(name = "leftStickPress", bit = (uint)iOSButton.LeftStick)]
60 [InputControl(name = "rightStickPress", bit = (uint)iOSButton.RightStick)]
61 [InputControl(name = "leftShoulder", bit = (uint)iOSButton.LeftShoulder)]
62 [InputControl(name = "rightShoulder", bit = (uint)iOSButton.RightShoulder)]
63 [InputControl(name = "start", bit = (uint)iOSButton.Start)]
64 [InputControl(name = "select", bit = (uint)iOSButton.Select)]
65 public uint buttons;
66
67 [InputControl(name = "leftTrigger", offset = sizeof(uint) + sizeof(float) * (uint)iOSButton.LeftTrigger)]
68 [InputControl(name = "rightTrigger", offset = sizeof(uint) + sizeof(float) * (uint)iOSButton.RightTrigger)]
69 public fixed float buttonValues[MaxButtons];
70
71 private const uint kAxisOffset = sizeof(uint) + sizeof(float) * MaxButtons;
72 [InputControl(name = "leftStick", offset = (uint)iOSAxis.LeftStickX * sizeof(float) + kAxisOffset)]
73 [InputControl(name = "rightStick", offset = (uint)iOSAxis.RightStickX * sizeof(float) + kAxisOffset)]
74 public fixed float axisValues[MaxAxis];
75
76 public FourCC format => kFormat;
77
78 public iOSGameControllerState WithButton(iOSButton button, bool value = true, float rawValue = 1.0f)
79 {
80 buttonValues[(int)button] = rawValue;
81
82 Debug.Assert((int)button < 32, $"Expected button < 32, so we fit into the 32 bit wide bitmask");
83 var bit = 1U << (int)button;
84 if (value)
85 buttons |= bit;
86 else
87 buttons &= ~bit;
88
89 return this;
90 }
91
92 public iOSGameControllerState WithAxis(iOSAxis axis, float value)
93 {
94 axisValues[(int)axis] = value;
95 return this;
96 }
97 }
98}
99
100namespace UnityEngine.InputSystem.iOS
101{
102 /// <summary>
103 /// A generic Gamepad connected to an iOS device.
104 /// </summary>
105 /// <remarks>
106 /// Any MFi-certified Gamepad which is not an <see cref="XboxOneGampadiOS"/> or <see cref="DualShock4GampadiOS"/> will
107 /// be represented as an iOSGameController.
108 /// </remarks>
109 [InputControlLayout(stateType = typeof(iOSGameControllerState), displayName = "iOS Gamepad")]
110 public class iOSGameController : Gamepad
111 {
112 }
113
114 /// <summary>
115 /// An Xbox One Bluetooth controller connected to an iOS device.
116 /// </summary>
117 [InputControlLayout(stateType = typeof(iOSGameControllerState), displayName = "iOS Xbox One Gamepad")]
118 public class XboxOneGampadiOS : XInput.XInputController
119 {
120 }
121
122 /// <summary>
123 /// A PlayStation DualShock 4 controller connected to an iOS device.
124 /// </summary>
125 [InputControlLayout(stateType = typeof(iOSGameControllerState), displayName = "iOS DualShock 4 Gamepad")]
126 public class DualShock4GampadiOS : DualShockGamepad
127 {
128 }
129
130 /// <summary>
131 /// A PlayStation DualSense controller connected to an iOS device.
132 /// </summary>
133 [InputControlLayout(stateType = typeof(iOSGameControllerState), displayName = "iOS DualSense Gamepad")]
134 public class DualSenseGampadiOS : DualShockGamepad
135 {
136 }
137}
138#endif // UNITY_EDITOR || UNITY_IOS || UNITY_TVOS || UNITY_VISIONOS