LinuxSupport.cs 3.1 KB

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