diff --git a/Assets/Editor/AddScenesToBuild.cs b/Assets/Editor/AddScenesToBuild.cs index b4f6b85d40..a4285b43f2 100644 --- a/Assets/Editor/AddScenesToBuild.cs +++ b/Assets/Editor/AddScenesToBuild.cs @@ -2,6 +2,7 @@ using UnityEditor; using UnityEditor.SceneManagement; using UnityEngine; +using System; [InitializeOnLoad] public class AddScenesToBuild : EditorWindow @@ -66,7 +67,7 @@ private static bool IsPathInExcludedFolder(string path) // Check if the path or any part of it contains any of the excluded folder names foreach (string folder in excludedFolders) { - if (path.ToLower().Contains(folder.ToLower())) + if (path.Contains(folder, StringComparison.InvariantCultureIgnoreCase)) { return true; } diff --git a/ExternalSampleProjects/InputDeviceTester/Assets/InputDeviceTester/Scripts/Input/GamepadISX.cs b/ExternalSampleProjects/InputDeviceTester/Assets/InputDeviceTester/Scripts/Input/GamepadISX.cs index c7fc965c35..98d7193e43 100644 --- a/ExternalSampleProjects/InputDeviceTester/Assets/InputDeviceTester/Scripts/Input/GamepadISX.cs +++ b/ExternalSampleProjects/InputDeviceTester/Assets/InputDeviceTester/Scripts/Input/GamepadISX.cs @@ -109,9 +109,9 @@ protected string FirstLetterToUpper(string str) if (String.IsNullOrEmpty(str)) return null; else if (str.Length == 1) - return str.ToUpper(); + return str.ToUpperInvariant(); else - return char.ToUpper(str[0]) + str.Substring(1); + return char.ToUpperInvariant(str[0]) + str.Substring(1); } protected void ShowMessage(string msg) diff --git a/ExternalSampleProjects/InputDeviceTester/Assets/InputDeviceTester/Scripts/Input/PenISX.cs b/ExternalSampleProjects/InputDeviceTester/Assets/InputDeviceTester/Scripts/Input/PenISX.cs index 2f22b4b331..dfcb06346c 100644 --- a/ExternalSampleProjects/InputDeviceTester/Assets/InputDeviceTester/Scripts/Input/PenISX.cs +++ b/ExternalSampleProjects/InputDeviceTester/Assets/InputDeviceTester/Scripts/Input/PenISX.cs @@ -190,9 +190,9 @@ private string FirstLetterToUpper(string str) if (String.IsNullOrEmpty(str)) return null; else if (str.Length == 1) - return str.ToUpper(); + return str.ToUpperInvariant(); else - return char.ToUpper(str[0]) + str.Substring(1); + return char.ToUpperInvariant(str[0]) + str.Substring(1); } private void ShowMessage(string msg) diff --git a/Packages/com.unity.inputsystem/CHANGELOG.md b/Packages/com.unity.inputsystem/CHANGELOG.md index a1e43044c6..dce70fbe1a 100644 --- a/Packages/com.unity.inputsystem/CHANGELOG.md +++ b/Packages/com.unity.inputsystem/CHANGELOG.md @@ -17,6 +17,7 @@ however, it has to be formatted properly to pass verification tests. - Fixed the on hover behaviour of the two plus buttons in the Input Actions Editor window [ISXB-1327](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1327) - Fixed an issue on macOS which didn't detect up-left DPAD presses for Xbox controllers. [ISXB-810](https://issuetracker.unity3d.com/issues/macos-d-pad-upper-left-corner-is-not-logged-with-the-xbox-controller) - Fixed Input Actions code generation overwriting user files when the names happened to match. [ISXB-1257](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1257) +- Fixed Input Actions code generation using locale-dependent rules when lowercasing and uppercasing strings. [ISXB-1406](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1406) - Fixed an issue when providing JoinPlayer with a specific split screen index. [ISXB-897](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-897) ## [1.14.0] - 2025-03-20 diff --git a/Packages/com.unity.inputsystem/InputSystem/Controls/InputControlLayout.cs b/Packages/com.unity.inputsystem/InputSystem/Controls/InputControlLayout.cs index 501378afdc..3d7430d722 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Controls/InputControlLayout.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Controls/InputControlLayout.cs @@ -1673,7 +1673,7 @@ public InputControlLayout ToLayout() // Before render behavior. if (!string.IsNullOrEmpty(beforeRender)) { - var beforeRenderLowerCase = beforeRender.ToLower(); + var beforeRenderLowerCase = beforeRender.ToLowerInvariant(); if (beforeRenderLowerCase == "ignore") layout.m_UpdateBeforeRender = false; else if (beforeRenderLowerCase == "update") @@ -1685,7 +1685,7 @@ public InputControlLayout ToLayout() // CanRunInBackground flag. if (!string.IsNullOrEmpty(runInBackground)) { - var runInBackgroundLowerCase = runInBackground.ToLower(); + var runInBackgroundLowerCase = runInBackground.ToLowerInvariant(); if (runInBackgroundLowerCase == "enabled") layout.canRunInBackground = true; else if (runInBackgroundLowerCase == "disabled") diff --git a/Packages/com.unity.inputsystem/InputSystem/Controls/InputControlPath.cs b/Packages/com.unity.inputsystem/InputSystem/Controls/InputControlPath.cs index d2b42d39b3..b1a0aaaa3f 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Controls/InputControlPath.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Controls/InputControlPath.cs @@ -559,7 +559,7 @@ private static bool StringMatches(Substring str, InternedString matchTo) return true; // Wildcard at end of string so rest is matched. ++posInStr; - nextChar = char.ToLower(str[posInStr], CultureInfo.InvariantCulture); + nextChar = char.ToLowerInvariant(str[posInStr]); while (posInMatchTo < matchToLength && matchToLowerCase[posInMatchTo] != nextChar) ++posInMatchTo; @@ -567,7 +567,7 @@ private static bool StringMatches(Substring str, InternedString matchTo) if (posInMatchTo == matchToLength) return false; // Matched all the way to end of matchTo but there's more in str after the wildcard. } - else if (char.ToLower(nextChar, CultureInfo.InvariantCulture) != matchToLowerCase[posInMatchTo]) + else if (char.ToLowerInvariant(nextChar) != matchToLowerCase[posInMatchTo]) { return false; } @@ -1156,7 +1156,7 @@ private static bool MatchPathComponent(string component, string path, ref int in } var charInComponent = component[indexInComponent]; - if (charInComponent == nextCharInPath || char.ToLower(charInComponent, CultureInfo.InvariantCulture) == char.ToLower(nextCharInPath, CultureInfo.InvariantCulture)) + if (charInComponent == nextCharInPath || char.ToLowerInvariant(charInComponent) == char.ToLowerInvariant(nextCharInPath)) { ++indexInComponent; ++indexInPath; diff --git a/Packages/com.unity.inputsystem/InputSystem/Controls/KeyControl.cs b/Packages/com.unity.inputsystem/InputSystem/Controls/KeyControl.cs index de58183fa8..3e5b601583 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Controls/KeyControl.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Controls/KeyControl.cs @@ -77,17 +77,18 @@ protected override void RefreshConfiguration() return; } - var textInfo = CultureInfo.InvariantCulture.TextInfo; // We need to lower case first because ToTitleCase preserves upper casing. // For example on Swedish Windows layout right shift display name is "HÖGER SKIFT". // Just passing it to ToTitleCase won't change anything. But passing "höger skift" will return "Höger Skift". - var keyNameLowerCase = textInfo.ToLower(rawKeyName); + var keyNameLowerCase = rawKeyName.ToLowerInvariant(); + if (string.IsNullOrEmpty(keyNameLowerCase)) { displayName = rawKeyName; return; } + var textInfo = CultureInfo.InvariantCulture.TextInfo; displayName = textInfo.ToTitleCase(keyNameLowerCase); } } diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/AssetImporter/InputActionImporter.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/AssetImporter/InputActionImporter.cs index 4eb0826fc0..03910a9d1a 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/AssetImporter/InputActionImporter.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/AssetImporter/InputActionImporter.cs @@ -236,8 +236,8 @@ private static void GenerateWrapperCode(AssetImportContext ctx, InputActionAsset var directory = Path.GetDirectoryName(assetPath); wrapperFilePath = Path.Combine(directory, wrapperFilePath); } - else if (!wrapperFilePath.ToLower().StartsWith("assets/") && - !wrapperFilePath.ToLower().StartsWith("assets\\")) + else if (!wrapperFilePath.StartsWith("assets/", StringComparison.InvariantCultureIgnoreCase) && + !wrapperFilePath.StartsWith("assets\\", StringComparison.InvariantCultureIgnoreCase)) { // User-specified file in Assets/ folder. wrapperFilePath = Path.Combine("Assets", wrapperFilePath); diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/InputParameterEditor.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/InputParameterEditor.cs index 6d7efc2e3d..ba2bf38db7 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/InputParameterEditor.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/InputParameterEditor.cs @@ -210,7 +210,7 @@ public void Initialize(string label, string tooltip, string defaultName, Func> Project Settings... >> Input (NEW)." + ? $"If enabled, the default {label.ToLowerInvariant()} configured globally in the input settings is used. See Edit >> Project Settings... >> Input (NEW)." : "If enabled, the default value is used."); m_ValueLabel = EditorGUIUtility.TrTextContent(label, tooltip); if (defaultComesFromInputSettings) diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/InputSystemPluginControl.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/InputSystemPluginControl.cs index 30ae8bee3e..f0f120bf7f 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/InputSystemPluginControl.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/InputSystemPluginControl.cs @@ -73,10 +73,10 @@ public static void RegisterPlatform(BuildTarget target) private static bool IsPluginInstalled() { var registeredPackages = UnityEditor.PackageManager.PackageInfo.GetAllRegisteredPackages(); - var plugInName = PlugInName + EditorUserBuildSettings.activeBuildTarget.ToString().ToLower(); + var plugInName = PlugInName + EditorUserBuildSettings.activeBuildTarget.ToString(); foreach (var package in registeredPackages) { - if (package.name.Equals(plugInName)) + if (package.name.Equals(plugInName, StringComparison.InvariantCultureIgnoreCase)) return true; } return false; diff --git a/Packages/com.unity.inputsystem/InputSystem/Editor/Internal/AdvancedDropdown/AdvancedDropdownDataSource.cs b/Packages/com.unity.inputsystem/InputSystem/Editor/Internal/AdvancedDropdown/AdvancedDropdownDataSource.cs index 23fd0ca927..9ecbc3c07e 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Editor/Internal/AdvancedDropdown/AdvancedDropdownDataSource.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Editor/Internal/AdvancedDropdown/AdvancedDropdownDataSource.cs @@ -80,7 +80,7 @@ protected virtual AdvancedDropdownItem Search(string searchString) if (searchTree == null) { // Support multiple search words separated by spaces. - var searchWords = searchString.ToLower().Split(' '); + var searchWords = searchString.ToLowerInvariant().Split(' '); // We keep two lists. Matches that matches the start of an item always get first priority. var matchesStart = new List(); @@ -88,7 +88,7 @@ protected virtual AdvancedDropdownItem Search(string searchString) foreach (var e in m_SearchableElements) { - var name = e.searchableName.ToLower().Replace(" ", ""); + var name = e.searchableName.ToLowerInvariant().Replace(" ", ""); AddMatchItem(e, name, searchWords, matchesStart, matchesWithin); } diff --git a/Packages/com.unity.inputsystem/InputSystem/Plugins/XR/XRLayoutBuilder.cs b/Packages/com.unity.inputsystem/InputSystem/Plugins/XR/XRLayoutBuilder.cs index e73dc3d648..3c3ef1aa31 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Plugins/XR/XRLayoutBuilder.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Plugins/XR/XRLayoutBuilder.cs @@ -217,7 +217,7 @@ private InputControlLayout Build() if (inheritedLayout != null) featureName = ConvertPotentialAliasToName(inheritedLayout, featureName); - featureName = featureName.ToLower(); + featureName = featureName.ToLowerInvariant(); if (IsSubControl(featureName)) { diff --git a/Packages/com.unity.inputsystem/InputSystem/Utilities/CSharpCodeHelpers.cs b/Packages/com.unity.inputsystem/InputSystem/Utilities/CSharpCodeHelpers.cs index f79053afda..e8c3e1d628 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Utilities/CSharpCodeHelpers.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Utilities/CSharpCodeHelpers.cs @@ -85,7 +85,7 @@ public static string MakeTypeName(string name, string suffix = "") { var symbolName = MakeIdentifier(name, suffix); if (char.IsLower(symbolName[0])) - symbolName = char.ToUpper(symbolName[0]) + symbolName.Substring(1); + symbolName = char.ToUpperInvariant(symbolName[0]) + symbolName.Substring(1); return symbolName; } diff --git a/Packages/com.unity.inputsystem/InputSystem/Utilities/InternedString.cs b/Packages/com.unity.inputsystem/InputSystem/Utilities/InternedString.cs index c9f1da2757..8badfff055 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Utilities/InternedString.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Utilities/InternedString.cs @@ -171,26 +171,22 @@ public override string ToString() public static bool operator==(InternedString a, string b) { - return string.Compare(a.m_StringLowerCase, b.ToLower(CultureInfo.InvariantCulture), - StringComparison.InvariantCultureIgnoreCase) == 0; + return string.Compare(a.m_StringLowerCase, b, StringComparison.InvariantCultureIgnoreCase) == 0; } public static bool operator!=(InternedString a, string b) { - return string.Compare(a.m_StringLowerCase, b.ToLower(CultureInfo.InvariantCulture), - StringComparison.InvariantCultureIgnoreCase) != 0; + return string.Compare(a.m_StringLowerCase, b, StringComparison.InvariantCultureIgnoreCase) != 0; } public static bool operator==(string a, InternedString b) { - return string.Compare(a.ToLower(CultureInfo.InvariantCulture), b.m_StringLowerCase, - StringComparison.InvariantCultureIgnoreCase) == 0; + return string.Compare(a, b.m_StringLowerCase, StringComparison.InvariantCultureIgnoreCase) == 0; } public static bool operator!=(string a, InternedString b) { - return string.Compare(a.ToLower(CultureInfo.InvariantCulture), b.m_StringLowerCase, - StringComparison.InvariantCultureIgnoreCase) != 0; + return string.Compare(a, b.m_StringLowerCase, StringComparison.InvariantCultureIgnoreCase) != 0; } public static bool operator<(InternedString left, InternedString right) diff --git a/Packages/com.unity.inputsystem/InputSystem/Utilities/StringHelpers.cs b/Packages/com.unity.inputsystem/InputSystem/Utilities/StringHelpers.cs index 19691a86bf..56991ebe5b 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Utilities/StringHelpers.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Utilities/StringHelpers.cs @@ -327,7 +327,6 @@ public static string MakeUniqueName(string baseName, IEnumerable(string baseName, IEnumerable