Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        public bool HasSameSerialNumber(InputDeviceInfo deviceInfo)
        {
            if (string.IsNullOrEmpty(serialNumber))
            {
                return(false);
            }

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

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

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

            return(SystemFindDetachedDevice(deviceInfo, readOnlyDetachedDevices));
        }
Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 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);
            }
        }
Esempio n. 10
0
 public bool HasSameLocation(InputDeviceInfo deviceInfo)
 {
     return(Info.HasSameLocation(deviceInfo));
 }
Esempio n. 11
0
 public bool Matches(InputDeviceInfo deviceInfo)
 {
     return(Matches(deviceInfo, Matchers));
 }
Esempio n. 12
0
 public bool LastResortMatches(InputDeviceInfo deviceInfo)
 {
     return(Matches(deviceInfo, LastResortMatchers));
 }
Esempio n. 13
0
 public bool HasSameVersionNumber(InputDeviceInfo deviceInfo)
 {
     return(versionNumber == deviceInfo.versionNumber);
 }
Esempio n. 14
0
 public bool HasSameProductID(InputDeviceInfo deviceInfo)
 {
     return(productID == deviceInfo.productID);
 }
Esempio n. 15
0
 public bool HasSameVendorID(InputDeviceInfo deviceInfo)
 {
     return(Info.HasSameVendorID(deviceInfo));
 }
Esempio n. 16
0
 internal void Initialize(DeviceHandle deviceHandle, InputDeviceInfo deviceInfo)
 {
     Initialize(deviceHandle, deviceInfo, this.profile);
 }
Esempio n. 17
0
 public bool HasSameProductID(InputDeviceInfo deviceInfo)
 {
     return(Info.HasSameProductID(deviceInfo));
 }
Esempio n. 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;
        }
Esempio n. 19
0
 public bool HasSameVendorID(InputDeviceInfo deviceInfo)
 {
     return(vendorID == deviceInfo.vendorID);
 }
Esempio n. 20
0
 public static extern bool GetDeviceInfo(DeviceHandle handle, out InputDeviceInfo deviceInfo);
Esempio n. 21
0
 public bool HasSameVersionNumber(InputDeviceInfo deviceInfo)
 {
     return(Info.HasSameVersionNumber(deviceInfo));
 }
Esempio n. 22
0
 public static bool GetDeviceInfo(DeviceHandle handle, out InputDeviceInfo deviceInfo)
 {
     deviceInfo = new InputDeviceInfo(); return(false);
 }
Esempio n. 23
0
 public bool HasSameSerialNumber(InputDeviceInfo deviceInfo)
 {
     return(Info.HasSameSerialNumber(deviceInfo));
 }