unity 检测硬件usb 插拔操作

插件  LibUsbDotNet.dll   

网盘下载

链接: https://pan.baidu.com/s/1QoHa3sMZxAlckQJmF3mRGA 提取码: 7ybq 

安装 LibUsbDotNet_Setup.2.2.8.exe 

默认安装地址  C:\Program Files\LibUsbDotNet   中有各种usb操作c#示例

usb 插拔示例 C:\Program Files\LibUsbDotNet\Src\Test_DeviceNotify

unity应用此插件注意 api为 .net4.x 版本    在编辑器中应用时可能会报错

 

using LibUsbDotNet.DeviceNotify;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class LibUsb : MonoBehaviour
{
    private IDeviceNotifier devNotifier;
    public Text text;
    delegate void AppendNotifyDelegate(string s);
    void Start()
    {
        devNotifier = DeviceNotifier.OpenDeviceNotifier();

        devNotifier.OnDeviceNotify += onDevNotify;
    }

    private void onDevNotify(object sender, DeviceNotifyEventArgs e)
    {
        text.text = e.EventType.ToString();

    }
}

 

posted @ 2020-11-04 15:02  GP19  阅读(1213)  评论(0)    收藏  举报