Yes itâs the real native file browser from Windows and Mac Windows: dragable and resizable Mac: resizable but not dragable (because I made it attached to the top of the window, see screenshot below)
(The blur in the background is not a result of opening FileBrowserNative, I just edited the screenshot to hide something Iâm working on )
It seems to work very nicely so far.
However, I am facing some problems using your onDone action. It seems that many operations are not allowed here because the action is invoked from another thread (verified by looking at your source code). For example I cannot save to PlayerPrefs here or access gameObjects without throwing an exception (e.g. âget_gameObject can only be called from the main thread.â)
Could you move the invocation of the onDone action to the main thread somehow or are there other workarounds for this problem? Then I think your plug-in would be perfect.
Thanks a lot!
Edit:
Also I have problems setting the starting path of the browser. It does not seem to accept special paths like Application.streamingAssetsPath or strings like "D:"⌠How can I use it correctly? So far it only works with the Environment.Special folders for me.
This is a much needed feature for some types of Unity project!
How does it work technically - does it run a separate exe that creates the file browser window and then communicates back to the main app?
In order for this to work, youâll have to use a Dispatcher to run something on the main frame whenever possible. Because FileBrowser (on Windows) is launched calling a FileBrowser.exe via Process.Start(), I launch that in a thread, otherwise it blocks the entire game window. And so youâre not on the main Unity thread, and canât do normal actions.
Itâs real easy to use
Instead of directly calling your code like : MyMethod();
You just do : Dispatcher.Invoke(MyMethod); or Dispatcher.Invoke(() => { myCodeHere⌠});
Iâll add that to the readme and the demo script, thanks!
On Mac, it uses native plugins, that is some Objective-C code, compiled into a bundle and used/called directly from Unity.
On Windows, at first I wanted to make a DLL that does all the work. But in order to use the FileBrowser UI weâre used to, you have to target at least .NET 4.5 when creating the DLL. Which is not compatible and wonât load in UnityâŚ
So youâll have to target .NET 3.5. But when youâre doing that, C# will use an old, ugly UI for the FIleBrowser:
So yes, as you said. I build a FileBrowser.exe file (with .NET 4.5), place it in the StreamingAssets folder (to be able to find/load it at runtime in a build), and communicates back to the main app by reading the return value of the Process.Start method (see FileBrowserWindows.cs for that).
Thanks a lot for this too
Youâre right, thereâs an issue with startingDirectory!
But it only happens if the path you specify in startingDirectory contains / instead of
So for now, try doing yourStartingDirectory.Replace(â/â, @"") for now, and Iâll fix that for the next version
Thanks for the help with the dispatcher! Works now.
I did that and it works without problems for most paths. Root paths of volumes however produce problems even though I verified that they are formatted with backslash (e.g. "D:").
NativeFileBrowser 1.0.2 is now available on the Asset Store!
FIX: Windows: Fix startingDirectory not working if the path contained / instead of .
You can now safely use paths with either / or .
FIX: Windows: Fixed possible issue because result return was not Trim(),
NEW: Added documentation on how to call Unity main thread methods in the FileBrowser callback.
See the section called: âFix âAction invoked from another threadââ,
NEW: Added FAQ âWhy are you using a .exe file on Windows?â.
This is seems to work great, however, in full screen mode Unity gets minimized. This is sort of ok if Unity gets maximized again after file or folder selection. My two questions are:
Can we prevent Unity from being minimized when the file dialog is opened?
If we canât prevent Unity from minimizing, can we have Unity maximized again after the file dialog is closed?
I donât think I can prevent that. As I told you in an email, we call an external process to open the Native File Browser, and we canât have two processes at the same time in fullscreen mode. Weâll have to wait for Unity to update .NET to 4.5 to be able to hopefully open the File Browser without leaving the fullscreen mode.