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