Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Packages/com.unity.inputsystem/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,17 @@ public InputDeviceMatcher WithManufacturer(string pattern, bool supportRegex = t
return With(kManufacturerKey, pattern, supportRegex);
}

/// <summary>
/// Add a pattern (simple string) to <see cref="patterns"/> to match a <see cref="InputDeviceDescription.manufacturer"/>.
/// </summary>
/// <param name="noRegExPattern">String to match - simple keyword search in a device manufacturer string (eg "SONY").</param>
/// <returns>The modified device matcher with the added pattern.</returns>
/// <seealso cref="InputDeviceDescription.manufacturer"/>
public InputDeviceMatcher WithManufacturerContains(string noRegExPattern)
{
return With(kManufacturerContainsKey, noRegExPattern, supportRegex: false);
}

/// <summary>
/// Add a pattern to <see cref="patterns"/> to match a <see cref="InputDeviceDescription.product"/>.
/// </summary>
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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");

Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ public static void Initialize()
InputSystem.RegisterLayoutMatcher<DualShock4GamepadHID>(
new InputDeviceMatcher()
.WithInterface("HID")
.WithManufacturer("Sony.+Entertainment")
.WithManufacturerContains("Sony")
.WithManufacturerContains("Entertainment")
.WithProduct("Wireless Controller"));

InputSystem.RegisterLayout<DualShock3GamepadHID>(
Expand All @@ -65,8 +66,9 @@ public static void Initialize()
InputSystem.RegisterLayoutMatcher<DualShock3GamepadHID>(
new InputDeviceMatcher()
.WithInterface("HID")
.WithManufacturer("Sony.+Entertainment")
.WithProduct("PLAYSTATION(R)3 Controller"));
.WithManufacturerContains("Sony")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering it this could be just WithManufacturer("Sony", supportRegex:false) ?

There is a small chance this matches wider now - E.g. Entertainment Sony would match now, but I don't think this is likely to be any false positives.

Copy link
Contributor Author

@AlexTyrer AlexTyrer Aug 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it needs to be an exact match as the code does:

string.Compare(...) == 0

... so we would need to provide the entire manufacturer string - and there seem to be two flavours of Sony manufacturer string:

  • "Sony Interactive Entertainment"
  • "Sony Computer Entertainment"

... hence the regex in the original code.

Just checked this.

.WithManufacturer("Sony", supportRegex:false) // test
... and some of the tests fail.

This is the reason why I added the 'Contains' thing - an explicit non-regex pattern that just has to be in the manufacturer string.

.WithManufacturerContains("Entertainment")
.WithProduct("PLAYSTATION(R)3 Controller", supportRegex: false));
#endif
}
}
Expand Down