internal bool Matches(InputDeviceInfo deviceInfo)
        {
            if (VendorID.HasValue)
            {
                if (VendorID.Value != deviceInfo.vendorID)
                {
                    return(false);
                }
            }

            if (ProductID.HasValue)
            {
                if (ProductID.Value != deviceInfo.productID)
                {
                    return(false);
                }
            }

            if (VersionNumber.HasValue)
            {
                if (VersionNumber.Value != deviceInfo.versionNumber)
                {
                    return(false);
                }
            }

            if (DriverType.HasValue)
            {
                if (DriverType.Value != deviceInfo.driverType)
                {
                    return(false);
                }
            }

            if (TransportType.HasValue)
            {
                if (TransportType.Value != deviceInfo.transportType)
                {
                    return(false);
                }
            }

            if (!string.IsNullOrEmpty(NameLiteral))
            {
                if (!string.Equals(deviceInfo.name, NameLiteral, StringComparison.OrdinalIgnoreCase))
                {
                    return(false);
                }
            }

            if (!string.IsNullOrEmpty(NamePattern))
            {
                if (!Regex.IsMatch(deviceInfo.name, NamePattern, RegexOptions.IgnoreCase))
                {
                    return(false);
                }
            }

            return(true);
        }
        public bool HasSameSerialNumber(InputDeviceInfo deviceInfo)
        {
            if (string.IsNullOrEmpty(serialNumber))
            {
                return(false);
            }

            return(serialNumber == deviceInfo.serialNumber);
        }
        public bool HasSameLocation(InputDeviceInfo deviceInfo)
        {
            if (string.IsNullOrEmpty(location))
            {
                return(false);
            }

            return(location == deviceInfo.location);
        }
Beispiel #4
0
        NativeInputDevice FindDetachedDevice(InputDeviceInfo deviceInfo)
        {
            var readOnlyDetachedDevices = new ReadOnlyCollection <NativeInputDevice>(detachedDevices);

            if (CustomFindDetachedDevice != null)
            {
                return(CustomFindDetachedDevice(deviceInfo, readOnlyDetachedDevices));
            }

            return(SystemFindDetachedDevice(deviceInfo, readOnlyDetachedDevices));
        }
Beispiel #5
0
        static NativeInputDevice SystemFindDetachedDevice(InputDeviceInfo deviceInfo, ReadOnlyCollection <NativeInputDevice> detachedDevices)
        {
            var detachedDevicesCount = detachedDevices.Count;

            for (var i = 0; i < detachedDevicesCount; i++)
            {
                var device = detachedDevices[i];
                if (device.Info.HasSameVendorID(deviceInfo) &&
                    device.Info.HasSameProductID(deviceInfo) &&
                    device.Info.HasSameSerialNumber(deviceInfo))
                {
                    return(device);
                }
            }

            for (var i = 0; i < detachedDevicesCount; i++)
            {
                var device = detachedDevices[i];
                if (device.Info.HasSameVendorID(deviceInfo) &&
                    device.Info.HasSameProductID(deviceInfo) &&
                    device.Info.HasSameLocation(deviceInfo))
                {
                    return(device);
                }
            }

            for (var i = 0; i < detachedDevicesCount; i++)
            {
                var device = detachedDevices[i];
                if (device.Info.HasSameVendorID(deviceInfo) &&
                    device.Info.HasSameProductID(deviceInfo) &&
                    device.Info.HasSameVersionNumber(deviceInfo))
                {
                    return(device);
                }
            }

            for (var i = 0; i < detachedDevicesCount; i++)
            {
                var device = detachedDevices[i];
                if (device.Info.HasSameLocation(deviceInfo))
                {
                    return(device);
                }
            }

            return(null);
        }
