コード例 #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);
        }
コード例 #2
0
        public bool HasSameSerialNumber(InputDeviceInfo deviceInfo)
        {
            if (string.IsNullOrEmpty(serialNumber))
            {
                return(false);
            }

            return(serialNumber == deviceInfo.serialNumber);
        }
コード例 #3
0
        public bool HasSameLocation(InputDeviceInfo deviceInfo)
        {
            if (string.IsNullOrEmpty(location))
            {
                return(false);
            }

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

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

            return(SystemFindDetachedDevice(deviceInfo, readOnlyDetachedDevices));
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #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);
            }
        }
コード例 #9
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));

            // 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);
            }
        }
コード例 #10
0
 public bool HasSameLocation(InputDeviceInfo deviceInfo)
 {
     return(Info.HasSameLocation(deviceInfo));
 }
コード例 #11
0
 public bool Matches(InputDeviceInfo deviceInfo)
 {
     return(Matches(deviceInfo, Matchers));
 }
コード例 #12
0
 public bool LastResortMatches(InputDeviceInfo deviceInfo)
 {
     return(Matches(deviceInfo, LastResortMatchers));
 }
コード例 #13
0
 public bool HasSameVersionNumber(InputDeviceInfo deviceInfo)
 {
     return(versionNumber == deviceInfo.versionNumber);
 }
コード例 #14
0
 public bool HasSameProductID(InputDeviceInfo deviceInfo)
 {
     return(productID == deviceInfo.productID);
 }
コード例 #15
0
 public bool HasSameVendorID(InputDeviceInfo deviceInfo)
 {
     return(Info.HasSameVendorID(deviceInfo));
 }
コード例 #16
0
 internal void Initialize(DeviceHandle deviceHandle, InputDeviceInfo deviceInfo)
 {
     Initialize(deviceHandle, deviceInfo, this.profile);
 }
コード例 #17
0
 public bool HasSameProductID(InputDeviceInfo deviceInfo)
 {
     return(Info.HasSameProductID(deviceInfo));
 }
コード例 #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;
        }
コード例 #19
0
 public bool HasSameVendorID(InputDeviceInfo deviceInfo)
 {
     return(vendorID == deviceInfo.vendorID);
 }
コード例 #20
0
ファイル: Native.cs プロジェクト: JeffAntonelli/MetalStormNul
 public static extern bool GetDeviceInfo(DeviceHandle handle, out InputDeviceInfo deviceInfo);
コード例 #21
0
 public bool HasSameVersionNumber(InputDeviceInfo deviceInfo)
 {
     return(Info.HasSameVersionNumber(deviceInfo));
 }
コード例 #22
0
ファイル: Native.cs プロジェクト: JeffAntonelli/MetalStormNul
 public static bool GetDeviceInfo(DeviceHandle handle, out InputDeviceInfo deviceInfo)
 {
     deviceInfo = new InputDeviceInfo(); return(false);
 }
コード例 #23
0
 public bool HasSameSerialNumber(InputDeviceInfo deviceInfo)
 {
     return(Info.HasSameSerialNumber(deviceInfo));
 }