Нет описания
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

InputSettings.cs 50KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine.InputSystem.Controls;
  4. using UnityEngine.InputSystem.Layouts;
  5. using UnityEngine.InputSystem.LowLevel;
  6. using UnityEngine.InputSystem.Processors;
  7. using UnityEngine.InputSystem.Utilities;
  8. ////TODO: make sure that alterations made to InputSystem.settings in play mode do not leak out into edit mode or the asset
  9. ////TODO: handle case of supportFixedUpdates and supportDynamicUpdates both being set to false; should it be an enum?
  10. ////TODO: figure out how this gets into a build
  11. ////TODO: allow setting up single- and multi-user configs for the project
  12. ////TODO: allow enabling/disabling plugins
  13. ////REVIEW: should the project settings include a list of action assets to use? (or to force into a build)
  14. ////REVIEW: add extra option to enable late-updates?
  15. ////REVIEW: put default sensor sampling frequency here?
  16. ////REVIEW: put default gamepad polling frequency here?
  17. ////REVIEW: Have an InputActionAsset field in here that allows having a single default set of actions that are enabled with no further setup?
  18. namespace UnityEngine.InputSystem
  19. {
  20. /// <summary>
  21. /// Project-wide input settings.
  22. /// </summary>
  23. /// <remarks>
  24. /// Several aspects of the input system can be customized to tailor how the system functions to the
  25. /// specific needs of a project. These settings are collected in this class. There is one global
  26. /// settings object active at any one time. It can be accessed and set through <see cref="InputSystem.settings"/>.
  27. ///
  28. /// Changing a setting on the object takes effect immediately. It also triggers the
  29. /// <see cref="InputSystem.onSettingsChange"/> callback.
  30. /// </remarks>
  31. /// <seealso cref="InputSystem.settings"/>
  32. /// <seealso cref="InputSystem.onSettingsChange"/>
  33. public partial class InputSettings : ScriptableObject
  34. {
  35. /// <summary>
  36. /// Allows you to control how the input system handles updates. In other words, how and when pending input events are processed.
  37. /// </summary>
  38. /// <value>When to run input updates.</value>
  39. /// <remarks>
  40. /// By default, input updates will automatically be triggered as part of the player loop.
  41. /// If <c>updateMode</c> is set to <see cref="UpdateMode.ProcessEventsInDynamicUpdate"/>
  42. /// (the default), then right at the beginning of a dynamic update (i.e. before all
  43. /// <c>MonoBehaviour.Update</c> methods are called), input is processed. And if <c>updateMode</c>
  44. /// is set to <see cref="UpdateMode.ProcessEventsInFixedUpdate"/>, then right at the beginning
  45. /// of each fixed update (i.e. before all <c>MonoBehaviour.FixedUpdate</c> methods are
  46. /// called), input is processed.
  47. ///
  48. /// Additionally, if there are devices that need updates right before rendering (see <see
  49. /// cref="InputDevice.updateBeforeRender"/>), an extra update will be run right before
  50. /// rendering. This special update will only consume input on devices that have
  51. /// <see cref="InputDevice.updateBeforeRender"/> set to <c>true</c>.
  52. ///
  53. /// You can run updates manually using <see cref="InputSystem.Update"/>. Doing so
  54. /// outside of tests is only recommended, however, if <c>updateMode</c> is set to
  55. /// <see cref="UpdateMode.ProcessEventsManually"/> (in which case it is actually required
  56. /// for input to be processed at all).
  57. ///
  58. /// Note that in the editor, input updates will also run before each editor update
  59. /// (i.e. as part of <c>EditorApplication.update</c>). Player and editor input state
  60. /// are kept separate, though, so any input consumed in editor updates will not be visible
  61. /// in player updates and vice versa.
  62. /// </remarks>
  63. /// <seealso cref="InputSystem.Update"/>
  64. public UpdateMode updateMode
  65. {
  66. get => m_UpdateMode;
  67. set
  68. {
  69. if (m_UpdateMode == value)
  70. return;
  71. m_UpdateMode = value;
  72. OnChange();
  73. }
  74. }
  75. /// <summary>
  76. /// If true, sensors that deliver rotation values on handheld devices will automatically adjust
  77. /// rotations when the screen orientation changes.
  78. /// </summary>
  79. /// <remarks>
  80. /// This is enabled by default.
  81. ///
  82. /// If enabled, rotation values will be rotated around Z. In <see cref="ScreenOrientation.Portrait"/>, values
  83. /// remain unchanged. In <see cref="ScreenOrientation.PortraitUpsideDown"/>, they will be rotated by 180 degrees.
  84. /// In <see cref="ScreenOrientation.LandscapeLeft"/> by 90 degrees, and in <see cref="ScreenOrientation.LandscapeRight"/>
  85. /// by 270 degrees.
  86. ///
  87. /// Sensors affected by this setting are <see cref="Accelerometer"/>, <see cref="Compass"/>, and <see cref="Gyroscope"/>.
  88. /// </remarks>
  89. /// <seealso cref="CompensateDirectionProcessor"/>
  90. public bool compensateForScreenOrientation
  91. {
  92. get => m_CompensateForScreenOrientation;
  93. set
  94. {
  95. if (m_CompensateForScreenOrientation == value)
  96. return;
  97. m_CompensateForScreenOrientation = value;
  98. OnChange();
  99. }
  100. }
  101. /// <summary>
  102. /// Currently: Option is deprecated and has no influence on the system. Filtering on noise is always enabled.
  103. /// Previously: Whether to not make a device <c>.current</c> (see <see cref="InputDevice.MakeCurrent"/>)
  104. /// when there is only noise in the input.
  105. /// </summary>
  106. /// <remarks>
  107. /// We add extra processing every time input is
  108. /// received on a device that is considered noisy. These devices are those that
  109. /// have at least one control that is marked as <see cref="InputControl.noisy"/>.
  110. /// A good example is the PS4 controller which has a gyroscope sensor built into
  111. /// the device. Whereas sticks and buttons on the device require user interaction
  112. /// to produce non-default values, the gyro will produce varying values even if
  113. /// the device just sits there without user interaction.
  114. ///
  115. /// Without noise filtering, a PS4 controller will thus continually make itself
  116. /// current as it will send a continuous stream of input even when not actively
  117. /// used by the player. By toggling this property on, each input event will be
  118. /// run through a noise mask. Only if state has changed outside of memory areas
  119. /// marked as noise will the input be considered valid user interaction and the
  120. /// device will be made current. Note that in this process, the system does
  121. /// <em>not</em> determine whether non-noisy controls on the device have actually
  122. /// changed value. All the system establishes is whether such controls have changed
  123. /// <em>state</em>. However, processing such as for deadzones may cause values
  124. /// to not effectively change even though the non-noisy state of the device has
  125. /// changed.
  126. /// </remarks>
  127. /// <seealso cref="InputDevice.MakeCurrent"/>
  128. /// <seealso cref="InputControl.noisy"/>
  129. [Obsolete("filterNoiseOnCurrent is deprecated, filtering of noise is always enabled now.", false)]
  130. public bool filterNoiseOnCurrent
  131. {
  132. get => false;
  133. set
  134. {
  135. /* no op */
  136. }
  137. }
  138. /// <summary>
  139. /// Default value used when nothing is set explicitly on <see cref="StickDeadzoneProcessor.min"/>
  140. /// or <see cref="AxisDeadzoneProcessor.min"/>.
  141. /// </summary>
  142. /// <value>Default lower limit for deadzones.</value>
  143. /// <remarks>
  144. /// "Deadzones" refer to limits established for the range of values accepted as input
  145. /// on a control. If the value for the control falls outside the range, i.e. below the
  146. /// given minimum or above the given maximum, the value is clamped to the respective
  147. /// limit.
  148. ///
  149. /// This property configures the default lower bound of the value range.
  150. ///
  151. /// Note that deadzones will by default re-normalize values after clamping. This means that
  152. /// inputs at the lower and upper end are dropped and that the range in-between is re-normalized
  153. /// to [0..1].
  154. ///
  155. /// Note that deadzones preserve the sign of inputs. This means that both the upper and
  156. /// the lower deadzone bound extend to both the positive and the negative range. For example,
  157. /// a deadzone min of 0.1 will clamp values between -0.1 and +0.1.
  158. ///
  159. /// The most common example of where deadzones are used are the sticks on gamepads, i.e.
  160. /// <see cref="Gamepad.leftStick"/> and <see cref="Gamepad.rightStick"/>. Sticks will
  161. /// usually be wobbly to some extent (just how wobbly varies greatly between different
  162. /// types of controllers -- which means that often deadzones need to be configured on a
  163. /// per-device type basis). Using deadzones, stick motion at the extreme ends of the spectrum
  164. /// can be filtered out and noise in these areas can effectively be eliminated this way.
  165. ///
  166. /// The default value for this property is 0.125.
  167. /// </remarks>
  168. /// <seealso cref="StickDeadzoneProcessor"/>
  169. /// <seealso cref="AxisDeadzoneProcessor"/>
  170. public float defaultDeadzoneMin
  171. {
  172. get => m_DefaultDeadzoneMin;
  173. set
  174. {
  175. // ReSharper disable once CompareOfFloatsByEqualityOperator
  176. if (m_DefaultDeadzoneMin == value)
  177. return;
  178. m_DefaultDeadzoneMin = value;
  179. OnChange();
  180. }
  181. }
  182. /// <summary>
  183. /// Default value used when nothing is set explicitly on <see cref="StickDeadzoneProcessor.max"/>
  184. /// or <see cref="AxisDeadzoneProcessor.max"/>.
  185. /// </summary>
  186. /// <value>Default upper limit for deadzones.</value>
  187. /// <remarks>
  188. /// "Deadzones" refer to limits established for the range of values accepted as input
  189. /// on a control. If the value for the control falls outside the range, i.e. below the
  190. /// given minimum or above the given maximum, the value is clamped to the respective
  191. /// limit.
  192. ///
  193. /// This property configures the default upper bound of the value range.
  194. ///
  195. /// Note that deadzones will by default re-normalize values after clamping. This means that
  196. /// inputs at the lower and upper end are dropped and that the range in-between is re-normalized
  197. /// to [0..1].
  198. ///
  199. /// Note that deadzones preserve the sign of inputs. This means that both the upper and
  200. /// the lower deadzone bound extend to both the positive and the negative range. For example,
  201. /// a deadzone max of 0.95 will clamp values of &gt;0.95 and &lt;-0.95.
  202. ///
  203. /// The most common example of where deadzones are used are the sticks on gamepads, i.e.
  204. /// <see cref="Gamepad.leftStick"/> and <see cref="Gamepad.rightStick"/>. Sticks will
  205. /// usually be wobbly to some extent (just how wobbly varies greatly between different
  206. /// types of controllers -- which means that often deadzones need to be configured on a
  207. /// per-device type basis). Using deadzones, stick motion at the extreme ends of the spectrum
  208. /// can be filtered out and noise in these areas can effectively be eliminated this way.
  209. ///
  210. /// The default value for this property is 0.925.
  211. /// </remarks>
  212. /// <seealso cref="StickDeadzoneProcessor"/>
  213. /// <seealso cref="AxisDeadzoneProcessor"/>
  214. public float defaultDeadzoneMax
  215. {
  216. get => m_DefaultDeadzoneMax;
  217. set
  218. {
  219. // ReSharper disable once CompareOfFloatsByEqualityOperator
  220. if (m_DefaultDeadzoneMax == value)
  221. return;
  222. m_DefaultDeadzoneMax = value;
  223. OnChange();
  224. }
  225. }
  226. /// <summary>
  227. /// The default value threshold for when a button is considered pressed. Used if
  228. /// no explicit thresholds are set on parameters such as <see cref="Controls.ButtonControl.pressPoint"/>
  229. /// or <see cref="Interactions.PressInteraction.pressPoint"/>.
  230. /// </summary>
  231. /// <value>Default button press threshold.</value>
  232. /// <remarks>
  233. /// In the input system, each button constitutes a full floating-point value. Pure
  234. /// toggle buttons, such as <see cref="Gamepad.buttonSouth"/> for example, will simply
  235. /// alternate between 0 (not pressed) and 1 (pressed). However, buttons may also have
  236. /// ranges, such as <see cref="Gamepad.leftTrigger"/> for example. When used in a context
  237. /// where a clear distinction between pressed and not pressed is required, we need a value
  238. /// beyond which we consider the button pressed.
  239. ///
  240. /// By setting this property, the default value for this can be configured. If a button
  241. /// has a value equal to or greater than the button press point, it is considered pressed.
  242. ///
  243. /// The default value is 0.5.
  244. ///
  245. /// Any value will implicitly be clamped to <c>0.0001f</c> as allowing a value of 0 would
  246. /// cause all buttons in their default state to already be pressed.
  247. ///
  248. /// Lowering the button press point will make triggers feel more like hair-triggers (akin
  249. /// to using the hair-trigger feature on Xbox Elite controllers). However, it may make using
  250. /// the directional buttons (i.e. <see cref="Controls.StickControl.up"/> etc) be fickle as
  251. /// solely moving in only one direction with sticks isn't easy. To counteract that, the button
  252. /// press points on the stick buttons can be raised.
  253. ///
  254. /// Another solution is to simply lower the press points on the triggers specifically.
  255. ///
  256. /// <example>
  257. /// <code>
  258. /// InputSystem.RegisterLayoutOverride(@"
  259. /// {
  260. /// ""name"" : ""HairTriggers"",
  261. /// ""extend"" : ""Gamepad"",
  262. /// ""controls"" [
  263. /// { ""name"" : ""leftTrigger"", ""parameters"" : ""pressPoint=0.1"" },
  264. /// { ""name"" : ""rightTrigger"", ""parameters"" : ""pressPoint=0.1"" }
  265. /// ]
  266. /// }
  267. /// ");
  268. /// </code>
  269. /// </example>
  270. /// </remarks>
  271. /// <seealso cref="buttonReleaseThreshold"/>
  272. /// <seealso cref="Controls.ButtonControl.pressPoint"/>
  273. /// <seealso cref="Controls.ButtonControl.isPressed"/>
  274. /// <seealso cref="Interactions.PressInteraction.pressPoint"/>
  275. /// <seealso cref="Interactions.TapInteraction.pressPoint"/>
  276. /// <seealso cref="Interactions.SlowTapInteraction.pressPoint"/>
  277. /// <seealso cref="InputBindingCompositeContext.ReadValueAsButton"/>
  278. public float defaultButtonPressPoint
  279. {
  280. get => m_DefaultButtonPressPoint;
  281. set
  282. {
  283. // ReSharper disable once CompareOfFloatsByEqualityOperator
  284. if (m_DefaultButtonPressPoint == value)
  285. return;
  286. m_DefaultButtonPressPoint = Mathf.Clamp(value, ButtonControl.kMinButtonPressPoint, float.MaxValue);
  287. OnChange();
  288. }
  289. }
  290. /// <summary>
  291. /// The percentage of <see cref="defaultButtonPressPoint"/> at which a button that was pressed
  292. /// is considered released again.
  293. /// </summary>
  294. /// <remarks>
  295. /// This setting helps avoid flickering around the button press point by introducing something akin to a
  296. /// "dead zone" below <see cref="defaultButtonPressPoint"/>. Once a button has been pressed to a magnitude
  297. /// of at least <see cref="defaultButtonPressPoint"/>, it is considered pressed and keeps being considered pressed
  298. /// until its magnitude falls back to a value of or below <see cref="buttonReleaseThreshold"/> percent of
  299. /// <see cref="defaultButtonPressPoint"/>.
  300. ///
  301. /// This is a percentage rather than a fixed value so it allows computing release
  302. /// points even when the press point has been customized. If, for example, a <see cref="Interactions.PressInteraction"/>
  303. /// sets a custom <see cref="Interactions.PressInteraction.pressPoint"/>, the respective release point
  304. /// can still be computed from the percentage set here.
  305. /// </remarks>
  306. public float buttonReleaseThreshold
  307. {
  308. get => m_ButtonReleaseThreshold;
  309. set
  310. {
  311. // ReSharper disable once CompareOfFloatsByEqualityOperator
  312. if (m_ButtonReleaseThreshold == value)
  313. return;
  314. m_ButtonReleaseThreshold = value;
  315. OnChange();
  316. }
  317. }
  318. /// <summary>
  319. /// Default time (in seconds) within which a press and release has to occur for it
  320. /// to be registered as a "tap".
  321. /// </summary>
  322. /// <value>Default upper limit on press durations for them to register as taps.</value>
  323. /// <remarks>
  324. /// A tap is considered as a quick press-and-release on a button-like input control.
  325. /// This property determines just how quick the press-and-release has to be, i.e. what
  326. /// the maximum time is that can elapse between the button being pressed and released
  327. /// again. If the delay between press and release is greater than this time, the
  328. /// input does not qualify as a tap.
  329. ///
  330. /// The default tap time is 0.2 seconds.
  331. /// </remarks>
  332. /// <seealso cref="Interactions.TapInteraction"/>
  333. public float defaultTapTime
  334. {
  335. get => m_DefaultTapTime;
  336. set
  337. {
  338. // ReSharper disable once CompareOfFloatsByEqualityOperator
  339. if (m_DefaultTapTime == value)
  340. return;
  341. m_DefaultTapTime = value;
  342. OnChange();
  343. }
  344. }
  345. /// <summary>
  346. /// Allows you to specify the default minimum duration required of a press-and-release interaction to evaluate to a slow-tap-interaction.
  347. /// </summary>
  348. /// <value>The default minimum duration that the button-like input control must remain in pressed state for the interaction to evaluate to a slow-tap-interaction.</value>
  349. /// <remarks>
  350. /// A slow-tap-interaction is considered as a press-and-release sequence on a button-like input control.
  351. /// This property determines the lower bound of the duration that must elapse between the button being pressed and released again.
  352. /// If the delay between press and release is less than this duration, the input does not qualify as a slow-tap-interaction.
  353. ///
  354. /// The default slow-tap time is 0.5 seconds.
  355. /// </remarks>
  356. /// <seealso cref="Interactions.SlowTapInteraction"/>
  357. public float defaultSlowTapTime
  358. {
  359. get => m_DefaultSlowTapTime;
  360. set
  361. {
  362. // ReSharper disable once CompareOfFloatsByEqualityOperator
  363. if (m_DefaultSlowTapTime == value)
  364. return;
  365. m_DefaultSlowTapTime = value;
  366. OnChange();
  367. }
  368. }
  369. /// <summary>
  370. /// Allows you to specify the default minimum duration required of a press-and-release interaction to evaluate to a hold-interaction.
  371. /// </summary>
  372. /// <value>The default minimum duration that the button-like input control must remain in pressed state for the interaction to evaluate to a hold-interaction.</value>
  373. /// <remarks>
  374. /// A hold-interaction is considered as a press-and-release sequence on a button-like input control.
  375. /// This property determines the lower bound of the duration that must elapse between the button being pressed and released again.
  376. /// If the delay between press and release is less than this duration, the input does not qualify as a hold-interaction.
  377. ///
  378. /// The default hold time is 0.4 seconds.
  379. /// </remarks>
  380. /// <seealso cref="Interactions.HoldInteraction"/>
  381. public float defaultHoldTime
  382. {
  383. get => m_DefaultHoldTime;
  384. set
  385. {
  386. // ReSharper disable once CompareOfFloatsByEqualityOperator
  387. if (m_DefaultHoldTime == value)
  388. return;
  389. m_DefaultHoldTime = value;
  390. OnChange();
  391. }
  392. }
  393. /// <summary>
  394. /// Allows you to specify the default maximum radius that a touch contact may be moved from its origin to evaluate to a tap-interaction.
  395. /// </summary>
  396. /// <value>The default maximum radius (in pixels) that a touch contact may be moved from its origin to evaluate to a tap-interaction.</value>
  397. /// <remarks>
  398. /// A tap-interaction or slow-tap-interaction is considered as a press-and-release sequence.
  399. /// If the associated touch contact is moved a distance equal or greater to the value of this setting,
  400. /// the input sequence do not qualify as a tap-interaction.
  401. ///
  402. /// The default tap-radius is 5 pixels.
  403. /// </remarks>
  404. /// <seealso cref="Interactions.TapInteraction"/>
  405. /// <seealso cref="Interactions.SlowTapInteraction"/>
  406. /// <seealso cref="Interactions.MultiTapInteraction"/>
  407. public float tapRadius
  408. {
  409. get => m_TapRadius;
  410. set
  411. {
  412. // ReSharper disable once CompareOfFloatsByEqualityOperator
  413. if (m_TapRadius == value)
  414. return;
  415. m_TapRadius = value;
  416. OnChange();
  417. }
  418. }
  419. /// <summary>
  420. /// Allows you to specify the maximum duration that may pass between taps in order to evaluate to a multi-tap-interaction.
  421. /// </summary>
  422. /// <value>The default maximum duration (in seconds) that may pass between taps in order to evaluate to a multi-tap-interaction.</value>
  423. /// <remarks>
  424. /// A multi-tap interaction is considered as multiple press-and-release sequences.
  425. /// This property defines the maximum duration that may pass between these press-and-release sequences.
  426. /// If consecutive taps (press-and-release sequences) occur with a inter-sequence duration exceeding
  427. /// this property, the interaction do not qualify as a multi-tap-interaction.
  428. ///
  429. /// The default multi-tap delay time is 0.75 seconds.
  430. /// </remarks>
  431. /// <seealso cref="defaultTapTime"/>
  432. public float multiTapDelayTime
  433. {
  434. get => m_MultiTapDelayTime;
  435. set
  436. {
  437. // ReSharper disable once CompareOfFloatsByEqualityOperator
  438. if (m_MultiTapDelayTime == value)
  439. return;
  440. m_MultiTapDelayTime = value;
  441. OnChange();
  442. }
  443. }
  444. /// <summary>
  445. /// When <c>Application.runInBackground</c> is true, this property determines what happens when application focus changes
  446. /// (see <a href="https://docs.unity3d.com/ScriptReference/Application-isFocused.html">Application.isFocused</a>) changes and how we handle
  447. /// input while running the background.
  448. /// </summary>
  449. /// <value>What to do with input while not having focus. Set to <see cref="BackgroundBehavior.ResetAndDisableNonBackgroundDevices"/> by default.</value>
  450. /// <remarks>
  451. /// If <c>Application.runInBackground</c> is false, the value of this property is ignored. In that case, nothing happens when
  452. /// focus is lost. However, when focus is regained, <see cref="InputSystem.TrySyncDevice"/> is called on all devices.
  453. ///
  454. /// Note that in the editor as well as in development standalone players, <c>Application.runInBackground</c> will effectively always be
  455. /// turned on. The editor keeps the player loop running regardless of Game View focus for as long as the editor is active and in play mode
  456. /// and development players will implicitly turn on the setting during the build process.
  457. /// </remarks>
  458. /// <seealso cref="InputSystem.ResetDevice"/>
  459. /// <seealso cref="InputSystem.EnableDevice"/>
  460. /// <seealso cref="InputDevice.canRunInBackground"/>
  461. /// <seealso cref="editorInputBehaviorInPlayMode"/>
  462. public BackgroundBehavior backgroundBehavior
  463. {
  464. get => m_BackgroundBehavior;
  465. set
  466. {
  467. if (m_BackgroundBehavior == value)
  468. return;
  469. m_BackgroundBehavior = value;
  470. OnChange();
  471. }
  472. }
  473. /// <summary>
  474. /// Determines how player focus is handled in the editor with respect to input.
  475. /// </summary>
  476. /// <remarks>
  477. /// This setting only has an effect while in play mode (see <a href="https://docs.unity3d.com/ScriptReference/Application-isPlaying.html">Application.isPlaying</a>).
  478. /// While not in play mode, all input is invariably routed to the editor.
  479. ///
  480. /// The editor generally treats Game View focus as equivalent to application focus (see <a href="https://docs.unity3d.com/ScriptReference/Application-isFocused.html">Application.isFocused</a>).
  481. /// In other words, as long as any Game View has focus, the player is considered to have input focus. As soon as focus is transferred to a non-Game View
  482. /// <c>EditorWindow</c> or the editor as a whole loses focus, the player is considered to have lost input focus.
  483. ///
  484. /// However, unlike in built players, the editor will keep running the player loop while in play mode regardless of whether a Game View is focused
  485. /// or not. This essentially equates to <a href="https://docs.unity3d.com/ScriptReference/Application-runInBackground.html">Application.runInBackground</a> always
  486. /// being true in the editor.
  487. ///
  488. /// To accommodate this behavior, this setting determines where input is routed while the player loop is running with no Game View being focused. As such,
  489. /// it also dictates which input reaches the editor (if any) while the game is playing.
  490. /// </remarks>
  491. /// <seealso cref="backgroundBehavior"/>
  492. public EditorInputBehaviorInPlayMode editorInputBehaviorInPlayMode
  493. {
  494. get => m_EditorInputBehaviorInPlayMode;
  495. set
  496. {
  497. if (m_EditorInputBehaviorInPlayMode == value)
  498. return;
  499. m_EditorInputBehaviorInPlayMode = value;
  500. OnChange();
  501. }
  502. }
  503. /// <summary>
  504. /// Determines how the Inspector window displays <see cref="InputActionProperty"/> fields.
  505. /// </summary>
  506. /// <seealso cref="InputActionPropertyDrawerMode"/>
  507. public InputActionPropertyDrawerMode inputActionPropertyDrawerMode
  508. {
  509. get => m_InputActionPropertyDrawerMode;
  510. set
  511. {
  512. if (m_InputActionPropertyDrawerMode == value)
  513. return;
  514. m_InputActionPropertyDrawerMode = value;
  515. OnChange();
  516. }
  517. }
  518. /// <summary>
  519. /// Upper limit on the amount of bytes worth of <see cref="InputEvent"/>s processed in a single
  520. /// <see cref="InputSystem.Update"/>.
  521. /// </summary>
  522. /// <remarks>
  523. /// This setting establishes a bound on the amount of input event data processed in a single
  524. /// update and thus limits throughput allowed for input. This prevents long stalls from
  525. /// leading to long delays in input processing.
  526. ///
  527. /// When the limit is exceeded, all events remaining in the buffer are thrown away (the
  528. /// <see cref="InputEventBuffer"/> is reset) and an error is logged. After that, the current
  529. /// update will abort and early out.
  530. ///
  531. /// Setting this property to 0 or a negative value will disable the limit.
  532. ///
  533. /// The default value is 5MB.
  534. /// </remarks>
  535. /// <seealso cref="InputSystem.Update"/>
  536. /// <see cref="InputEvent.sizeInBytes"/>
  537. public int maxEventBytesPerUpdate
  538. {
  539. get => m_MaxEventBytesPerUpdate;
  540. set
  541. {
  542. if (m_MaxEventBytesPerUpdate == value)
  543. return;
  544. m_MaxEventBytesPerUpdate = value;
  545. OnChange();
  546. }
  547. }
  548. /// <summary>
  549. /// Upper limit on the number of <see cref="InputEvent"/>s that can be queued within one
  550. /// <see cref="InputSystem.Update"/>.
  551. /// <remarks>
  552. /// This settings establishes an upper limit on the number of events that can be queued
  553. /// using <see cref="InputSystem.QueueEvent"/> during a single update. This prevents infinite
  554. /// loops where an action callback queues an event that causes the action callback to
  555. /// be called again which queues an event...
  556. ///
  557. /// Note that this limit only applies while the input system is updating. There is no limit
  558. /// on the number of events that can be queued outside of this time, but those will be queued
  559. /// into the next frame where the <see cref="maxEventBytesPerUpdate"/> setting will apply.
  560. ///
  561. /// The default value is 1000.
  562. /// </remarks>
  563. /// </summary>
  564. public int maxQueuedEventsPerUpdate
  565. {
  566. get => m_MaxQueuedEventsPerUpdate;
  567. set
  568. {
  569. if (m_MaxQueuedEventsPerUpdate == value)
  570. return;
  571. m_MaxQueuedEventsPerUpdate = value;
  572. OnChange();
  573. }
  574. }
  575. /// <summary>
  576. /// List of device layouts used by the project.
  577. /// </summary>
  578. /// <remarks>
  579. /// This would usually be one of the high-level abstract device layouts. For example, for
  580. /// a game that supports touch, gamepad, and keyboard&amp;mouse, the list would be
  581. /// <c>{ "Touchscreen", "Gamepad", "Mouse", "Keyboard" }</c>. However, nothing prevents the
  582. /// the user from adding something a lot more specific. A game that can only be played
  583. /// with a DualShock controller could make this list just be <c>{ "DualShockGamepad" }</c>,
  584. /// for example.
  585. ///
  586. /// In the editor, we use the information to filter what we display to the user by automatically
  587. /// filtering out irrelevant controls in the control picker and such.
  588. ///
  589. /// The information is also used when a new device is discovered. If the device is not listed
  590. /// as supported by the project, it is ignored.
  591. ///
  592. /// The list is empty by default. An empty list indicates that no restrictions are placed on what
  593. /// devices are supported. In this editor, this means that all possible devices and controls are
  594. /// shown.
  595. /// </remarks>
  596. /// <seealso cref="InputControlLayout"/>
  597. public ReadOnlyArray<string> supportedDevices
  598. {
  599. get => new ReadOnlyArray<string>(m_SupportedDevices);
  600. set
  601. {
  602. // Detect if there was a change.
  603. if (supportedDevices.Count == value.Count)
  604. {
  605. var hasChanged = false;
  606. for (var i = 0; i < supportedDevices.Count; ++i)
  607. if (m_SupportedDevices[i] != value[i])
  608. {
  609. hasChanged = true;
  610. break;
  611. }
  612. if (!hasChanged)
  613. return;
  614. }
  615. m_SupportedDevices = value.ToArray();
  616. OnChange();
  617. }
  618. }
  619. /// <summary>
  620. /// Disables merging of redundant input events (at the moment, only mouse events).
  621. /// Disable it if you want to get all events.
  622. /// </summary>
  623. /// <remarks>
  624. /// When using a high frequency mouse, the number of mouse move events in each frame can be
  625. /// very large, which can have a negative effect on performance. To help with this,
  626. /// merging events can be used which coalesces consecutive mouse move events into a single
  627. /// input action update.
  628. ///
  629. /// For example, if there are one hundred mouse events, but they are all position updates
  630. /// with no clicks, and there is an input action callback handler for the mouse position, that
  631. /// callback handler will only be called one time in the current frame. Delta and scroll
  632. /// values for the mouse will still be accumulated across all mouse events.
  633. /// </remarks>
  634. public bool disableRedundantEventsMerging
  635. {
  636. get => m_DisableRedundantEventsMerging;
  637. set
  638. {
  639. if (m_DisableRedundantEventsMerging == value)
  640. return;
  641. m_DisableRedundantEventsMerging = value;
  642. OnChange();
  643. }
  644. }
  645. /// <summary>
  646. /// Improves shortcut key support by making composite controls consume control input
  647. /// </summary>
  648. /// <remarks>
  649. /// Actions are exclusively triggered and will consume/block other actions sharing the same input.
  650. /// E.g. when pressing the 'Shift+B' keys, the associated action would trigger but any action bound to just the 'B' key would be prevented from triggering at the same time.
  651. /// Please note that enabling this will cause actions with composite bindings to consume input and block any other actions which are enabled and sharing the same controls.
  652. /// Input consumption is performed in priority order, with the action containing the greatest number of bindings checked first.
  653. /// Therefore actions requiring fewer keypresses will not be triggered if an action using more keypresses is triggered and has overlapping controls.
  654. /// This works for shortcut keys, however in other cases this might not give the desired result, especially where there are actions with the exact same number of composite controls, in which case it is non-deterministic which action will be triggered.
  655. /// These conflicts may occur even between actions which belong to different Action Maps e.g. if using an UIInputModule with the Arrow Keys bound to the Navigate Action in the UI Action Map, this would interfere with other Action Maps using those keys.
  656. /// However conflicts would not occur between actions which belong to different Action Assets.
  657. /// </remarks>
  658. public bool shortcutKeysConsumeInput
  659. {
  660. get => m_ShortcutKeysConsumeInputs;
  661. set
  662. {
  663. if (m_ShortcutKeysConsumeInputs == value)
  664. return;
  665. m_ShortcutKeysConsumeInputs = value;
  666. OnChange();
  667. }
  668. }
  669. /// <summary>
  670. /// Enable or disable an internal feature by its name.
  671. /// </summary>
  672. /// <param name="featureName">Name of the feature.</param>
  673. /// <param name="enabled">Whether to enable or disable the feature.</param>
  674. /// <exception cref="ArgumentNullException"><paramref name="featureName"/> is <c>null</c> or empty.</exception>
  675. /// <remarks>
  676. /// This method is intended for experimental features. These must be enabled/disabled from code.
  677. /// Setting or unsetting a feature flag will not be persisted in an <c>.inputsettings</c> file.
  678. /// </remarks>
  679. public void SetInternalFeatureFlag(string featureName, bool enabled)
  680. {
  681. if (string.IsNullOrEmpty(featureName))
  682. throw new ArgumentNullException(nameof(featureName));
  683. switch (featureName)
  684. {
  685. case InputFeatureNames.kUseOptimizedControls:
  686. optimizedControlsFeatureEnabled = enabled;
  687. break;
  688. case InputFeatureNames.kUseReadValueCaching:
  689. readValueCachingFeatureEnabled = enabled;
  690. break;
  691. case InputFeatureNames.kParanoidReadValueCachingChecks:
  692. paranoidReadValueCachingChecksEnabled = enabled;
  693. break;
  694. default:
  695. if (m_FeatureFlags == null)
  696. m_FeatureFlags = new HashSet<string>();
  697. if (enabled)
  698. m_FeatureFlags.Add(featureName.ToUpperInvariant());
  699. else
  700. m_FeatureFlags.Remove(featureName.ToUpperInvariant());
  701. break;
  702. }
  703. OnChange();
  704. }
  705. [Tooltip("Determine which type of devices are used by the application. By default, this is empty meaning that all devices recognized "
  706. + "by Unity will be used. Restricting the set of supported devices will make only those devices appear in the input system.")]
  707. [SerializeField] private string[] m_SupportedDevices;
  708. [Tooltip("Determine when Unity processes events. By default, accumulated input events are flushed out before each fixed update and "
  709. + "before each dynamic update. This setting can be used to restrict event processing to only where the application needs it.")]
  710. [SerializeField] private UpdateMode m_UpdateMode = UpdateMode.ProcessEventsInDynamicUpdate;
  711. [SerializeField] private int m_MaxEventBytesPerUpdate = 5 * 1024 * 1024;
  712. [SerializeField] private int m_MaxQueuedEventsPerUpdate = 1000;
  713. [SerializeField] private bool m_CompensateForScreenOrientation = true;
  714. [SerializeField] private BackgroundBehavior m_BackgroundBehavior = BackgroundBehavior.ResetAndDisableNonBackgroundDevices;
  715. [SerializeField] private EditorInputBehaviorInPlayMode m_EditorInputBehaviorInPlayMode;
  716. [SerializeField] private InputActionPropertyDrawerMode m_InputActionPropertyDrawerMode = InputActionPropertyDrawerMode.Compact;
  717. [SerializeField] private float m_DefaultDeadzoneMin = 0.125f;
  718. [SerializeField] private float m_DefaultDeadzoneMax = 0.925f;
  719. // A setting of 0.5 seems to roughly be what games generally use on the gamepad triggers.
  720. // Having a higher value here also obsoletes the need for custom press points on stick buttons
  721. // (the up/down/left/right ones).
  722. [Min(ButtonControl.kMinButtonPressPoint)]
  723. [SerializeField] private float m_DefaultButtonPressPoint = 0.5f;
  724. [SerializeField] private float m_ButtonReleaseThreshold = 0.75f;
  725. [SerializeField] private float m_DefaultTapTime = 0.2f;
  726. [SerializeField] private float m_DefaultSlowTapTime = 0.5f;
  727. [SerializeField] private float m_DefaultHoldTime = 0.4f;
  728. [SerializeField] private float m_TapRadius = 5;
  729. [SerializeField] private float m_MultiTapDelayTime = 0.75f;
  730. [SerializeField] private bool m_DisableRedundantEventsMerging = false;
  731. [SerializeField] private bool m_ShortcutKeysConsumeInputs = false; // This is the shortcut support from v1.4. Temporarily moved here as an opt-in feature, while it's issues are investigated.
  732. [NonSerialized] internal HashSet<string> m_FeatureFlags;
  733. internal bool IsFeatureEnabled(string featureName)
  734. {
  735. return m_FeatureFlags != null && m_FeatureFlags.Contains(featureName.ToUpperInvariant());
  736. }
  737. // Needs a static field because feature check is in the hot path
  738. internal static bool optimizedControlsFeatureEnabled = false;
  739. internal static bool readValueCachingFeatureEnabled;
  740. internal static bool paranoidReadValueCachingChecksEnabled;
  741. internal void OnChange()
  742. {
  743. if (InputSystem.settings == this)
  744. InputSystem.s_Manager.ApplySettings();
  745. }
  746. internal const int s_OldUnsupportedFixedAndDynamicUpdateSetting = 0;
  747. /// <summary>
  748. /// How the input system should update.
  749. /// </summary>
  750. /// <remarks>
  751. /// By default, the input system will run event processing as part of the player loop. In the default configuration,
  752. /// the processing will happens once before every every dynamic update (<a href="https://docs.unity3d.com/ScriptReference/MonoBehaviour.Update.html">Update</a>),
  753. /// i.e. <see cref="ProcessEventsInDynamicUpdate"/> is the default behavior.
  754. ///
  755. /// There are two types of updates not governed by UpdateMode. One is <see cref="InputUpdateType.Editor"/> which
  756. /// will always be enabled in the editor and govern input updates for <see cref="UnityEditor.EditorWindow"/>s in
  757. /// sync to <see cref="UnityEditor.EditorApplication.update"/>.
  758. ///
  759. /// The other update type is <see cref="InputUpdateType.BeforeRender"/>. This type of update is enabled and disabled
  760. /// automatically in response to whether devices are present requiring this type of update (<see
  761. /// cref="InputDevice.updateBeforeRender"/>). This update does not consume extra state.
  762. /// </remarks>
  763. /// <seealso cref="InputSystem.Update"/>
  764. /// <seealso cref="InputUpdateType"/>
  765. /// <seealso href="https://docs.unity3d.com/ScriptReference/MonoBehaviour.FixedUpdate.html"/>
  766. /// <seealso href="https://docs.unity3d.com/ScriptReference/MonoBehaviour.Update.html"/>
  767. public enum UpdateMode
  768. {
  769. // Removed: ProcessEventsInBothFixedAndDynamicUpdate=0
  770. /// <summary>
  771. /// Automatically run input updates right before every <a href="https://docs.unity3d.com/ScriptReference/MonoBehaviour.Update.html">Update</a>.
  772. ///
  773. /// In this mode, no processing happens specifically for fixed updates. Querying input state in
  774. /// <a href="https://docs.unity3d.com/ScriptReference/MonoBehaviour.FixedUpdate.html">FixedUpdate</a> will result in errors being logged in the editor and in
  775. /// development builds. In release player builds, the value of the dynamic update state is returned.
  776. /// </summary>
  777. ProcessEventsInDynamicUpdate = 1,
  778. /// <summary>
  779. /// Automatically input run updates right before every <a href="https://docs.unity3d.com/ScriptReference/MonoBehaviour.FixedUpdate.html">FixedUpdate</a>.
  780. ///
  781. /// In this mode, no processing happens specifically for dynamic updates. Querying input state in
  782. /// <a href="https://docs.unity3d.com/ScriptReference/MonoBehaviour.Update.html">Update</a> will result in errors being logged in the editor and in
  783. /// development builds. In release player builds, the value of the fixed update state is returned.
  784. /// </summary>
  785. ProcessEventsInFixedUpdate,
  786. /// <summary>
  787. /// Do not run updates automatically. In this mode, <see cref="InputSystem.Update"/> must be called
  788. /// manually to update input.
  789. ///
  790. /// This mode is most useful for placing input updates in the frame explicitly at an exact location.
  791. ///
  792. /// Note that failing to call <see cref="InputSystem.Update"/> may result in a lot of events
  793. /// accumulating or some input getting lost.
  794. /// </summary>
  795. ProcessEventsManually,
  796. }
  797. /// <summary>
  798. /// Determines how the applications behaves when running in the background. See <see cref="backgroundBehavior"/>.
  799. /// </summary>
  800. /// <seealso href="https://docs.unity3d.com/ScriptReference/Application-isFocused.html"/>
  801. /// <seealso href="https://docs.unity3d.com/ScriptReference/Application-runInBackground.html"/>
  802. /// <seealso cref="backgroundBehavior"/>
  803. /// <seealso cref="InputSettings.editorInputBehaviorInPlayMode"/>
  804. public enum BackgroundBehavior
  805. {
  806. /// <summary>
  807. /// When the application loses focus, issue a <see cref="InputSystem.ResetDevice"/> call on every <see cref="InputDevice"/> that is
  808. /// not marked as <see cref="InputDevice.canRunInBackground"/> and then disable the device (see <see cref="InputSystem.DisableDevice"/>
  809. /// and <see cref="InputDevice.enabled"/>). Devices that <see cref="InputDevice.canRunInBackground"/> will not be touched and will
  810. /// keep running as is.
  811. ///
  812. /// In effect, this setting will "soft-reset" all devices that cannot receive input while the application does
  813. /// not have focus. That is, it will reset all controls that are not marked as <see cref="InputControlLayout.ControlItem.dontReset"/>
  814. /// to their default state.
  815. ///
  816. /// When the application comes back into focus, all devices that have been reset and disabled will be re-enabled and a synchronization
  817. /// request (see <see cref="RequestSyncCommand"/>) will be sent to each device.
  818. ///
  819. /// Devices that are added while the application is running in the background are treated like devices that were already present
  820. /// when losing focus. That is, if they cannot run in the background, they will be disabled until focus comes back.
  821. ///
  822. /// Note that the resets will cancel <see cref="InputAction"/>s that are in progress from controls on devices that are being reset.
  823. /// </summary>
  824. ResetAndDisableNonBackgroundDevices = 0,
  825. /// <summary>
  826. /// Like <see cref="ResetAndDisableNonBackgroundDevices"/> but instead treat all devices as having <see cref="InputDevice.canRunInBackground"/>
  827. /// return false. This effectively means that all input is silenced while the application is running in the background.
  828. /// </summary>
  829. ResetAndDisableAllDevices = 1,
  830. /// <summary>
  831. /// Ignore all changes in focus and leave devices untouched. This also disables focus checks in <see cref="UI.InputSystemUIInputModule"/>.
  832. /// </summary>
  833. IgnoreFocus = 2,
  834. }
  835. /// <summary>
  836. /// Determines how player focus is handled with respect to input when we are in play mode in the editor.
  837. /// See <see cref="InputSettings.editorInputBehaviorInPlayMode"/>. The setting does not have an effect
  838. /// when the editor is not in play mode.
  839. /// </summary>
  840. public enum EditorInputBehaviorInPlayMode
  841. {
  842. /// <summary>
  843. /// When the game view does not have focus, input from <see cref="Pointer"/> devices (such as <see cref="Mouse"/> and <see cref="Touchscreen"/>)
  844. /// is routed to the editor and not visible in player code. Input from devices such as <see cref="Gamepad"/>s will continue to
  845. /// go to the game regardless of which <c>EditorWindow</c> is focused.
  846. ///
  847. /// This is the default. It makes sure that the devices that are used with the editor UI respect <c>EditorWindow</c> focus and thus
  848. /// do not lead to accidental inputs affecting the game. While at the same time letting all other input get through to the game.
  849. /// It does, however, mean that no other <c>EditorWindow</c> can tap input from these devices (such as <see cref="Gamepad"/>s and <see cref="HID"/>s).
  850. /// </summary>
  851. PointersAndKeyboardsRespectGameViewFocus,
  852. /// <summary>
  853. /// When the game view does not have focus, all input is routed to the editor (and thus <c>EditorWindow</c>s). No input
  854. /// is received in the game regardless of the type of device generating it.
  855. /// </summary>
  856. AllDevicesRespectGameViewFocus,
  857. /// <summary>
  858. /// All input is going to the game at all times. This most closely aligns input behavior in the editor with that in players. <see cref="backgroundBehavior"/>
  859. /// will be respected as in the player and devices may thus be disabled in the runtime based on Game View focus.
  860. /// </summary>
  861. AllDeviceInputAlwaysGoesToGameView,
  862. }
  863. /// <summary>
  864. /// Determines how the Inspector window displays <see cref="InputActionProperty"/> fields.
  865. /// </summary>
  866. /// <seealso cref="inputActionPropertyDrawerMode"/>
  867. public enum InputActionPropertyDrawerMode
  868. {
  869. /// <summary>
  870. /// Display the property in a compact format, using a minimal number of lines.
  871. /// Toggling between a reference to an input action in an asset and a directly serialized input action
  872. /// is done using a dropdown menu.
  873. /// </summary>
  874. Compact,
  875. /// <summary>
  876. /// Display the effective action underlying the property, using multiple lines.
  877. /// Toggling between a reference to an input action in an asset and a directly serialized input action
  878. /// is done using a property that is always visible.
  879. /// </summary>
  880. /// <remarks>
  881. /// This mode could be useful if you want to see or revert prefab overrides and hide the field that is ignored.
  882. /// </remarks>
  883. MultilineEffective,
  884. /// <summary>
  885. /// Display both the input action and external reference underlying the property.
  886. /// Toggling between a reference to an input action in an asset and a directly serialized input action
  887. /// is done using a property that is always visible.
  888. /// </summary>
  889. /// <remarks>
  890. /// This mode could be useful if you want to see both values of the property without needing to toggle Use Reference.
  891. /// </remarks>
  892. MultilineBoth,
  893. }
  894. }
  895. }