InputControlLayoutAttribute.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using System;
  2. using UnityEngine.Scripting;
  3. ////REVIEW: should this *not* be inherited? inheritance can lead to surprises
  4. namespace UnityEngine.InputSystem.Layouts
  5. {
  6. /// <summary>
  7. /// Attribute to control layout settings of a type used to generate an <see cref="InputControlLayout"/>.
  8. /// </summary>
  9. [AttributeUsage(AttributeTargets.Class, Inherited = false)]
  10. public sealed class InputControlLayoutAttribute : Attribute
  11. {
  12. /// <summary>
  13. /// Associates a state representation with an input device and drives
  14. /// the control layout generated for the device from its state rather
  15. /// than from the device class.
  16. /// </summary>
  17. /// <remarks>This is *only* useful if you have a state struct dictating a specific
  18. /// state layout and you want the device layout to automatically take offsets from
  19. /// the fields annotated with <see cref="InputControlAttribute"/>.
  20. /// </remarks>
  21. public Type stateType { get; set; }
  22. public string stateFormat { get; set; }
  23. ////TODO: rename this to just "usages"; "commonUsages" is such a weird name
  24. [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.")]
  25. public string[] commonUsages { get; set; }
  26. public string variants { get; set; }
  27. internal bool? updateBeforeRenderInternal;
  28. /// <summary>
  29. /// Whether the device should receive events in <see cref="LowLevel.InputUpdateType.BeforeRender"/> updates.
  30. /// </summary>
  31. /// <seealso cref="InputDevice.updateBeforeRender"/>
  32. public bool updateBeforeRender
  33. {
  34. get => updateBeforeRenderInternal.Value;
  35. set => updateBeforeRenderInternal = value;
  36. }
  37. /// <summary>
  38. /// If true, the layout describes a generic class of devices such as "gamepads" or "mice".
  39. /// </summary>
  40. /// <remarks>
  41. /// This property also determines how the layout is presented in the UI. All the device layouts
  42. /// that are marked as generic kinds of devices are displayed with their own entry at the root level of
  43. /// the control picker (<see cref="UnityEngine.InputSystem.Editor.InputControlPicker"/>), for example.
  44. /// </remarks>
  45. public bool isGenericTypeOfDevice { get; set; }
  46. /// <summary>
  47. /// Gives a name to display in the UI. By default, the name is the same as the class the attribute
  48. /// is applied to.
  49. /// </summary>
  50. public string displayName { get; set; }
  51. public string description { get; set; }
  52. /// <summary>
  53. /// If true, don't include the layout when presenting picking options in the UI.
  54. /// </summary>
  55. /// <remarks>
  56. /// This will keep device layouts out of the control picker and will keep control layouts out of
  57. /// action type dropdowns.
  58. /// </remarks>
  59. public bool hideInUI { get; set; }
  60. }
  61. }