Search Unity

UniFileBrowser - runtime file browsing

Discussion in 'Assets and Asset Store' started by Eric5h5, May 4, 2013.

  1. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    This has actually been around for a while, but I just released version 2.2 and it occurred to me that I didn't have a topic specifically for it. So here it is! UniFileBrowser is a runtime file-browser. It's not a plugin, allows for lot of customization, and works on most platforms. Source code is included; it works with Unityscript and C# (and probably Boo though I haven't tested that). Available on my site and the Unity asset store.



    Feature highlights:
    • Can be skinned as desired, and the various GUI elements can be resized easily. Includes two demo GUISkins, as shown above.
    • Actions for opening and saving files, and opening folders.
    • Can filter files by extension, including multiple extensions. (e.g., if you want to list all .jpg and .png files.)
    • Can automatically add an extension when saving.
    • Can allow or disallow navigation to other folders.
    • Full keyboard control.
    • Can use multi-file selection, including shift for selecting a range of files and command/ctrl for adding/removing individual files.
    • Can have a delete button. (Destructive! Limiting to the initial folder is strongly recommended in this case.)
    • Can show volumes/hard drives.
    • When saving, can prevent input of "illegal" characters that are not allowed in file names in common file systems.
    • Can allow or disallow window dragging and resizing.
    • Includes detailed documentation.

    There are a number of functions you can use, including:
    • OpenFileWindow: causes the file browser window to open, allowing the user to select a file. Uses a delegate so that a function you specify is called with the selected path. (Yes, delegates work with Unityscript.)
    • SaveFileWindow: as above, for saving files.
    • OpenFolderWindow: as above, for selecting folders.
    • CloseFileWindow: closes the file browser window.
    • SetPath: sets the path that the file browser window opens to by default.
    • SetWindowTitle: used for custom window titles.
    • FileWindowOpen: true or false depending on if the window is open.
    • GetFileWindowRect: returns the current rect for the window.
    • SendWindowCloseMessage: calls a function when the window is closed.
    • SendWindowChangeMessage: calls a function if the window is moved.
    • SetFileExtensions: sets the file filtering extensions at runtime.

    Limitations:
    • No loading/saving game code is included. It's a file-browser only. Loading and saving games is extremely game-dependent, so you'll need your own code for that.
    • While it works on mobile, it's currently limited to the built-in behavior for OnGUI code. So it's functional but doesn't have an ideal touch interface for scrolling and so on.
    • Since Unity doesn't allow external file access in the web browser, it won't work on that platform.

    If you have any questions, find any bugs (never! ;) ), or have any feature suggestions, post them here. If you bought from my site and don't have the latest version (currently 2.6.1), send me a PM with the address you used when buying. Update notices are sent out automatically for new versions, but you need to make sure you opt in to that (if you don't, then I can't send any update notices to you), and you might also want to check your spam folder.

    --Eric
     
    Meltdown likes this.
  2. Logiquefloue

    Logiquefloue

    Joined:
    Jun 6, 2013
    Posts:
    21
    Hello,

    PlayMaker I use because I do not know coding and I bought "UnitFileBrowser".

    I can not call functions UniFileBrowser.use.OpenFileWindow (OpenFileFunction) ... since PlayMaker.

    Unfortunately the example does not allow truly open files!
    Can you tell me how to make operational example or give me an example that open the file?


    thank you
     
  3. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    The point of UniFileBrowser is that it's a file browser, it's not a load/save system. It sends a string containing the file path to your functions (or an array of strings containing multiple file paths); what you do with that information totally depends on your game/app and what it does. Because of that, I can't write any code that actually opens files for you, so you'll need to write it yourself or find a third-party save system. You'll have to ask the creators of PlayMaker about PlayMaker support.

    --Eric
     
  4. Logiquefloue

    Logiquefloue

    Joined:
    Jun 6, 2013
    Posts:
    21
    Thank you for the quick response :)

    I'm sorry to ask "dumb" question, but I am new to the computer world ...

    I want to open an excel file from my game .. So if I understand correctly, your application just lets me browse to find my file ... I need another application (such as "Easy save", "save game" for example) that really opens my excel file. This is correct?

    thank you
     
  5. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    That is indeed correct. See here about opening Excel files.

    --Eric
     
  6. Logiquefloue

    Logiquefloue

    Joined:
    Jun 6, 2013
    Posts:
    21
    The link explains how to open an excel file in Unity ... But I do not want to do that.
    I just want to create a shortcut (a button) in my game that I opened the excel software. That way the player does not have to leave the game to go on his windows open excel file.
    This is possible in your opinion?

    Thank you very much.
     
  7. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
  8. Logiquefloue

    Logiquefloue

    Joined:
    Jun 6, 2013
    Posts:
    21
    Exactly, I want to launch Excel itself from my game
     
  9. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,462
    Is it possible to modify this to work with NGUI ?
     
  10. vrpostcard

    vrpostcard

    Joined:
    Feb 24, 2013
    Posts:
    33
    UniFileBrowser works with playmaker. I have successfully configured it to load textures from a directory and then apply them to a game object. I may be able to dig up the FSM actions if you are still interested.
     
  11. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I'm sure it's technically possible, but UniFileBrowser is heavily dependent on OnGUI code, so it would probably involve mostly rewriting it from scratch.

    --Eric
     
  12. Kragh

    Kragh

    Joined:
    Jan 22, 2008
    Posts:
    657
    I want to use the OpenFolderWindow, so I can browser to a folder (Where the user will then save some stuff). But... I had thought you had implemented some "Create folder" functionality. Do I miss it somewhere? I know it is easy to implement (And I will), but if I misunderstand something, or it is indeed already made, I would want to save the time making it myself ;)
     
  13. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    There's currently no functionality for that, sorry...I guess you just imagined it. ;)

    --Eric
     
  14. shwa

    shwa

    Joined:
    Apr 9, 2012
    Posts:
    461
    "so you'll need to write it yourself or find a third-party save system." Eric

    Hi Eric,
    Can you recommend a 3rd party save system?

    I'm looking into Easysave2. to do what i want to do (below), in conjunction with UnifileBrowser.

    EasySave2
    http://forum.unity3d.com/threads/91040-Easy-Save-Save-using-a-single-function!

    I bought UnifileBrowser a while ago. Recently updated it.

    OSX/WIN Standalone use in Unity 4:

    Am trying to figure out how to use it to allow a user to import an image from their desktop or hard drive,
    and have that image replace a texture that's already live in runtime.

    Basically, i've got a quasi 3d art gallery scene, and want the to user/player to be able to use it to see their own images in that gallery.

    thanks.
     
    Last edited: Nov 20, 2013
  15. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I'm not familiar with third-party save systems so I wouldn't be able to recommend one. For importing images, you can use the WWW class with a file:// prefix, or Texture2D.LoadImage. Note that Unity only loads PNG and JPG formats; for others you'd have to write your own importer.

    --Eric
     
  16. shwa

    shwa

    Joined:
    Apr 9, 2012
    Posts:
    461
    Thanks, Eric.

    I'll try and figure this out some more.
     
  17. shwa

    shwa

    Joined:
    Apr 9, 2012
    Posts:
    461
    Hi Eric,

    (Btw, i'm more designer/artist, than coder.)

    I bought EasySave2 and want to integrate UniFile with it to see if i can get a working solution.

    I've brought both of them into my current 3d gallery project. No code conflicts.
    Using OSX Unity 4 pro. Standalone. (Win standalone later.)

    Have got UniFile's example working in my 3d gallery.
    Both the Open and Open Folder buttons work:
    and display the name of the file i've chosen (the path to the file is not displayed),
    or the name of the folder i've chosen. (the path to the folder is displayed.)

    What i need next is to understand how i can access the path information to either a file or folder, which i can then use with EasySave2 to get my desired results.

    I hope i'm being clear.

    thanks.

    shwa
     
  18. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    The loading function you specify has the user-selected path passed to it as a string, so you can use the path with System.IO functions or whatever to do what you want with the file. I'm not familiar with EasySave2 or what its requirements are.

    --Eric
     
  19. shwa

    shwa

    Joined:
    Apr 9, 2012
    Posts:
    461
    Eric wrote :
    "It would be better if you posted that in a new topic since it's not related to UniFileBrowser, "

    You are right.
    Sorry about that.

    - shwa
     
    Last edited: Nov 26, 2013
  20. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    It would be better if you posted that in a new topic since it's not related to UniFileBrowser, although from what I remember Application.dataPath is inside the app bundle.

    --Eric
     
  21. shwa

    shwa

    Joined:
    Apr 9, 2012
    Posts:
    461
    "although from what I remember Application.dataPath is inside the app bundle."

    Doh.

    I'm losing my mind.
     
  22. derkoi

    derkoi

    Joined:
    Jul 3, 2012
    Posts:
    2,260
    Hi Eric,

    Is there a function that gets called when the user presses cancel? Thanks.
     
  23. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    There's a SendWindowCloseMessage function, which you could use to detect the cancel button since the open or save function would not be called in that case.

    --Eric
     
  24. dvulanov

    dvulanov

    Joined:
    Sep 23, 2013
    Posts:
    2
    Hey,

    I'm trying to use this package in 4.3 with C#. I get compiler errors:

    UnityProject/Assets/UniFileBrowser Assets/Demo/UniFileBrowserExample.cs(52,52): Error CS0584: Internal compiler error: Could not import type `CompilerGenerated.__UniFileBrowser_delegate$callable0$103_24__' from `Assembly-UnityScript-firstpass, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' (CS0584) (Assembly-CSharp)

    That said, even with these errors everything still runs and I can use the browser, so I'm not exactly sure what's going on. Has anyone seen this before?

    Thanks for any help,
    Dan
     
    Last edited: Dec 17, 2013
  25. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I haven't come across this...I did a search and this topic was the only result for something like that, so unfortunately I don't really have any advice.

    --Eric
     
  26. dvulanov

    dvulanov

    Joined:
    Sep 23, 2013
    Posts:
    2
    Ok, I'll see if I can figure something out.

    Thanks,
    Dan
     
  27. Kragh

    Kragh

    Joined:
    Jan 22, 2008
    Posts:
    657
    Hi Eric, I have problems with special letters. I'm danish, and so we have 3 special letters (æ, ø and å), which the uniFileBrowser doesn't seem to work with. I also had a problem with #. It is surely a problem with the version of UTF that is used...somewhere.
    Do you have any reason to think this is a problem with your product? I use the path string you deliver to me via the delegate, to open files using the www class. So it may also be here the problem arrises.
     
  28. tbreina

    tbreina

    Joined:
    Mar 11, 2013
    Posts:
    22
    Code (csharp):
    1.  
    2. private string _videofileName = "initial value";
    3.  
    4. private void OpenFile (string pathToFile)
    5. {
    6.                 _videofileName = "file:///" + pathToFile;
    7. }
    8.  
    9.  
    10. public void OnGUI ()
    11. {
    12.  
    13. if (GUI.Button (new Rect (20.0f, 10.0f, 80.0f, 30.0f), "File stream")) {
    14.     UniFileBrowser.use.OpenFileWindow (OpenFile);  // Open file browser
    15.  
    16.         Debug.Log("Selected = " + _videofileName);
    17.  
    18. }
    19. }
    20.  
    I've managed to get the code working, but am having a slight problem.

    When I execute the code snippet above, it correctly shows a button labeled "File Stream". When I click on the button, it correctly opens the UniFileBrowser and I can select a file name.

    However, the code prints the Debug log "initial value" rather than the filename selected by UniFileBrowser. If I click the button again, it uses the previous value I selected with the UniFileBrowser.

    So the Debug.Log section doesn't wait for UniFileBrowser to return with a value. It's always one iteration behind.

    Is there someway I can force the GUI to wait for the value from UniFileBrowser?

    Thanks.
    -Tony
     
  29. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I would assume that's the case, since I tested local files with the æ character and so on, and it worked as expected.

    No, OnGUI is immediate mode and can never be delayed in any way, same as Update. The purpose of using a delegate with UniFileBrowser is that the function is run when the user selects the file, so you don't have to worry about trying to make functions wait. You can put your Debug.Log code in the delegate instead of OnGUI.

    --Eric
     
  30. tbreina

    tbreina

    Joined:
    Mar 11, 2013
    Posts:
    22
    Ok. So in order to get button to use the file selected, I needed to add the code to the delegate function instead of after UniFileBrowser.use.OpenFileWindow (OpenFile).

    Here's the code that works:

    Code (csharp):
    1. private string _videofileName = "initial value";
    2.  
    3.  
    4.  
    5. private void OpenFile (string pathToFile)
    6.  
    7. {
    8.  
    9.                 _videofileName = "file:///" + pathToFile;
    10.  
    11. // THIS IS WHERE THE CODE GOES FOR DOING SOMETHING WITH WHATEVER FILENAME WAS SELECTED BY UniFileBrowser.
    12.  Debug.Log("Selected = " + _videofileName);
    13.  
    14. }
    15.  
    16.  
    17.  
    18.  
    19.  
    20. public void OnGUI ()
    21.  
    22. {
    23.  
    24.  
    25.  
    26. if (GUI.Button (new Rect (20.0f, 10.0f, 80.0f, 30.0f), "File stream")) {
    27.  
    28.     UniFileBrowser.use.OpenFileWindow (OpenFile);  // Open file browser
    29.    // DON"T PLACE THE FILENAME PROCESSING CODE HERE. IT WILL HAVE THE "initial value" and always be one iteration behind.
    30.  
    31. }
    32.  
    33. }
    I just wasn't understanding what the delegate function was doing. Now this makes more sense (and works properly).

    Thanks Eric.

    -Tony
     
    ColdMud likes this.
  31. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    973
    How would I change the filebrowser starting folder?

    So now it is Application.dataPath.

    I create a userFileFolder in my app with
    Code (csharp):
    1. System.IO.Directory.CreateDirectory(userFileFolder);
    and then would like it to become a starting folder in Windows, Mac and Linux standalones.

    I would just add
    Code (csharp):
    1.  "/"+userFileFolder
    to Application.dataPath in Windows, but I am not sure if that would also work on Mac.
     
  32. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You can use the SetPath function.

    --Eric
     
  33. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    973
    Thanks. Fantastic. I just missed that. Sorry for troubling you.
     
  34. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    973
    But I am just wondering if there is a web version of this.
    I mean a supplement for browsing the server files, working with the same way and skin.
    I have made myself this:
    http://virtualplayground.d2.pl/Unity/experiments/?drawTube
    Basicaly I would like to have that utility unified with unifilebrowser in the other project with both standalone and web versions working the same way.
    But that seems as simple as an insertion of some code into the GetCurrentFileInfo () private function.
     
    Last edited: Jan 15, 2014
  35. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    No, sorry. It's not something that can be done in Unity itself and would require server scripting. You can adapt the code yourself if you want (aside from doing the server programming), but I wouldn't be able to provide support since it's outside the scope for UFB.

    --Eric
     
  36. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    973
    But looks like the SetPath function was also limiting the browsing to that path only.
    Am I right?
    I just expected this and LimitToInitialFolder setting to work independently.

    No. It works fine, I have just put the wrong path, should delete this post.
     
    Last edited: Feb 4, 2014
  37. murkantilism

    murkantilism

    Joined:
    Apr 30, 2012
    Posts:
    21
    Hi Eric!

    To make UniFileBrowser more usable on mobile touch screens, I'd like to increase the size of of the files and folders. I've already increased the size of the Cancel/OK/Open buttons quite easily, but I can't seem to find anything related to the size of the file and folder selection text. Can you point me in the right direction?

    Also, what about increasing the width of the scroll bar? Also a little difficult to select on mobile.

    Thanks!

    Edit: Thanks so much for the quick response, that's exactly the variables I needed to modify! =)
     
    Last edited: Feb 4, 2014
  38. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    The file/folder size can be changed using the listScrollView custom style in the GUISkin. The scroll bars can be changed using the scrollbar styles also in the GUISkin.

    --Eric
     
  39. blueFire

    blueFire

    Joined:
    Nov 27, 2010
    Posts:
    68
    Eric,

    I have ran into a problem. When using the OpenFolderWindow() function I have discovered after I open a subfolder and then select the "\" symbol at the top drop down list (see photo at bottom) I get the following errror:

    ArgumentException: UNC paths should be of the form \\server\share.
    System.IO.Path.InsecureGetFullPath (System.String path) (at /Users/builduser/buildslave/monoAndRuntimeClassLibs/build/mcs/class/corlib/System.IO/Path.cs:350)
    System.IO.Path.GetFullPath (System.String path) (at /Users/builduser/buildslave/monoAndRuntimeClassLibs/build/mcs/class/corlib/System.IO/Path.cs:289)
    System.IO.DirectoryInfo..ctor (System.String path, Boolean simpleOriginalPath) (at /Users/builduser/buildslave/monoAndRuntimeClassLibs/build/mcs/class/corlib/System.IO/DirectoryInfo.cs:61)
    System.IO.DirectoryInfo..ctor (System.String path)
    (wrapper remoting-invoke-with-check) System.IO.DirectoryInfo:.ctor (string)
    UniFileBrowser.GetCurrentFileInfo () (at Assets/Plugins/UniFileBrowser/UniFileBrowser.js:796)
    UniFileBrowser.BuildPathList (Int32 pathEntry) (at Assets/Plugins/UniFileBrowser/UniFileBrowser.js:789)
    UniFileBrowser.DrawFileWindow () (at Assets/Plugins/UniFileBrowser/UniFileBrowser.js:642)
    CompilerGenerated.$adaptor$__UniFileBrowser_closeWindowFunction$callable2$106_35__$WindowFunction$0.Invoke (Int32 capacity)
    UnityEngine.GUI.CallWindowDelegate (UnityEngine.WindowFunction func, Int32 id, UnityEngine.GUISkin _skin, Int32 forceRect, Single width, Single height, UnityEngine.GUIStyle style) (at C:/BuildAgent/work/d3d49558e4d408f4/artifacts/EditorGenerated/GUI.cs:1395)

    $Image1.png

    Jason
     
  40. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Is this over a server?

    --Eric
     
  41. blueFire

    blueFire

    Joined:
    Nov 27, 2010
    Posts:
    68
    No. I have a local app (Android platform) that I am using it in.

    Jason
     
  42. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I can see you're running in the editor on Windows though. I guess Mono doesn't support different file systems like that? It should work if you build for the device.

    --Eric
     
  43. blueFire

    blueFire

    Joined:
    Nov 27, 2010
    Posts:
    68
    You are correct. When I built the target for the various formats it seemed to work correctly.

    Jason
     
  44. darkmax

    darkmax

    Joined:
    Feb 21, 2012
    Posts:
    83
    Hi I'm interested on your plugin, but I didn't see if it has ngui support, and it will be great if it has it. Any change to add ngui support?
     
  45. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    No, sorry.

    --Eric
     
  46. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,462
    @ Eric5h5

    Will there be an update so that this Awesome asset will work with Unity's new GUI system?
     
  47. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Possibly; I'd have to see the new GUI system first to see if there would be any advantage to using it for UniFileBrowser. OnGUI isn't going away...while it's a pain for some things, it's pretty well suited for programmatic GUIs, and UniFileBrowser is highly programmatic. It's not something that needs to be laid out visually (nor can it be, really).

    --Eric
     
  48. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,462
    Ah, I see your point about laying the GUI out visually as opposed to programmatically.

    Is it true that new GUI is very similar to NGUI? or based on NGUI?
     
  49. destapp

    destapp

    Joined:
    Oct 22, 2012
    Posts:
    18
    hi, if i use uniFileBrowser, can i open file. jpg or .png into my game ? and showing up in my game
    its like load or importing image file into game.. on runtime mode
    or
    its just open image file with default aplication like window image viewer??

    thx
     
    Last edited: Mar 17, 2014
  50. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Sure, since Unity has the built-in ability to load png and jpg images at runtime. UniFileBrowser only passes the selected path to your own functions, so what you do with the files is up to you. You could technically import any kind of image, but you'd have to write or buy an importer for anything other than jpg or png.

    --Eric