Search Unity

UWP - File Picker problems

Discussion in 'Windows' started by meister-hubert, Mar 30, 2020.

  1. meister-hubert

    meister-hubert

    Joined:
    Jan 16, 2020
    Posts:
    1
    Hi,
    I am building a VR App for scientific data visualization (UWP-WMR) and I want to read in .csv-files.
    I found a script for this and it works well. I also downloaded a free Filepicker-Asset (https://assetstore.unity.com/packages/tools/input-management/simple-file-browser-98451) which works in the Unity project. When I export the game to UWP however, the filebrowser freezes and doesn't show anything.
    So I searched a lot and found two things: UWP is very restrictive when it comes to file access permission (https://docs.microsoft.com/en-us/windows/uwp/files/file-access-permissions).
    I am not sure if this means I can still see filepaths to restricted folders. So if I have permission to the download-folder, can I still navigate there through restricted filepaths? Do I see files, that I can't access or are they "hidden" in the browser?

    The next thing is the file browser itself. I probably need an async method? I looked into Windows.Storage (https://docs.microsoft.com/en-us/windows/uwp/files/quickstart-using-file-and-folder-pickers), but the C# unity-script tells me "using Windows.*" doesnt exist. So instead i looked into UnityEngine.Windows.File & Directory, but apparently a lot of the System.IO.* functionality is missing, such as .getParent().

    The desired outcome is this: I press a button and a canvas with a filebrowser pops up. I navigate to the .csv file, click it and the filepath is handed over to the plot-method.
    So, how do I do this?

    Unity 2018.4 LTS, .NET 4.X, IL2CCP backend

    I am pretty new to C#, so I would appreciate any help.
    Thank you!
     
    Last edited: Mar 30, 2020
  2. timke

    timke

    Joined:
    Nov 30, 2017
    Posts:
    407
    I recommend you start with Microsoft's UWP samples to first learn how to develop for that platform:
    https://github.com/Microsoft/Windows-universal-samples.
    Here's a link specifically for opening a FilePicker: https://github.com/microsoft/Windows-universal-samples/tree/master/Samples/FilePicker

    WinRT APIs aren't available within the Editor context, and so any code that calls into these APIs must be enclosed in #ifdefs; see Platform dependent compilation. Note there are several #defines for UWP: UNITY_WSA, UNITY_WINRT, UNITY_UWP, etc. (for legacy reason) but in your case they all mean the same thing.

    Please refer to the Unity documentation on developing for Universal Windows Platform: https://docs.unity3d.com/2018.4/Documentation/Manual/windowsstore-gettingstarted.html