• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by ignotuscaligo · Apr 04, 2012 at 06:12 PM · guifilenavigationdirectory

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?

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Eric5h5 · Apr 04, 2012 at 06:42 PM 0
Share

Yes, it involves programming a bunch of lines of GUI code. ;) Or you can get UniFileBrowser. To use it, just do something like

 function OnGUI () {
     if (GUILayout.Button("Open File")) Send$$anonymous$$essage("OpenFileWindow");
 }
 
 function OpenFile (filePath : String) {
     var www = new WWW("file://" + filePath);
     renderer.material.mainTexture = www.texture; 
 }

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by kromenak · Apr 04, 2012 at 06:24 PM

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

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Eric5h5 · Apr 04, 2012 at 06:26 PM 0
Share

That will only work in the editor.

avatar image ignotuscaligo · Apr 04, 2012 at 06:29 PM 0
Share

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)

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How to output a file to a single string? 1 Answer

Download Links from GUI 2 Answers

How do I load a config (.cfg) or ini file? 2 Answers

Problem Reading A Text File 2 Answers

Creating a Directory in "My Documents" 2 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges