123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189 |
- using UnityEngine.InputSystem.Controls;
- using UnityEngine.InputSystem.Layouts;
- using UnityEngine.InputSystem.LowLevel;
- using UnityEngine.InputSystem.Utilities;
- namespace UnityEngine.InputSystem.LowLevel
- {
- internal struct JoystickState : IInputStateTypeInfo
- {
- public static FourCC kFormat => new FourCC('J', 'O', 'Y');
- [InputControl(name = "trigger", displayName = "Trigger", layout = "Button", usages = new[] { "PrimaryTrigger", "PrimaryAction", "Submit" }, bit = (int)Button.Trigger)]
- public int buttons;
- [InputControl(displayName = "Stick", layout = "Stick", usage = "Primary2DMotion", processors = "stickDeadzone")]
- public Vector2 stick;
- public enum Button
- {
-
- HatSwitchUp,
- HatSwitchDown,
- HatSwitchLeft,
- HatSwitchRight,
- Trigger
- }
- public FourCC format => kFormat;
- }
- }
- namespace UnityEngine.InputSystem
- {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- [InputControlLayout(stateType = typeof(JoystickState), isGenericTypeOfDevice = true)]
- [Scripting.Preserve]
- public class Joystick : InputDevice
- {
-
-
-
-
-
-
-
-
- public ButtonControl trigger { get; private set; }
-
-
-
-
-
-
-
-
- public StickControl stick { get; private set; }
-
-
-
-
-
-
-
-
-
-
- public AxisControl twist { get; private set; }
-
-
-
-
-
-
-
-
-
-
-
- public Vector2Control hatswitch { get; private set; }
-
-
-
-
-
-
-
-
-
- public static Joystick current { get; private set; }
-
-
-
-
-
-
-
-
-
-
-
-
- public new static ReadOnlyArray<Joystick> all => new ReadOnlyArray<Joystick>(s_Joysticks, 0, s_JoystickCount);
-
-
-
-
- protected override void FinishSetup()
- {
-
- trigger = GetChildControl<ButtonControl>("{PrimaryTrigger}");
- stick = GetChildControl<StickControl>("{Primary2DMotion}");
-
- twist = TryGetChildControl<AxisControl>("{Twist}");
- hatswitch = TryGetChildControl<Vector2Control>("{Hatswitch}");
- base.FinishSetup();
- }
-
-
-
-
-
-
-
-
- public override void MakeCurrent()
- {
- base.MakeCurrent();
- current = this;
- }
-
-
-
- protected override void OnAdded()
- {
- ArrayHelpers.AppendWithCapacity(ref s_Joysticks, ref s_JoystickCount, this);
- }
-
-
-
- protected override void OnRemoved()
- {
- base.OnRemoved();
- if (current == this)
- current = null;
-
- var index = ArrayHelpers.IndexOfReference(s_Joysticks, this, s_JoystickCount);
- if (index != -1)
- ArrayHelpers.EraseAtWithCapacity(s_Joysticks, ref s_JoystickCount, index);
- else
- {
- Debug.Assert(false,
- $"Joystick {this} seems to not have been added but is being removed (joystick list: {string.Join(", ", all)})");
- }
- }
- private static int s_JoystickCount;
- private static Joystick[] s_Joysticks;
- }
- }
|