- Home /
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!
Answer by CHPedersen · Jun 28, 2011 at 12:51 PM
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:
http://answers.unity3d.com/questions/14869/how-to-open-a-windows-file-open-or-save-dialog-wit.html
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:
http://www.unifycommunity.com/wiki/index.php?title=ImprovedFileBrowser
I've used his with great results, and modyfied it to make it into a SaveFile-dialog, too.
Thanks for your response. I was thinking that it would be a hassle trying to take this route so I think I might just implement the custom file browser that I have worked on. I might even try out that ImprovedFileBrowser. Thanks again!
Answer by PygmyMonkey · Aug 05, 2016 at 10:52 AM
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: https://www.assetstore.unity3d.com/en/#!/content/68064
I've been searching for a way to do that for more than a year... and finally found how to do it :)
Your answer
Follow this Question
Related Questions
file browser error 1 Answer
How can I have the user chose a filesave location for a c document? 0 Answers
Hide hidden directories in file browser. 1 Answer
how to solve null reference on file browser script 1 Answer
File browser 0 Answers