コード例 #1
0
        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);
        }
コード例 #2
0
        public override void Update(ulong updateTick, float deltaTime)
        {
            IntPtr source;
            int    num = Native.GetDeviceEvents(out source);

            if (num <= 0)
            {
                return;
            }
            Utility.ArrayExpand(ref deviceEvents, num);
            MarshalUtility.Copy(source, deviceEvents, num);
            int  num2 = 0;
            uint num3 = deviceEvents[num2++];

            for (int i = 0; i < num3; i++)
            {
                uint          num4          = deviceEvents[num2++];
                StringBuilder stringBuilder = new StringBuilder(256);
                stringBuilder.Append("Attached native device with handle " + num4 + ":\n");
                if (Native.GetDeviceInfo(num4, out NativeDeviceInfo deviceInfo))
                {
                    stringBuilder.AppendFormat("Name: {0}\n", deviceInfo.name);
                    stringBuilder.AppendFormat("Driver Type: {0}\n", deviceInfo.driverType);
                    stringBuilder.AppendFormat("Location ID: {0}\n", deviceInfo.location);
                    stringBuilder.AppendFormat("Serial Number: {0}\n", deviceInfo.serialNumber);
                    stringBuilder.AppendFormat("Vendor ID: 0x{0:x}\n", deviceInfo.vendorID);
                    stringBuilder.AppendFormat("Product ID: 0x{0:x}\n", deviceInfo.productID);
                    stringBuilder.AppendFormat("Version Number: 0x{0:x}\n", deviceInfo.versionNumber);
                    stringBuilder.AppendFormat("Buttons: {0}\n", deviceInfo.numButtons);
                    stringBuilder.AppendFormat("Analogs: {0}\n", deviceInfo.numAnalogs);
                    DetectDevice(num4, deviceInfo);
                }
                Logger.LogInfo(stringBuilder.ToString());
            }
            uint num5 = deviceEvents[num2++];

            for (int j = 0; j < num5; j++)
            {
                uint num6 = deviceEvents[num2++];
                Logger.LogInfo("Detached native device with handle " + num6 + ":");
                NativeInputDevice nativeInputDevice = FindAttachedDevice(num6);
                if (nativeInputDevice != null)
                {
                    DetachDevice(nativeInputDevice);
                }
                else
                {
                    Logger.LogWarning("Couldn't find device to detach with handle: " + num6);
                }
            }
        }
コード例 #3
0
        private NativeInputDevice FindAttachedDevice(uint deviceHandle)
        {
            int count = attachedDevices.Count;

            for (int i = 0; i < count; i++)
            {
                NativeInputDevice nativeInputDevice = attachedDevices[i];
                if (nativeInputDevice.Handle == deviceHandle)
                {
                    return(nativeInputDevice);
                }
            }
            return(null);
        }
コード例 #4
0
        private static NativeInputDevice SystemFindDetachedDevice(NativeDeviceInfo deviceInfo, ReadOnlyCollection <NativeInputDevice> detachedDevices)
        {
            int count = detachedDevices.Count;

            for (int i = 0; i < count; i++)
            {
                NativeInputDevice nativeInputDevice = detachedDevices[i];
                if (nativeInputDevice.Info.HasSameVendorID(deviceInfo) && nativeInputDevice.Info.HasSameProductID(deviceInfo) && nativeInputDevice.Info.HasSameSerialNumber(deviceInfo))
                {
                    return(nativeInputDevice);
                }
            }
            for (int j = 0; j < count; j++)
            {
                NativeInputDevice nativeInputDevice2 = detachedDevices[j];
                if (nativeInputDevice2.Info.HasSameVendorID(deviceInfo) && nativeInputDevice2.Info.HasSameProductID(deviceInfo) && nativeInputDevice2.Info.HasSameLocation(deviceInfo))
                {
                    return(nativeInputDevice2);
                }
            }
            for (int k = 0; k < count; k++)
            {
                NativeInputDevice nativeInputDevice3 = detachedDevices[k];
                if (nativeInputDevice3.Info.HasSameVendorID(deviceInfo) && nativeInputDevice3.Info.HasSameProductID(deviceInfo) && nativeInputDevice3.Info.HasSameVersionNumber(deviceInfo))
                {
                    return(nativeInputDevice3);
                }
            }
            for (int l = 0; l < count; l++)
            {
                NativeInputDevice nativeInputDevice4 = detachedDevices[l];
                if (nativeInputDevice4.Info.HasSameLocation(deviceInfo))
                {
                    return(nativeInputDevice4);
                }
            }
            return(null);
        }
