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

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

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

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

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