Bez popisu
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

InputControlLayoutAttribute.cs 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. using System;
  2. using UnityEngine.InputSystem.Utilities;
  3. using UnityEngine.Scripting;
  4. ////REVIEW: should this *not* be inherited? inheritance can lead to surprises
  5. namespace UnityEngine.InputSystem.Layouts
  6. {
  7. /// <summary>
  8. /// Attribute to control layout settings of a type used to generate an <see cref="InputControlLayout"/>.
  9. /// </summary>
  10. [AttributeUsage(AttributeTargets.Class, Inherited = false)]
  11. public sealed class InputControlLayoutAttribute : Attribute
  12. {
  13. /// <summary>
  14. /// Associates a state representation with an input device and drives
  15. /// the control layout generated for the device from its state rather
  16. /// than from the device class.
  17. /// </summary>
  18. /// <remarks>This is *only* useful if you have a state struct dictating a specific
  19. /// state layout and you want the device layout to automatically take offsets from
  20. /// the fields annotated with <see cref="InputControlAttribute"/>.
  21. ///
  22. /// <example>
  23. /// <code>
  24. /// public struct MyStateStruct : IInputStateTypeInfo
  25. /// {
  26. /// public FourCC format => new FourCC('M', 'Y', 'D', 'V');
  27. ///
  28. /// [InputControl(name = "button1", layout = "Button", bit = 0)]
  29. /// [InputControl(name = "button2", layout = "Button", bit = 0)]
  30. /// public int buttons;
  31. /// }
  32. ///
  33. /// [InputControlLayout(stateType = typeof(MyStateStruct)]
  34. /// public class MyDevice : InputDevice
  35. /// {
  36. /// }
  37. /// </code>
  38. /// </example>
  39. /// </remarks>
  40. /// <seealso cref="LowLevel.InputStateBlock"/>
  41. /// <seealso cref="LowLevel.MouseState"/>
  42. public Type stateType { get; set; }
  43. /// <summary>
  44. /// <see cref="FourCC"/> identifier for the memory format associated with the layout.
  45. /// </summary>
  46. /// <seealso cref="LowLevel.InputStateBlock.format"/>
  47. public string stateFormat { get; set; }
  48. ////TODO: rename this to just "usages"; "commonUsages" is such a weird name
  49. [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays", Justification = "According to MSDN, this message can be ignored for attribute parameters, as there are no better alternatives.")]
  50. public string[] commonUsages { get; set; }
  51. public string variants { get; set; }
  52. /// <summary>
  53. /// Allows marking a device as noisy regardless of control layout.
  54. /// </summary>
  55. /// <remarks>
  56. /// Controls can be individually marked as noisy using the <see cref="InputControlAttribute.noisy"/>
  57. /// attribute, but this property can be used to mark a device as noisy even when no control has been
  58. /// marked as such. This can be useful when a device state layout has only been partially implemented
  59. /// i.e. some data in the state memory has not been mapped to a control, and the unimplemented controls
  60. /// are noisy. Without doing this, the device will constantly be made current as the system has no way
  61. /// to know that the event data contains only noise.
  62. /// </remarks>
  63. public bool isNoisy { get; set; }
  64. internal bool? canRunInBackgroundInternal;
  65. public bool canRunInBackground
  66. {
  67. get => canRunInBackgroundInternal.Value;
  68. set => canRunInBackgroundInternal = value;
  69. }
  70. internal bool? updateBeforeRenderInternal;
  71. /// <summary>
  72. /// Whether the device should receive events in <see cref="LowLevel.InputUpdateType.BeforeRender"/> updates.
  73. /// </summary>
  74. /// <seealso cref="InputDevice.updateBeforeRender"/>
  75. public bool updateBeforeRender
  76. {
  77. get => updateBeforeRenderInternal.Value;
  78. set => updateBeforeRenderInternal = value;
  79. }
  80. /// <summary>
  81. /// If true, the layout describes a generic class of devices such as "gamepads" or "mice".
  82. /// </summary>
  83. /// <remarks>
  84. /// This property also determines how the layout is presented in the UI. All the device layouts
  85. /// that are marked as generic kinds of devices are displayed with their own entry at the root level of
  86. /// the control picker (<see cref="UnityEngine.InputSystem.Editor.InputControlPicker"/>), for example.
  87. /// </remarks>
  88. public bool isGenericTypeOfDevice { get; set; }
  89. /// <summary>
  90. /// Gives a name to display in the UI. By default, the name is the same as the class the attribute
  91. /// is applied to.
  92. /// </summary>
  93. public string displayName { get; set; }
  94. public string description { get; set; }
  95. /// <summary>
  96. /// If true, don't include the layout when presenting picking options in the UI.
  97. /// </summary>
  98. /// <remarks>
  99. /// This will keep device layouts out of the control picker and will keep control layouts out of
  100. /// action type dropdowns.
  101. /// </remarks>
  102. public bool hideInUI { get; set; }
  103. }
  104. }