public static DeviceInfo FromDescription(InputDeviceDescription description, bool native = false, string layout = null) { string product; if (!string.IsNullOrEmpty(description.product) && !string.IsNullOrEmpty(description.manufacturer)) { product = string.Format("{0} {1}", description.manufacturer, description.product); } else if (!string.IsNullOrEmpty(description.product)) { product = description.product; } else { product = description.manufacturer; } if (string.IsNullOrEmpty(layout)) { layout = description.deviceClass; } return(new DeviceInfo { layout = layout, @interface = description.interfaceName, product = product, native = native }); }
public static InputDeviceMatcher FromDeviceDescription(InputDeviceDescription deviceDescription) { var matcher = new InputDeviceMatcher(); if (!string.IsNullOrEmpty(deviceDescription.interfaceName)) { matcher = matcher.WithInterface(deviceDescription.interfaceName); } if (!string.IsNullOrEmpty(deviceDescription.deviceClass)) { matcher = matcher.WithDeviceClass(deviceDescription.deviceClass); } if (!string.IsNullOrEmpty(deviceDescription.manufacturer)) { matcher = matcher.WithManufacturer(deviceDescription.manufacturer); } if (!string.IsNullOrEmpty(deviceDescription.product)) { matcher = matcher.WithProduct(deviceDescription.product); } if (!string.IsNullOrEmpty(deviceDescription.version)) { matcher = matcher.WithVersion(deviceDescription.version); } // We don't include capabilities in this conversion. return(matcher); }
private static bool IsIgnoredDevice(InputDeviceDescription description) { #if UNITY_STANDALONE_WIN #endif return(false); }
private int GetNumPropertiesIn(InputDeviceDescription description) { var count = 0; if (!string.IsNullOrEmpty(description.interfaceName)) { count += 1; } if (!string.IsNullOrEmpty(description.deviceClass)) { count += 1; } if (!string.IsNullOrEmpty(description.manufacturer)) { count += 1; } if (!string.IsNullOrEmpty(description.product)) { count += 1; } if (!string.IsNullOrEmpty(description.version)) { count += 1; } if (!string.IsNullOrEmpty(description.capabilities)) { count += 1; } return(count); }
internal void SetupWithDescription(InternedString layout, InputDeviceDescription deviceDescription, InternedString variant) { InstantiateLayout(layout, variant, new InternedString(), null, null); FinalizeControlHierarchy(); if (!deviceDescription.empty) { m_Device.m_Description = deviceDescription; } m_Device.CallFinishSetupRecursive(this); }
public int ReportNewInputDevice(InputDeviceDescription description, int deviceId = InputDevice.kInvalidDeviceId, ulong userHandle = 0, string userName = null, string userId = null) { deviceId = ReportNewInputDevice(description.ToJson(), deviceId); // If we have user information, automatically set up if (userHandle != 0) { AssociateInputDeviceWithUser(deviceId, userHandle, userName, userId); } return(deviceId); }
public int ReportNewInputDevice(InputDeviceDescription description, int deviceId = InputDevice.kInvalidDeviceId) { return(ReportNewInputDevice(description.ToJson(), deviceId)); }
/// <summary> /// Return the level of matching to the given <paramref name="deviceDescription">device description</paramref>. /// </summary> /// <param name="deviceDescription"></param> /// <returns></returns> /// <remarks> /// The algorithm computes a score of how well the matcher matches the given description. For every property /// that is present on t /// </remarks> public float MatchPercentage(InputDeviceDescription deviceDescription) { if (empty) { return(0); } // Go through all patterns. Score is 0 if any of the patterns // doesn't match. var numPatterns = m_Patterns.Length; for (var i = 0; i < numPatterns; ++i) { var key = m_Patterns[i].Key; var pattern = m_Patterns[i].Value; if (key == kInterfaceKey) { if (string.IsNullOrEmpty(deviceDescription.interfaceName) || !MatchSingleProperty(pattern, deviceDescription.interfaceName)) { return(0); } } else if (key == kDeviceClassKey) { if (string.IsNullOrEmpty(deviceDescription.deviceClass) || !MatchSingleProperty(pattern, deviceDescription.deviceClass)) { return(0); } } else if (key == kManufacturerKey) { if (string.IsNullOrEmpty(deviceDescription.manufacturer) || !MatchSingleProperty(pattern, deviceDescription.manufacturer)) { return(0); } } else if (key == kProductKey) { if (string.IsNullOrEmpty(deviceDescription.product) || !MatchSingleProperty(pattern, deviceDescription.product)) { return(0); } } else if (key == kVersionKey) { if (string.IsNullOrEmpty(deviceDescription.version) || !MatchSingleProperty(pattern, deviceDescription.version)) { return(0); } } else { // Capabilities match. Take the key as a path into the JSON // object and match the value found at the given path. if (string.IsNullOrEmpty(deviceDescription.capabilities)) { return(0); } var graph = new JsonGraph(deviceDescription.capabilities); if (!graph.NavigateToProperty(key.ToString()) || !graph.CurrentPropertyHasValueEqualTo(pattern)) { return(0); } } } // All patterns matched. Our score is determined by the number of properties // we matched against. var propertyCountInDescription = GetNumPropertiesIn(deviceDescription); var scorePerProperty = 1.0f / propertyCountInDescription; return(numPatterns * scorePerProperty); }