InputUpdateType.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. using System;
  2. using UnityEngine.InputSystem.Layouts;
  3. ////TODO: ManualThreaded
  4. namespace UnityEngine.InputSystem.LowLevel
  5. {
  6. /// <summary>
  7. /// Enum of different player loop positions where the input system can invoke it's update mechanism.
  8. /// </summary>
  9. [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1714:FlagsEnumsShouldHavePluralNames", Justification = "Not consistently used as flags, many using APIs expect only one type to be passed.")]
  10. [Flags]
  11. public enum InputUpdateType
  12. {
  13. None = 0,
  14. /// <summary>
  15. /// Update corresponding to <see cref="MonoBehaviour.OnUpdate"/>.
  16. /// </summary>
  17. /// <remarks>
  18. /// Every frame has exactly one dynamic update. If not reconfigured using <see cref="PlayerLoop"/>,
  19. /// the dynamic update happens after all the fixed updates for the frame have run (which can be
  20. /// zero or more).
  21. ///
  22. /// Input updates run before script callbacks on MonoBehaviours are fired.
  23. /// </remarks>
  24. Dynamic = 1 << 0,
  25. /// <summary>
  26. /// Update corresponding to <see cref="MonoBehaviour.OnFixedUpdate"/>.
  27. /// </summary>
  28. /// <remarks>
  29. /// Every frame has zero or more fixed updates. These are run before the dynamic update for the
  30. /// frame.
  31. ///
  32. /// Input updates run before script callbacks on MonoBehaviours are fired.
  33. /// </remarks>
  34. Fixed = 1 << 1,
  35. ////REVIEW: Axe this update type from the public API?
  36. /// <summary>
  37. /// Input update that happens right before rendering.
  38. /// </summary>
  39. /// <remarks>
  40. /// The BeforeRender update affects only devices that have before-render updates enabled. This
  41. /// has to be done through a device's layout (<see cref="InputControlLayout.updateBeforeRender"/>
  42. /// and is visible through <see cref="InputDevice.updateBeforeRender"/>.
  43. ///
  44. /// BeforeRender updates are useful to minimize lag of transform data that is used in rendering
  45. /// but is coming from external tracking devices. An example are HMDs. If the head transform used
  46. /// for the render camera is not synchronized right before rendering, it can result in a noticeable
  47. /// lag between head and camera movement.
  48. /// </remarks>
  49. BeforeRender = 1 << 2,
  50. /// <summary>
  51. /// Input update that happens right before <see cref="UnityEditor.EditorWindow"/>s are updated.
  52. /// </summary>
  53. /// <remarks>
  54. /// This update only occurs in the editor. It is triggered right before <see cref="UnityEditor.EditorApplication.update"/>.
  55. /// </remarks>
  56. /// <seealso cref="UnityEditor.EditorApplication.update"/>
  57. Editor = 1 << 3,
  58. ////TODO
  59. Manual = 1 << 4,
  60. ////REVIEW: kill?
  61. Default = Dynamic | Fixed | Editor,
  62. }
  63. internal static class InputUpdate
  64. {
  65. public static InputUpdateType s_LastUpdateType;
  66. public static uint s_UpdateStepCount;
  67. public static uint s_LastUpdateRetainedEventBytes;
  68. public static uint s_LastUpdateRetainedEventCount;
  69. [Serializable]
  70. public struct SerializedState
  71. {
  72. public InputUpdateType lastUpdateType;
  73. public uint updateStepCount;
  74. public uint lastUpdateRetainedEventBytes;
  75. public uint lastUpdateRetainedEventCount;
  76. }
  77. public static SerializedState Save()
  78. {
  79. return new SerializedState
  80. {
  81. lastUpdateType = s_LastUpdateType,
  82. updateStepCount = s_UpdateStepCount,
  83. lastUpdateRetainedEventBytes = s_LastUpdateRetainedEventBytes,
  84. lastUpdateRetainedEventCount = s_LastUpdateRetainedEventCount,
  85. };
  86. }
  87. public static void Restore(SerializedState state)
  88. {
  89. s_LastUpdateType = state.lastUpdateType;
  90. s_UpdateStepCount = state.updateStepCount;
  91. s_LastUpdateRetainedEventBytes = state.lastUpdateRetainedEventBytes;
  92. s_LastUpdateRetainedEventCount = state.lastUpdateRetainedEventCount;
  93. }
  94. }
  95. }