コード例 #5
0
        private void OnGUI()
        {
            int num  = Mathf.FloorToInt(Screen.width / Mathf.Max(1, InputManager.Devices.Count));
            int num2 = 10;
            int num3 = 10;
            int num4 = 15;

            GUI.skin.font = font;
            SetColor(Color.white);
            string str = "Devices:";

            str = str + " (Platform: " + InputManager.Platform + ")";
            str = str + " " + InputManager.ActiveDevice.Direction.Vector;
            if (isPaused)
            {
                SetColor(Color.red);
                str = "+++ PAUSED +++";
            }
            GUI.Label(new Rect(num2, num3, num2 + num, num3 + 10), str, style);
            SetColor(Color.white);
            foreach (InputDevice device in InputManager.Devices)
            {
                bool  flag  = InputManager.ActiveDevice == device;
                Color color = (!flag) ? Color.white : Color.yellow;
                num3 = 35;
                if (device.IsUnknown)
                {
                    SetColor(Color.red);
                    GUI.Label(new Rect(num2, num3, num2 + num, num3 + 10), "Unknown Device", style);
                }
                else
                {
                    SetColor(color);
                    GUI.Label(new Rect(num2, num3, num2 + num, num3 + 10), device.Name, style);
                }
                num3 += num4;
                SetColor(color);
                if (device.IsUnknown)
                {
                    GUI.Label(new Rect(num2, num3, num2 + num, num3 + 10), device.Meta, style);
                    num3 += num4;
                }
                GUI.Label(new Rect(num2, num3, num2 + num, num3 + 10), "Style: " + device.DeviceStyle, style);
                num3 += num4;
                GUI.Label(new Rect(num2, num3, num2 + num, num3 + 10), "GUID: " + device.GUID, style);
                num3 += num4;
                GUI.Label(new Rect(num2, num3, num2 + num, num3 + 10), "SortOrder: " + device.SortOrder, style);
                num3 += num4;
                GUI.Label(new Rect(num2, num3, num2 + num, num3 + 10), "LastChangeTick: " + device.LastChangeTick, style);
                num3 += num4;
                NativeInputDevice nativeInputDevice = device as NativeInputDevice;
                if (nativeInputDevice != null)
                {
                    NativeDeviceInfo info  = nativeInputDevice.Info;
                    object           arg   = info.vendorID;
                    NativeDeviceInfo info2 = nativeInputDevice.Info;
                    object           arg2  = info2.productID;
                    NativeDeviceInfo info3 = nativeInputDevice.Info;
                    string           text  = $"VID = 0x{arg:x}, PID = 0x{arg2:x}, VER = 0x{info3.versionNumber:x}";
                    GUI.Label(new Rect(num2, num3, num2 + num, num3 + 10), text, style);
                    num3 += num4;
                }
                num3 += num4;
                foreach (InputControl control in device.Controls)
                {
                    if (control != null && !Utility.TargetIsAlias(control.Target))
                    {
                        string arg3 = (!device.IsKnown) ? control.Handle : $"{control.Target} ({control.Handle})";
                        SetColor((!control.State) ? color : Color.green);
                        string text2 = string.Format("{0} {1}", arg3, (!control.State) ? string.Empty : ("= " + control.Value));
                        GUI.Label(new Rect(num2, num3, num2 + num, num3 + 10), text2, style);
                        num3 += num4;
                    }
                }
                num3 += num4;
                color = ((!flag) ? Color.white : new Color(1f, 0.7f, 0.2f));
                if (device.IsKnown)
                {
                    InputControl command = device.Command;
                    SetColor((!command.State) ? color : Color.green);
                    string text3 = string.Format("{0} {1}", "Command", (!command.State) ? string.Empty : ("= " + command.Value));
                    GUI.Label(new Rect(num2, num3, num2 + num, num3 + 10), text3, style);
                    num3   += num4;
                    command = device.LeftStickX;
                    SetColor((!command.State) ? color : Color.green);
                    text3 = string.Format("{0} {1}", "Left Stick X", (!command.State) ? string.Empty : ("= " + command.Value));
                    GUI.Label(new Rect(num2, num3, num2 + num, num3 + 10), text3, style);
                    num3   += num4;
                    command = device.LeftStickY;
                    SetColor((!command.State) ? color : Color.green);
                    text3 = string.Format("{0} {1}", "Left Stick Y", (!command.State) ? string.Empty : ("= " + command.Value));
                    GUI.Label(new Rect(num2, num3, num2 + num, num3 + 10), text3, style);
                    num3 += num4;
                    SetColor((!device.LeftStick.State) ? color : Color.green);
                    text3 = string.Format("{0} {1}", "Left Stick A", (!device.LeftStick.State) ? string.Empty : ("= " + device.LeftStick.Angle));
                    GUI.Label(new Rect(num2, num3, num2 + num, num3 + 10), text3, style);
                    num3   += num4;
                    command = device.RightStickX;
                    SetColor((!command.State) ? color : Color.green);
                    text3 = string.Format("{0} {1}", "Right Stick X", (!command.State) ? string.Empty : ("= " + command.Value));
                    GUI.Label(new Rect(num2, num3, num2 + num, num3 + 10), text3, style);
                    num3   += num4;
                    command = device.RightStickY;
                    SetColor((!command.State) ? color : Color.green);
                    text3 = string.Format("{0} {1}", "Right Stick Y", (!command.State) ? string.Empty : ("= " + command.Value));
                    GUI.Label(new Rect(num2, num3, num2 + num, num3 + 10), text3, style);
                    num3 += num4;
                    SetColor((!device.RightStick.State) ? color : Color.green);
                    text3 = string.Format("{0} {1}", "Right Stick A", (!device.RightStick.State) ? string.Empty : ("= " + device.RightStick.Angle));
                    GUI.Label(new Rect(num2, num3, num2 + num, num3 + 10), text3, style);
                    num3   += num4;
                    command = device.DPadX;
                    SetColor((!command.State) ? color : Color.green);
                    text3 = string.Format("{0} {1}", "DPad X", (!command.State) ? string.Empty : ("= " + command.Value));
                    GUI.Label(new Rect(num2, num3, num2 + num, num3 + 10), text3, style);
                    num3   += num4;
                    command = device.DPadY;
                    SetColor((!command.State) ? color : Color.green);
                    text3 = string.Format("{0} {1}", "DPad Y", (!command.State) ? string.Empty : ("= " + command.Value));
                    GUI.Label(new Rect(num2, num3, num2 + num, num3 + 10), text3, style);
                    num3 += num4;
                }
                SetColor(Color.cyan);
                InputControl anyButton = device.AnyButton;
                if ((bool)anyButton)
                {
                    GUI.Label(new Rect(num2, num3, num2 + num, num3 + 10), "AnyButton = " + anyButton.Handle, style);
                }
                num2 += num;
            }
            Color[] array = new Color[3]
            {
                Color.gray,
                Color.yellow,
                Color.white
            };
            SetColor(Color.white);
            num2 = 10;
            num3 = Screen.height - (10 + num4);
            for (int num5 = logMessages.Count - 1; num5 >= 0; num5--)
            {
                LogMessage logMessage = logMessages[num5];
                if (logMessage.type != 0)
                {
                    SetColor(array[(int)logMessage.type]);
                    string[] array2 = logMessage.text.Split('\n');
                    foreach (string text4 in array2)
                    {
                        GUI.Label(new Rect(num2, num3, Screen.width, num3 + 10), text4, style);
                        num3 -= num4;
                    }
                }
            }
        }
コード例 #6
0
 void DetachDevice(NativeInputDevice device)
 {
     attachedDevices.Remove(device);
     detachedDevices.Add(device);
     InputManager.DetachDevice(device);
 }
コード例 #7
0
 void AttachDevice(NativeInputDevice device)
 {
     detachedDevices.Remove(device);
     attachedDevices.Add(device);
     InputManager.AttachDevice(device);
 }