File Navigation Interface

So I’ve noticed the WWW class allows me to load files into my game, specifically loading an image directly onto a texture. Now I’m trying to find if I can build a GUI that allows me to navigate directories on my machine.

For example, I have an image “flower.jpg” sitting on my desktop. When I run my game, I’d like to be able to use the interface to goto the desktop and select the specific file, then pass the ‘url’ for that directory to a WWW object.

long story short/tldr: Is the a way for the GUI class to navigate the directories of the host computer?

Yes, it involves programming a bunch of lines of GUI code. ;) Or you can get [UniFileBrowser][1]. To use it, just do something like function OnGUI () { if (GUILayout.Button("Open File")) SendMessage("OpenFileWindow"); } function OpenFile (filePath : String) { var www = new WWW("file://" + filePath); renderer.material.mainTexture = www.texture; } [1]: http://starscenesoftware.com/Utilities.html#UniFileBrowser

1 Answer

1

You could probably use the EditorUtility class to open a Mac/Windows “Open File” dialog to select the file. The OpenFilePanel function will return the path to the selected file.

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

That will only work in the editor.

Thanks for the response, this gives me a good direction to start searching. (also thanks for the second comment, i was just about to ask that question, heh)