问题描述
我正在尝试在Hololens上开发一个Unity应用程序,该应用程序需要在运行时实例化一些3D模型.
I'm trying to develop a Unity application on Hololens which needs to instantiate some 3D models at runtime.
我当时在考虑使用OneDrive来存储统一的AssetBundle并在需要时加载,只需使用本地路径即可.我面临的问题是Hololens具有不同的文件系统结构,而UWP应用程序只能访问某些目录.
I was thinking of using OneDrive to store unity AssetBundle and load when I need, simply using the local path.The problem that I'm facing is that Hololens has a different file system structure and UWP application can access only certain directories.
我已阅读 Unity Hololens开发中FilePickers的问题, Hololens的文件选择器:列出可用的文件选择器吗?和应用程序与应用程序的交互-文件选择器.
我了解到,要打开OneDrive目录,我需要在Hololens上安装OneDrive应用程序,然后将我的Unity应用程序注册到OneDrive的 fileOpenPicker
合同中,但我不知道该怎么做这.在普通的UWP应用程序中,我不需要使用精确的文件选择器,因此不会出现此问题.
I've understood that in order to open the OneDrive directory I need to install OneDrive App on Hololens and then register my Unity application to OneDrive's fileOpenPicker
contracts but I can't figure out how to do this.In a common UWP application I don't need to use a precise file picker so I don't have this issue.
我不知道如何将我的应用程序注册到OneDrive的 fileOpenPicker
以便访问OneDrive应用程序目录.
I don't understand how I can register my app to OneDrive's fileOpenPicker
in order to access OneDrive app directory.
推荐答案
如果您不打算开源代码,则可以为此使用Clayton的Windows Store Native资产: https://assetstore.unity.com/packages/tools/integration/windows-store-native-54715
If you're not planning to open-source your code, you can use Clayton's Windows Store Native asset for this: https://assetstore.unity.com/packages/tools/integration/windows-store-native-54715
使用最新的SDK,HoloLens OS和Unity版本与OneDrive一起使用时,我没有任何问题.自从几个月前Redstone的一次重大更新以来,它就得到了支持,这对我来说就是其中的一项行之有效"的事情-我在应用程序中拥有此资产,并且在更新之后,我可以从文件选择器访问OneDrive,而无需需要修改我的代码中的内容.这只是文件夹窗口左上方的下拉菜单.
I've had no issues having it work with OneDrive using the latest SDKs, HoloLens OS and Unity versions. It has been supported since that big Redstone update a few months ago and it's been one of those "it just works" things for me - I had this asset in my app, and after that update, I could access OneDrive from the file picker without needing to modify a thing in my code. It's just a dropdown menu on the top left of the file folder window.
该资产捆绑包中需要的脚本为:
The scripts you'll need from that asset bundle are:
- WSANativeFilePicker.cs
- WSAPickerLocationId.cs
- WSAPickerViewMode.cs
- WSAStorageFile.cs
他们在其网站此处提供了出色的文档.如果您需要他们,我发现他们的支持团队也非常迅速且乐于助人.
They provide great documentation on their website here. I've found their support team is also very quick and helpful if you need them.
要选择要使用的文件
WSANativeFilePicker.PickSingleFile("Select", WSAPickerViewMode.Thumbnail, WSAPickerLocationId.PicturesLibrary, new[] { ".png", ".jpg" }, result =>
{
if (result != null)
{
byte[] fileBytes = result.ReadBytes();
string fileString = result.ReadText();
}
});
并保存文件
WSANativeFilePicker.PickSaveFile("Save", ".jpg", "Test Image", WSAPickerLocationId.DocumentsLibrary, new List<KeyValuePair<string, IList<string>>>() { new KeyValuePair<string, IList<string>>("Image Files", new List<string>() { ".png", ".jpg" }) }, result =>
{
if (result != null)
{
result.WriteBytes(new byte[2]);
result.WriteText("Hello World");
}
});
这篇关于使用OneDrive filePicker访问数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!