Beispiel #6
0
        // ReSharper disable once SuggestBaseTypeForParameter
        public bool Matches(InputDeviceInfo deviceInfo, InputDeviceMatcher[] matchers)
        {
            if (matchers != null)
            {
                var matchersCount = matchers.Length;
                for (var i = 0; i < matchersCount; i++)
                {
                    if (matchers[i].Matches(deviceInfo))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
        InputDeviceProfile DetectDevice(string unityJoystickName)
        {
            // Try to find a matching profile for this device.
            InputDeviceProfile deviceProfile = null;

            var deviceInfo = new InputDeviceInfo {
                name = unityJoystickName
            };

            // ReSharper disable once ConstantNullCoalescingCondition
            deviceProfile = deviceProfile ?? customDeviceProfiles.Find(profile => profile.Matches(deviceInfo));
            deviceProfile = deviceProfile ?? systemDeviceProfiles.Find(profile => profile.Matches(deviceInfo));
            deviceProfile = deviceProfile ?? customDeviceProfiles.Find(profile => profile.LastResortMatches(deviceInfo));
            deviceProfile = deviceProfile ?? systemDeviceProfiles.Find(profile => profile.LastResortMatches(deviceInfo));

            return(deviceProfile);
        }
Beispiel #8
0
        void DetectDevice(DeviceHandle deviceHandle, InputDeviceInfo deviceInfo)
        {
            // Try to find a matching profile for this device.
            InputDeviceProfile deviceProfile = null;

            // ReSharper disable once ConstantNullCoalescingCondition
            deviceProfile = deviceProfile ?? customDeviceProfiles.Find(profile => profile.Matches(deviceInfo));
            deviceProfile = deviceProfile ?? systemDeviceProfiles.Find(profile => profile.Matches(deviceInfo));
            deviceProfile = deviceProfile ?? customDeviceProfiles.Find(profile => profile.LastResortMatches(deviceInfo));
            deviceProfile = deviceProfile ?? systemDeviceProfiles.Find(profile => profile.LastResortMatches(deviceInfo));

            // Find a matching previously attached device or create a new one.
            if (deviceProfile == null || deviceProfile.IsNotHidden)
            {
                var device = FindDetachedDevice(deviceInfo) ?? new NativeInputDevice();
                device.Initialize(deviceHandle, deviceInfo, deviceProfile);
                AttachDevice(device);
            }
        }
        void DetectDevice(DeviceHandle deviceHandle, InputDeviceInfo deviceInfo)
        {
            // Try to find a matching profile for this device.
            InputDeviceProfile deviceProfile = null;

            // ReSharper disable once ConstantNullCoalescingCondition
            deviceProfile = deviceProfile ?? customDeviceProfiles.Find(profile => profile.Matches(deviceInfo));
            deviceProfile = deviceProfile ?? systemDeviceProfiles.Find(profile => profile.Matches(deviceInfo));
            deviceProfile = deviceProfile ?? customDeviceProfiles.Find(profile => profile.LastResortMatches(deviceInfo));
            deviceProfile = deviceProfile ?? systemDeviceProfiles.Find(profile => profile.LastResortMatches(deviceInfo));

            // Debug.Log( "MATCHED PROFILE: " + deviceProfile.DeviceName + " (" + deviceProfile.GetType() + ")" );

            // Find a matching previously attached device or create a new one.
            if (!deviceProfile.IsHidden)
            {
                var device = FindDetachedDevice(deviceInfo) ?? new NativeInputDevice();
                device.Initialize(deviceHandle, deviceInfo, deviceProfile);
                AttachDevice(device);
            }
        }
Beispiel #10
0
 public bool HasSameLocation(InputDeviceInfo deviceInfo)
 {
     return(Info.HasSameLocation(deviceInfo));
 }
Beispiel #11
0
 public bool Matches(InputDeviceInfo deviceInfo)
 {
     return(Matches(deviceInfo, Matchers));
 }
Beispiel #12
0
 public bool LastResortMatches(InputDeviceInfo deviceInfo)
 {
     return(Matches(deviceInfo, LastResortMatchers));
 }
 public bool HasSameVersionNumber(InputDeviceInfo deviceInfo)
 {
     return(versionNumber == deviceInfo.versionNumber);
 }
 public bool HasSameProductID(InputDeviceInfo deviceInfo)
 {
     return(productID == deviceInfo.productID);
 }
Beispiel #15
0
 public bool HasSameVendorID(InputDeviceInfo deviceInfo)
 {
     return(Info.HasSameVendorID(deviceInfo));
 }
Beispiel #16
0
 internal void Initialize(DeviceHandle deviceHandle, InputDeviceInfo deviceInfo)
 {
     Initialize(deviceHandle, deviceInfo, this.profile);
 }
Beispiel #17
0
 public bool HasSameProductID(InputDeviceInfo deviceInfo)
 {
     return(Info.HasSameProductID(deviceInfo));
 }
Beispiel #18
0
        internal void Initialize(DeviceHandle deviceHandle, InputDeviceInfo deviceInfo, InputDeviceProfile deviceProfile)
        {
            Handle  = deviceHandle;
            Info    = deviceInfo;
            profile = deviceProfile;

            SortOrder = 1000 + (int)Handle;

            numUnknownButtons = Math.Min((int)Info.numButtons, maxUnknownButtons);
            numUnknownAnalogs = Math.Min((int)Info.numAnalogs, maxUnknownAnalogs);

            buttons = new Int16[Info.numButtons];
            analogs = new Int16[Info.numAnalogs];

            AnalogSnapshot = null;

            const int numInputControlTypes = (int)InputControlType.Count + 1;

            controlSourceByTarget = new InputControlSource[numInputControlTypes];

            ClearInputState();
            ClearControls();

            if (IsKnown)
            {
                Name = profile.DeviceName ?? Info.name;
                Name = Name.Replace("{NAME}", Info.name).Trim();
                Meta = profile.DeviceNotes ?? Info.name;

                DeviceClass = profile.DeviceClass;
                DeviceStyle = profile.DeviceStyle;

                var analogMappingCount = profile.AnalogCount;
                for (var i = 0; i < analogMappingCount; i++)
                {
                    var analogMapping = profile.AnalogMappings[i];
                    var analogControl = AddControl(analogMapping.Target, analogMapping.Name);
                    analogControl.Sensitivity   = Mathf.Min(profile.Sensitivity, analogMapping.Sensitivity);
                    analogControl.LowerDeadZone = Mathf.Max(profile.LowerDeadZone, analogMapping.LowerDeadZone);
                    analogControl.UpperDeadZone = Mathf.Min(profile.UpperDeadZone, analogMapping.UpperDeadZone);
                    analogControl.Raw           = analogMapping.Raw;
                    analogControl.Passive       = analogMapping.Passive;

                    controlSourceByTarget[(int)analogMapping.Target] = analogMapping.Source;
                }

                var buttonMappingCount = profile.ButtonCount;
                for (var i = 0; i < buttonMappingCount; i++)
                {
                    var buttonMapping = profile.ButtonMappings[i];
                    var buttonControl = AddControl(buttonMapping.Target, buttonMapping.Name);
                    buttonControl.Passive = buttonMapping.Passive;

                    controlSourceByTarget[(int)buttonMapping.Target] = buttonMapping.Source;
                }
            }
            else
            {
                Name = "Unknown Device";
                Meta = Info.name;

                for (var i = 0; i < NumUnknownButtons; i++)
                {
                    AddControl(InputControlType.Button0 + i, "Button " + i);
                }

                for (var i = 0; i < NumUnknownAnalogs; i++)
                {
                    AddControl(InputControlType.Analog0 + i, "Analog " + i, 0.2f, 0.9f);
                }
            }

            skipUpdateFrames = 1;
        }
 public bool HasSameVendorID(InputDeviceInfo deviceInfo)
 {
     return(vendorID == deviceInfo.vendorID);
 }
Beispiel #20
0
 public static extern bool GetDeviceInfo(DeviceHandle handle, out InputDeviceInfo deviceInfo);
Beispiel #21
0
 public bool HasSameVersionNumber(InputDeviceInfo deviceInfo)
 {
     return(Info.HasSameVersionNumber(deviceInfo));
 }
Beispiel #22
0
 public static bool GetDeviceInfo(DeviceHandle handle, out InputDeviceInfo deviceInfo)
 {
     deviceInfo = new InputDeviceInfo(); return(false);
 }
Beispiel #23
0
 public bool HasSameSerialNumber(InputDeviceInfo deviceInfo)
 {
     return(Info.HasSameSerialNumber(deviceInfo));
 }