diff --git a/Packages/com.unity.inputsystem/CHANGELOG.md b/Packages/com.unity.inputsystem/CHANGELOG.md index 5c1a6882d3..d5f36cabfe 100644 --- a/Packages/com.unity.inputsystem/CHANGELOG.md +++ b/Packages/com.unity.inputsystem/CHANGELOG.md @@ -19,6 +19,7 @@ however, it has to be formatted properly to pass verification tests. ### Added - Added Hinge Angle sensor support for foldable devices. +- Added InputDeviceMatcher.WithManufacturerContains(string noRegexMatch) API to improve DualShockSupport.Initialize performance (ISX-1411) ### Changed - Use `ProfilerMarker` instead of `Profiler.BeginSample` and `Profiler.EndSample` when appropriate to enable recording of profiling data. diff --git a/Packages/com.unity.inputsystem/InputSystem/Devices/InputDeviceMatcher.cs b/Packages/com.unity.inputsystem/InputSystem/Devices/InputDeviceMatcher.cs index 496273f5a5..2292ad5058 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Devices/InputDeviceMatcher.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Devices/InputDeviceMatcher.cs @@ -142,6 +142,17 @@ public InputDeviceMatcher WithManufacturer(string pattern, bool supportRegex = t return With(kManufacturerKey, pattern, supportRegex); } + /// + /// Add a pattern (simple string) to to match a . + /// + /// String to match - simple keyword search in a device manufacturer string (eg "SONY"). + /// The modified device matcher with the added pattern. + /// + public InputDeviceMatcher WithManufacturerContains(string noRegExPattern) + { + return With(kManufacturerContainsKey, noRegExPattern, supportRegex: false); + } + /// /// Add a pattern to to match a . /// @@ -309,6 +320,12 @@ public float MatchPercentage(InputDeviceDescription deviceDescription) || !MatchSingleProperty(pattern, deviceDescription.manufacturer)) return 0; } + else if (key == kManufacturerContainsKey) + { + if (string.IsNullOrEmpty(deviceDescription.manufacturer) + || !MatchSinglePropertyContains(pattern, deviceDescription.manufacturer)) + return 0; + } else if (key == kProductKey) { if (string.IsNullOrEmpty(deviceDescription.product) @@ -357,6 +374,15 @@ private static bool MatchSingleProperty(object pattern, string value) return false; } + private static bool MatchSinglePropertyContains(object pattern, string value) + { + // String match. + if (pattern is string str) + return value.Contains(str, StringComparison.OrdinalIgnoreCase); + + return false; + } + private static int GetNumPropertiesIn(InputDeviceDescription description) { var count = 0; @@ -518,6 +544,7 @@ public override int GetHashCode() private static readonly InternedString kInterfaceKey = new InternedString("interface"); private static readonly InternedString kDeviceClassKey = new InternedString("deviceClass"); private static readonly InternedString kManufacturerKey = new InternedString("manufacturer"); + private static readonly InternedString kManufacturerContainsKey = new InternedString("manufacturerContains"); private static readonly InternedString kProductKey = new InternedString("product"); private static readonly InternedString kVersionKey = new InternedString("version"); @@ -529,6 +556,7 @@ internal struct MatcherJson public string deviceClass; public string[] deviceClasses; public string manufacturer; + public string manufacturerContains; public string[] manufacturers; public string product; public string[] products; @@ -617,13 +645,17 @@ public InputDeviceMatcher ToMatcher() foreach (var value in deviceClasses) matcher = matcher.WithDeviceClass(value); - // Manufacturer. + // Manufacturer (string or regex) if (!string.IsNullOrEmpty(manufacturer)) matcher = matcher.WithManufacturer(manufacturer); if (manufacturers != null) foreach (var value in manufacturers) matcher = matcher.WithManufacturer(value); + // ManufacturerContains (simple string, can occur anywhere in the reported manufacturer string) + if (!string.IsNullOrEmpty(manufacturerContains)) + matcher = matcher.WithManufacturerContains(manufacturerContains); + // Product. if (!string.IsNullOrEmpty(product)) matcher = matcher.WithProduct(product); diff --git a/Packages/com.unity.inputsystem/InputSystem/Plugins/DualShock/DualShockSupport.cs b/Packages/com.unity.inputsystem/InputSystem/Plugins/DualShock/DualShockSupport.cs index cd8f2cd3d9..851b3bb734 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Plugins/DualShock/DualShockSupport.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Plugins/DualShock/DualShockSupport.cs @@ -53,7 +53,8 @@ public static void Initialize() InputSystem.RegisterLayoutMatcher( new InputDeviceMatcher() .WithInterface("HID") - .WithManufacturer("Sony.+Entertainment") + .WithManufacturerContains("Sony") + .WithManufacturerContains("Entertainment") .WithProduct("Wireless Controller")); InputSystem.RegisterLayout( @@ -65,8 +66,9 @@ public static void Initialize() InputSystem.RegisterLayoutMatcher( new InputDeviceMatcher() .WithInterface("HID") - .WithManufacturer("Sony.+Entertainment") - .WithProduct("PLAYSTATION(R)3 Controller")); + .WithManufacturerContains("Sony") + .WithManufacturerContains("Entertainment") + .WithProduct("PLAYSTATION(R)3 Controller", supportRegex: false)); #endif } }