简体   繁体   中英

Using OneDrive filePicker to access data

I'm trying to develop a Unity application on Hololens which needs to instantiate some 3D models at runtime.

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.

I've read Trouble with FilePickers in Unity Hololens development , Filepicker for Hololens: List available filepickers? and App to app interactions - File pickers .

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.

I don't understand how I can register my app to OneDrive's fileOpenPicker in order to access OneDrive app directory.

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

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.

To pick a file you'll want to use

WSANativeFilePicker.PickSingleFile("Select", WSAPickerViewMode.Thumbnail, WSAPickerLocationId.PicturesLibrary, new[] { ".png", ".jpg" }, result =>
{
    if (result != null)
    {
        byte[] fileBytes = result.ReadBytes();
        string fileString = result.ReadText();
    }
});

And to save a file

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");
    }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM