Open Windows Explorer.

Is there a way for a user to click on a button in-game and have a window pop up like Windows Explorer (or Finder for Mac OS) where you can navigate through directories and open a selected file? I have written code for a customized File Browser but I want to use the built in file browser for windows/mac. Any help would be greatly appreciated Thanks!

There is always a way, but what you’re asking makes your application platform specific. Unity was built for the exact opposite, (hence its name), so accessing platform specific material such as the windowing system requires you to grab the dll’s that are native to that particular operating system, and call the external functions that manipulate the window system on that platform.

I haven’t looked deeply into this myself because frankly, it’s too high effort to be worth it. But the functions that you would require on Windows are probably located in User32.dll. There is a list of Win32 API lowlevel functions that reside in User32.dll here:

http://www.webtropy.com/articles/art9-2.asp?lib=user32.dll

As you can see, many of them operate on windows, like moving them around, closing them, finding them based on their caption, etc. etc. But they all require you to handle unmanaged memory, and the variables become hairy, the code hard to read and hard to debug.

And then if you do manage to get this working, you’d have to start the same research all over again when you want to do the same on a Mac, because it has a different window system, and a different set of external functions for you to manage and wrap your code around. All in all, there is no wrapped, catch-all functionality in Unity that does this for you, for platform independency reasons.

There is an editor function:

http://unity3d.com/support/documentation/ScriptReference/EditorUtility.OpenFilePanel.html

That does what you want in the editor, but that won’t work with the final build so probably won’t be of much use for you. There are also a few posts with people who’ve used the .Net Windows Forms library to try and open file dialogs, such as this one:

But it seems to have varying degrees of success. If I were you, I’d go with some file browser made in unity itself. That seems to be the best bet. Daniel Brauer has written one here:

I’ve used his with great results, and modyfied it to make it into a SaveFile-dialog, too.

Hello,

I made an Asset to use the Native File Browser from Windows and Mac in Unity at runtime, it’s available on the Asset Store: Unity Asset Store - The Best Assets for Game Making

I’ve been searching for a way to do that for more than a year… and finally found how to do it :slight_smile: