void AddSystemDeviceProfile(NativeInputDeviceProfile deviceProfile) { if (deviceProfile.IsSupportedOnThisPlatform) { systemDeviceProfiles.Add(deviceProfile); } }
internal void Initialize(UInt32 deviceHandle, NativeDeviceInfo deviceInfo, NativeInputDeviceProfile deviceProfile) { Handle = deviceHandle; Info = deviceInfo; profile = deviceProfile; SortOrder = 1000 + (int)Handle; buttons = new Int16[Info.numButtons]; analogs = new Int16[Info.numAnalogs]; AnalogSnapshot = null; ClearInputState(); ClearControls(); if (IsKnown) { Name = profile.Name ?? Info.name; Meta = profile.Meta ?? Info.name; var analogMappingCount = profile.AnalogCount; for (int i = 0; i < analogMappingCount; i++) { var analogMapping = profile.AnalogMappings[i]; var analogControl = AddControl(analogMapping.Target, analogMapping.Handle); 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; } var buttonMappingCount = profile.ButtonCount; for (int i = 0; i < buttonMappingCount; i++) { var buttonMapping = profile.ButtonMappings[i]; var buttonControl = AddControl(buttonMapping.Target, buttonMapping.Handle); buttonControl.Passive = buttonMapping.Passive; } } else { Name = "Unknown Device"; Meta = Info.name; for (int i = 0; i < NumUnknownButtons; i++) { AddControl(InputControlType.Button0 + i, "Button " + i); } for (int i = 0; i < NumUnknownAnalogs; i++) { AddControl(InputControlType.Analog0 + i, "Analog " + i, 0.2f, 0.9f); } } skipUpdateFrames = 1; }
private void AddSystemDeviceProfiles() { string[] profiles = NativeInputDeviceProfileList.Profiles; foreach (string typeName in profiles) { NativeInputDeviceProfile deviceProfile = (NativeInputDeviceProfile)Activator.CreateInstance(Type.GetType(typeName)); AddSystemDeviceProfile(deviceProfile); } }
private void DetectDevice(uint deviceHandle, NativeDeviceInfo deviceInfo) { NativeInputDeviceProfile nativeInputDeviceProfile = null; nativeInputDeviceProfile = (nativeInputDeviceProfile ?? customDeviceProfiles.Find((NativeInputDeviceProfile profile) => profile.Matches(deviceInfo))); nativeInputDeviceProfile = (nativeInputDeviceProfile ?? systemDeviceProfiles.Find((NativeInputDeviceProfile profile) => profile.Matches(deviceInfo))); nativeInputDeviceProfile = (nativeInputDeviceProfile ?? customDeviceProfiles.Find((NativeInputDeviceProfile profile) => profile.LastResortMatches(deviceInfo))); nativeInputDeviceProfile = (nativeInputDeviceProfile ?? systemDeviceProfiles.Find((NativeInputDeviceProfile profile) => profile.LastResortMatches(deviceInfo))); NativeInputDevice nativeInputDevice = FindDetachedDevice(deviceInfo) ?? new NativeInputDevice(); nativeInputDevice.Initialize(deviceHandle, deviceInfo, nativeInputDeviceProfile); AttachDevice(nativeInputDevice); }
void DetectDevice(DeviceHandle deviceHandle, NativeDeviceInfo deviceInfo) { // Try to find a matching profile for this device. NativeInputDeviceProfile deviceProfile = null; 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. var device = FindDetachedDevice(deviceInfo) ?? new NativeInputDevice(); device.Initialize(deviceHandle, deviceInfo, deviceProfile); AttachDevice(device); }
internal void Initialize(uint deviceHandle, NativeDeviceInfo deviceInfo, NativeInputDeviceProfile deviceProfile) { Handle = deviceHandle; Info = deviceInfo; profile = deviceProfile; base.SortOrder = (int)(1000 + Handle); NativeDeviceInfo info = Info; numUnknownButtons = Math.Min((int)info.numButtons, 20); NativeDeviceInfo info2 = Info; numUnknownAnalogs = Math.Min((int)info2.numAnalogs, 20); NativeDeviceInfo info3 = Info; buttons = new short[info3.numButtons]; NativeDeviceInfo info4 = Info; analogs = new short[info4.numAnalogs]; base.AnalogSnapshot = null; ClearInputState(); ClearControls(); if (IsKnown) { string name = profile.Name; if (name == null) { NativeDeviceInfo info5 = Info; name = info5.name; } base.Name = name; string text = profile.Meta; if (text == null) { NativeDeviceInfo info6 = Info; text = info6.name; } base.Meta = text; base.DeviceClass = profile.DeviceClass; base.DeviceStyle = profile.DeviceStyle; int analogCount = profile.AnalogCount; for (int i = 0; i < analogCount; i++) { InputControlMapping inputControlMapping = profile.AnalogMappings[i]; InputControl inputControl = AddControl(inputControlMapping.Target, inputControlMapping.Handle); inputControl.Sensitivity = Mathf.Min(profile.Sensitivity, inputControlMapping.Sensitivity); inputControl.LowerDeadZone = Mathf.Max(profile.LowerDeadZone, inputControlMapping.LowerDeadZone); inputControl.UpperDeadZone = Mathf.Min(profile.UpperDeadZone, inputControlMapping.UpperDeadZone); inputControl.Raw = inputControlMapping.Raw; inputControl.Passive = inputControlMapping.Passive; } int buttonCount = profile.ButtonCount; for (int j = 0; j < buttonCount; j++) { InputControlMapping inputControlMapping2 = profile.ButtonMappings[j]; InputControl inputControl2 = AddControl(inputControlMapping2.Target, inputControlMapping2.Handle); inputControl2.Passive = inputControlMapping2.Passive; } } else { base.Name = "Unknown Device"; NativeDeviceInfo info7 = Info; base.Meta = info7.name; for (int k = 0; k < NumUnknownButtons; k++) { AddControl((InputControlType)(500 + k), "Button " + k); } for (int l = 0; l < NumUnknownAnalogs; l++) { AddControl((InputControlType)(400 + l), "Analog " + l, 0.2f, 0.9f); } } skipUpdateFrames = 1; }