Native File Browser - Use native File Browser on Mac and Windows!

Native File Browser
Use native File Browser on Mac and Windows!

Native File Browser provides an easy way to use the native File Browser on Mac and Windows.

Features

  • Open File Panel / Open Multiple Files Panel,
  • Open Folder Panel / Open Multiple Folders Panel,
  • Save File Panel,
  • Define a starting directory,
  • Define the file extensions to be used,
  • Clean and documented C# code.

Links



2 Likes

Edit: Now available on the Asset Store :slight_smile:

1 Like

Nice!
Does it behave like the usual Filebrowser as we´re used to, e.g is it dragable and resizable?

Yes it’s the real native file browser from Windows and Mac :slight_smile:
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 :smile:)

Nice :slight_smile:
Is it possible to trial?

Well, there’s no way to do that with the Asset Store :confused:
I’ll PM you to see what we can do.

1 Like

Just bought it:
It works like a charm and is exactly what I have been waiting for! :slight_smile:

1 Like

Hey!

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?

Hey,
Thanks for pointing this out!

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.

So you’ll have to use a Dispatcher. You can find one right here:
https://github.com/nickgravelyn/UnityToolbag/tree/master/Dispatcher
With some explanations on the blog post here:
http://blog.theknightsofunity.com/using-threads-unity/

It’s real easy to use :slight_smile:
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!

Hello!

  • 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 :slight_smile:
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 :slight_smile:

NativeFileBrowser 1.0.1 is now available on the Asset Store :slight_smile:

  • FIX: Fixed Native File Browser not working when building with architecture x86 on Mac. It now works with any architecture (Universal, x86 and x64)
  • NEW: The FileBrowser on Mac now always display the “Create folder” button

Thanks for the help with the dispatcher! Works now. :slight_smile:

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:").

Yes, I also fixed this, don’t worry :slight_smile:
If you can’t wait for the update, you should be able to use “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?”.

NativeFileBrowser 1.0.3 is now available on the Asset Store!

  • FIX: Windows: Fixed issue happening when a LOT of files were selected.

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:

  1. Can we prevent Unity from being minimized when the file dialog is opened?
  2. If we can’t prevent Unity from minimizing, can we have Unity maximized again after the file dialog is closed?

Hey :slight_smile:

  1. 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.

  2. Good idea, I’ll try to take a look into it!

  1. This addon works very well!
  2. Yes, Fullscreen without minimize unity wold be nice.
  3. It seems you can’t open files with browsing Network. It works only with connected Network Drives.
  4. WebGL support would be nice :slight_smile: I currently use jslib’s