I'm trying to find out if it's possible to use the native HoloLens file picker in an immersive Unity app. I've tested 2 samples so far that both work, but only if they're using a UI window for the entire app. I've been following other people's SO posts and created this:
using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
#if WINDOWS_UWP
using System;
using System.Threading.Tasks;
using Windows.Storage;
using Windows.System;
using System.Threading.Tasks;
using Windows.Storage.Streams;
using Windows.Storage.Pickers;
#endif
...
void Start()
{
#if WINDOWS_UWP
SelectJSON();
#endif
}
#if WINDOWS_UWP
void SelectJSON()
{
UnityEngine.WSA.Application.InvokeOnUIThread(async () =>
{
debug.text = "starting filePicker";
var filepicker = new FileOpenPicker();
filepicker.FileTypeFilter.Add(".json");
debug.text = "waiting for single file";
var file = await filepicker.PickSingleFileAsync();
UnityEngine.WSA.Application.InvokeOnAppThread(() =>
{
debug.text = "about to read data";
ReadData(file);
}, false);
}, false);
}
#endif
In my app, I get to the 'new FileOpenPicker()' part, and that's where the code hangs. I believe that the app is trying to open the file explorer window, but since I'm in an immersive Unity app, it just hangs there since there's no response from the user. I've put in a try/catch statement previously, but there weren't any errors or exceptions. I have tried various settings in Unity, like Default FullScreen or Run In Background, but none of those did anything. Has anyone got the native FilePicker to work in their Unity app or can tell me what I'm doing wrong?