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