|
3 | 3 | using System.Linq; |
4 | 4 | using UnityEditor; |
5 | 5 |
|
| 6 | +#if UNITY_6000_0_OR_NEWER |
| 7 | +using System.Reflection; |
| 8 | +using UnityEditor.Build.Profile; |
| 9 | +#endif |
| 10 | + |
6 | 11 | namespace UnityEngine.InputSystem.Editor |
7 | 12 | { |
8 | 13 | internal static class EditorPlayerSettingHelpers |
@@ -154,7 +159,33 @@ private static int TupleToActiveInputHandler((bool newSystemEnabled, bool oldSys |
154 | 159 |
|
155 | 160 | private static SerializedProperty GetPropertyOrNull(string name) |
156 | 161 | { |
| 162 | +#if UNITY_6000_0_OR_NEWER |
| 163 | + // HOTFIX: the code below works around an issue causing an infinite reimport loop |
| 164 | + // this will be replaced by a call to an API in the editor instead of using reflection once it is available |
| 165 | + var buildProfileType = typeof(BuildProfile); |
| 166 | + var globalPlayerSettingsField = buildProfileType.GetField("s_GlobalPlayerSettings", BindingFlags.Static | BindingFlags.NonPublic); |
| 167 | + if (globalPlayerSettingsField == null) |
| 168 | + { |
| 169 | + Debug.LogError($"Could not find global player settings field in build profile when trying to get property {name}. Please try to update the Input System package."); |
| 170 | + return null; |
| 171 | + } |
| 172 | + var playerSettings = (PlayerSettings)globalPlayerSettingsField.GetValue(null); |
| 173 | + var activeBuildProfile = BuildProfile.GetActiveBuildProfile(); |
| 174 | + if (activeBuildProfile != null) |
| 175 | + { |
| 176 | + var playerSettingsOverrideField = buildProfileType.GetField("m_PlayerSettings", BindingFlags.Instance | BindingFlags.NonPublic); |
| 177 | + if (playerSettingsOverrideField == null) |
| 178 | + { |
| 179 | + Debug.LogError($"Could not find player settings override field in build profile when trying to get property {name}. Please try to update the Input System package."); |
| 180 | + return null; |
| 181 | + } |
| 182 | + var playerSettingsOverride = (PlayerSettings)playerSettingsOverrideField.GetValue(activeBuildProfile); |
| 183 | + if (playerSettingsOverride != null) |
| 184 | + playerSettings = playerSettingsOverride; |
| 185 | + } |
| 186 | +#else |
157 | 187 | var playerSettings = Resources.FindObjectsOfTypeAll<PlayerSettings>().FirstOrDefault(); |
| 188 | +#endif |
158 | 189 | if (playerSettings == null) |
159 | 190 | return null; |
160 | 191 | var playerSettingsObject = new SerializedObject(playerSettings); |
|
0 commit comments