【发布时间】:2018-05-15 18:08:04
【问题描述】:
正如标题所述,我有一个适用于 Samsung Gear VR 的 Unity3D 应用程序,我希望能够检测何时有东西插入了 Gear 的 USB-C 端口。
在这里和其他相关论坛上搜索我可能已经找到了一种使用 Android Intents (ACTION_USB_DEVICE_ATTACHED) 的方法,但它看起来不像是 Unity 应用程序的选项(或者至少我不能找到一种使用它的方法,Unity 论坛似乎又关闭了)。
现在,我基本上跳过了“检测”步骤,而是在适当的场景中在后台运行一个枚举器,检查 Android 上“/storage”中的任何文件夹是否具有名为“测试“。Android似乎将来自外部驱动器的数据存储在“/ storage”中,文件夹名称看似随机的字母数字字符,所以我发现确定它是否是我正在寻找的驱动器的唯一方法是检查 1 层深度以找到“测试”文件夹。
IEnumerator DirectoryReadTest()
{
Debug.Log("Running DirectoryReadTest...");
while (true)
{
DirectoryInfo info = new DirectoryInfo("/storage");
DirectoryInfo[] subs = info.GetDirectories();
foreach (DirectoryInfo d in subs)
{
Debug.Log("Directory: " + d.Name);
DirectoryInfo[] subd = d.GetDirectories("test");
if (subd.Length > 0)
{
Debug.Log("Found a test directory in storage.");
usbExternalDirectory = subd[0];
break;
}
}
yield return null;
}
}
这个方法目前有效,但意味着我必须让这个进程在后台不断运行,所以效率不是很高。我似乎无法过滤掉正在寻找诸如“如何判断 android 手机是否插入计算机 USB”之类的谷歌结果,所以我将不胜感激任何正确方向的指针。
【问题讨论】:
标签: c# android unity3d gear-vr