暫無描述
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.

InputEditorUserSettings.cs 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #if UNITY_EDITOR
  2. using System;
  3. using System.IO;
  4. ////TODO: event diagnostics should have a bool here
  5. namespace UnityEngine.InputSystem.Editor
  6. {
  7. /// <summary>
  8. /// Settings that are local to the current user and specific to the input system's use in the editor.
  9. /// </summary>
  10. /// <remarks>
  11. /// These settings are not stored in assets in the project along with the other input settings.
  12. /// Instead, they are serialized to JSON and stored in the project's Library/ folder.
  13. /// </remarks>
  14. internal static class InputEditorUserSettings
  15. {
  16. /// <summary>
  17. /// Where the settings are stored in the user's project.
  18. /// </summary>
  19. private const string kSavePath = "Library/InputUserSettings.json";
  20. public static bool simulateTouch
  21. {
  22. get => s_Settings.simulateTouch;
  23. set
  24. {
  25. if (s_Settings.simulateTouch == value)
  26. return;
  27. s_Settings.simulateTouch = value;
  28. OnChange();
  29. }
  30. }
  31. /// <summary>
  32. /// If this is true, then if <see cref="InputSettings.supportedDevices"/> is not empty, do
  33. /// not use it to prevent native devices
  34. /// </summary>
  35. /// <remarks>
  36. /// This switch is useful to preserve use of devices in the editor regardless of whether they the
  37. /// kind of devices used by the game at runtime. For example, a game may support only gamepads but
  38. /// in the editor, the keyboard, mouse, and tablet should still be usable.
  39. ///
  40. /// This switch is enabled by default.
  41. /// </remarks>
  42. public static bool addDevicesNotSupportedByProject
  43. {
  44. get => s_Settings.addDevicesNotSupportedByProject;
  45. set
  46. {
  47. if (s_Settings.addDevicesNotSupportedByProject == value)
  48. return;
  49. s_Settings.addDevicesNotSupportedByProject = value;
  50. OnChange();
  51. }
  52. }
  53. /// <summary>
  54. /// If this is true, then instead of having an explicit save button in the .inputactions asset editor,
  55. /// any changes will be saved automatically and immediately.
  56. /// </summary>
  57. /// <remarks>
  58. /// Disabled by default.
  59. /// </remarks>
  60. public static bool autoSaveInputActionAssets
  61. {
  62. get => s_Settings.autoSaveInputActionAssets;
  63. set
  64. {
  65. if (s_Settings.autoSaveInputActionAssets == value)
  66. return;
  67. s_Settings.autoSaveInputActionAssets = value;
  68. OnChange();
  69. }
  70. }
  71. [Serializable]
  72. internal struct SerializedState
  73. {
  74. public bool addDevicesNotSupportedByProject;
  75. public bool autoSaveInputActionAssets;
  76. public bool simulateTouch;
  77. }
  78. internal static SerializedState s_Settings;
  79. private static void OnChange()
  80. {
  81. Save();
  82. InputSystem.s_Manager.ApplySettings();
  83. }
  84. internal static void Load()
  85. {
  86. s_Settings = new SerializedState();
  87. if (!File.Exists(kSavePath))
  88. return;
  89. try
  90. {
  91. var json = File.ReadAllText(kSavePath);
  92. s_Settings = JsonUtility.FromJson<SerializedState>(json);
  93. }
  94. catch
  95. {
  96. s_Settings = new SerializedState();
  97. }
  98. }
  99. internal static void Save()
  100. {
  101. var json = JsonUtility.ToJson(s_Settings, prettyPrint: true);
  102. File.WriteAllText(kSavePath, json);
  103. }
  104. }
  105. }
  106. #endif