Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

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
    Probably not, but I don't know for sure.

    --Eric
     
  2. Qwolf

    Qwolf

    Joined:
    Feb 1, 2014
    Posts:
    28
    Are you going to try to fix the issue? It is definitely one of the more annoying problems I've experienced...
     
  3. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    There's nothing I can fix as far as I know; there are no errors here and it compiles fine in Unity, so I'm afraid I wouldn't know what to suggest.

    --Eric
     
    Qwolf likes this.
  4. Qwolf

    Qwolf

    Joined:
    Feb 1, 2014
    Posts:
    28
    Just wondering, what version of unity are you on? I was using 4.5.2 f1 when it happened. Going to update to the newest patch to see if it fixes anything.
     
  5. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    It's the same in any version here, but your issue seems to be with MonoDevelop, not Unity.

    --Eric
     
  6. Qwolf

    Qwolf

    Joined:
    Feb 1, 2014
    Posts:
    28
    Yup it's with Mono. I'll try to recreate the problem on a blank computer. You on Windows?
     
  7. Qwolf

    Qwolf

    Joined:
    Feb 1, 2014
    Posts:
    28
    The problem persists with a blank project with only the UniFileBrowser imported. It only shows on the c# project. I though it could have been a compatibility problem with the JSON library I was using but it still shows on a blank project.
     
  8. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Are you trying to compile in MonoDevelop? Normally you compile in Unity, which is simply a matter of saving the script. Then when you switch to Unity, it compiles.

    --Eric
     
  9. Qwolf

    Qwolf

    Joined:
    Feb 1, 2014
    Posts:
    28
    The error shows when you build (F8).
     
  10. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    That's not necessary; Unity does the compiling. As I mentioned, just save the script and switch to Unity.

    --Eric
     
  11. Qwolf

    Qwolf

    Joined:
    Feb 1, 2014
    Posts:
    28
    Ok. That will work as a temporary fix. I'll try to fix it for my use. I'll tell you if I found a fix.
     
  12. Gunhi

    Gunhi

    Joined:
    Apr 18, 2012
    Posts:
    300
    How can I get Event when User click "Cancel" (CloseFileWindow).

    C# please.
     
  13. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You can use SendWindowCloseMessage. From the docs:

    Code (csharp):
    1. UniFileBrowser.use.SendWindowCloseMessage (FileWindowClosed);
    Where FileWindowClosed is the function you want to run when the window is closed.

    --Eric
     
  14. braiam

    braiam

    Joined:
    Aug 6, 2014
    Posts:
    4
    Just reporting usage here. Now using vectrosity and unifilebrowser for the same project. Both working great. Thanks!

    I have a question. What if I want to build for the web player, but I don't want to use UFB just for that platform. Right now switching to the web player platform, makes unity throw compilation errors. Most of them are related to not finding things in System.IO.

    How can I tell unity that I don't want to include anything from UFB just for the web player?.
     
    Last edited: Aug 21, 2014
  15. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You could wrap the UFB code with #if !UNITY_WEBPLAYER.

    --Eric
     
  16. braiam

    braiam

    Joined:
    Aug 6, 2014
    Posts:
    4
    Perfect.

    To be precise, I had to wrap the two RefBool and RefInt private properties, the two List.<FileData> properties and all the functions in the file. There are some other properties halfway in the file. I had to leave those properties out of #if wraps.

    Wrapping the whole thing (including public properties and stuff) made me lose custom values in the property inpector every time I switched to webplayer and back. Just wrapping the necessary lines made the trick.

    Have a good day!
     
  17. Qwolf

    Qwolf

    Joined:
    Feb 1, 2014
    Posts:
    28
    When searching for an mp3 on android platforms, the file browser only returns the file name as opposed to the full directory.

    Any way to get the full directory?
     
  18. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    The string passed into your open file function is the complete path. If you're referring to the demo script, it only prints the file name rather than the complete path for illustrative purposes, but the full path is always what's passed into the function.

    --Eric
     
  19. gurayg

    gurayg

    Joined:
    Nov 28, 2013
    Posts:
    269
    Hello Eric,
    UFB is on my wishlist for a long time. I'd like to purchase this for an upcoming project.

    -Does using new Ugui give any benefit to UFB? will you be supporting it when 4.6 goes out?
    -Does UFB have file previewing and showing (system)places features?
    -Is it easy to implement features such as custom recent folders(auto shows last X visited folders) and folder bookmarks (user presses a button to save it in a list) to UFB?
    -I could see "folder creation" on the Assetstore page. Can we create a folder using UFB?

    Thanks
     
  20. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    I'm not sure there's much benefit to using the new GUI for this. (Well, you could make it 3D, but...why? ;) ) There aren't any file previewing or folder creation features currently. You get the source code, so you can add recent folders functionality if you want.

    --Eric
     
  21. gurayg

    gurayg

    Joined:
    Nov 28, 2013
    Posts:
    269
    Thanks for your swift reply Eric,

    I thought the Ugui has some optimizations under the hood and the easiness to use (I guess) + if you were to add file previewing and such capabilities in the future new system might be handy.

    Anyway, UFB already seem excellent as it is ;)
    Hope to use it in near future.
     
  22. JuanJSAR

    JuanJSAR

    Joined:
    Feb 21, 2014
    Posts:
    47
    --==ESPAÑOL==--
    Estoy interesado en comprarlo pero solo si funciona en Android y iOS?

    --==TRANSLATOR==--
    I am interested in buying it but only if it works on Android and iOS?
     
  23. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Yes, it does.

    --Eric
     
  24. JuanJSAR

    JuanJSAR

    Joined:
    Feb 21, 2014
    Posts:
    47
    --==ESPAÑOL==--
    Puedes darme soporte personal pues por correo?

    --==TRANSLATOR==--
    You can give me for personal support by mail?
     
  25. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Yes, if you buy the utility and have a question about it. You can also post here if you want.

    --Eric
     
  26. JuanJSAR

    JuanJSAR

    Joined:
    Feb 21, 2014
    Posts:
    47
    --==ESPAÑOL==--
    Una pregunta cuando abro digamos una imagen el que me arroja la direccion del archivo?

    --==TRANSLATOR==--
    A question when I open say a picture which throws me the address of the file?
     
  27. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Unfortunately, the translation isn't working very well. I'm not quite sure what you're asking. My guess is: "can I get the file path of a picture?" If so, the answer is yes. You can filter by file extensions and select only images.

    --Eric
     
  28. nikosurfing

    nikosurfing

    Joined:
    Mar 11, 2014
    Posts:
    45
    Hello, i interested to your actions on playmaker. How to do it? i spent a lot of days to learn it but i don't get it
     
  29. artfish

    artfish

    Joined:
    Aug 28, 2013
    Posts:
    34
    Does this work on iOS? Guess I should have asked before I bought it...
     
  30. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Yes, it does.

    --Eric
     
    artfish likes this.
  31. artfish

    artfish

    Joined:
    Aug 28, 2013
    Posts:
    34
    Thanks! I got it :D
     
  32. artfish

    artfish

    Joined:
    Aug 28, 2013
    Posts:
    34
    Eric, I'm sorry to hit you with a couple of noob questions. Ok, I'm really appreciating the work you've done with this so far. I am now able to record audio and save it, and then it shows up in my documents folder when I open it. I understand I have to write the code to play the file that has been loaded. So here is where my lack of experience is slowing me down. Once my .wav is loaded, where does it actually go, and how do I reference it in a script? I would simply want to create a gui button that plays the audio clip. Thanks for your help. :D
     
  33. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You have to write the code to load it as well, so where it goes depends on what you do. UFB only provides the path to the file that the user selects, so what you do with that is up to you. Typically you'd use System.IO commands, but that's beyond the scope of what UFB does, so it would be best to start a new topic about that.

    --Eric
     
  34. artfish

    artfish

    Joined:
    Aug 28, 2013
    Posts:
    34
    OK. got it. So is that path saved as a variable that I can reference in the code to load it? And if so, what is the variable?
    Let's say I'm using this code:
    1. varMusicFolder:System.IO.DirectoryInfo;
    2. var myClip : WWW;
    3. var myPath :String;
    4. functionStart()
    5. {
    6. myPath ="/mnt/sdcard/music";
    7. MusicFolder=newSystem.IO.DirectoryInfo(myPath);
    8. myClip =new WWW("file:///"+MusicFolder.GetFiles()[0].FullName);
    9. audio.clip = myClip.GetAudioClip(false,false);
    10. }
    11. functionUpdate()
    12. {
    13. if(!audio.isPlaying && audio.clip.isReadyToPlay){
    14. soundPlayer.audio.Play();
    Would I change the
    new WWW("file:///"+MusicFolder.GetFiles()[0].FullName);
    new WWW(PATH THAT WAS RETURNED FROM UNIFILE) ?
    And if so, that is the part I'm wondering what to type.

    Thanks
     
  35. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Yes, but the code would need to be in a OpenFileFunction delegate as described in the docs, since that's where the path is sent to. See also the included example scripts.

    --Eric
     
  36. artfish

    artfish

    Joined:
    Aug 28, 2013
    Posts:
    34
    Can I paypal you another 10$ to write me a simple code that loads the audioclip to an audiosource and plays it? God..I'm such a noob. :D Cuz I know it would take you all of about 10 seconds and it's going to take me hours. LOL
     
  37. artfish

    artfish

    Joined:
    Aug 28, 2013
    Posts:
    34
    Would this be a correct use?

    function OpenFile (pathToFile : String) {
    message = "You selected file: " + pathToFile.Substring (pathToFile.LastIndexOf (pathChar) + 1);
    Fade();
    var www : WWW = new WWW(pathToFile.Substring (pathToFile.LastIndexOf (pathChar) + 1));
    audio.clip = www.audioClip;
    audio.Play();
    }

    I added this to the UniFileExampleBrowser script, and get no errors, however, it doesn't play the sound file after I click open in my build. I'm banging my head against the wall.
     
  38. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You're only using the filename; you need to use the complete path. Also you need to specify file:// for local files when using the WWW class.

    --Eric
     
  39. artfish

    artfish

    Joined:
    Aug 28, 2013
    Posts:
    34
    I know you don't know me, but it really means a lot to me that you have been pointing me in the right direction. I know I'm so close..
    Here's what I have now:
    function OpenFile (pathToFile : String) {
    message = "You selected file: " + pathToFile.Substring (pathToFile.LastIndexOf (pathChar) + 1);
    Fade();
    var www : WWW = new WWW( "file://" + Application.persistentDataPath +"/Documents"+ pathToFile.Substring (pathToFile.LastIndexOf (pathChar) + 1)+".wav");
    audio.clip = www.audioClip;

    if(!audio.isPlaying && audio.clip.isReadyToPlay)
    audio.Play();
    }

    Does that look like the correct way to use the www class and the pathToFile?

    Because if it is, then I can look to other reasons as to why it's not playing...
    Thanks for your time and support! :D
     
  40. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You'd just use the path as passed into the OpenFile function directly; don't try to construct a different path using persistentDataPath and so on.

    --Eric
     
  41. artfish

    artfish

    Joined:
    Aug 28, 2013
    Posts:
    34
    Is there any way you could copy and paste my script from above and edit it to the correct syntax? If not, it's cool. I'll quit dragging this on and just hope I can figure it out on my own. (Obviously I don't understand enough about coding yet to implement what I was hoping to accomplish with purchasing this-sorry.) Thanks for your help.
     
  42. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Just use "file://" plus the path passed into the function (pathToFile).

    --Eric
     
  43. artfish

    artfish

    Joined:
    Aug 28, 2013
    Posts:
    34
    Dude. I'm still up trying to figure this out. LOL. I want to die.Can you PLEASE type it out for me? I will pay you for your time! PM me :D I feel like such an idiot that I can't understand and implement the simple instructions you are giving me.
     
  44. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    "file://" + pathToFile

    --Eric
     
  45. artfish

    artfish

    Joined:
    Aug 28, 2013
    Posts:
    34
    So this?
    function OpenFile (pathToFile : String) {
    message = "You selected file: " + pathToFile.Substring (pathToFile.LastIndexOf (pathChar) + 1);
    Fade();
    var www : WWW = new WWW( "file://" + pathToFile);
    audio.clip = www.audioClip;

    if(!audio.isPlaying && audio.clip.isReadyToPlay)
    audio.Play();
    }
     
  46. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Yep, looks OK.

    --Eric
     
  47. artfish

    artfish

    Joined:
    Aug 28, 2013
    Posts:
    34
    OK then. Thanks. It doesn't work, but at least I can start looking at other reasons why it won't load and play. I appreciate it.
     
  48. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    You can start by debugging the state of audio.isPlaying and audio.clip.isReadyToPlay.

    --Eric
     
    artfish likes this.
  49. artfish

    artfish

    Joined:
    Aug 28, 2013
    Posts:
    34
    Wow. I can't believe this has been so damn hard for me. No matter what I do, I simply cannot play make an audio file play after opening it. In the Editor, on my iOS build, whatever. I tried to post it answers, but my guess is that it wasn't pushed through moderation as you answered it here. :) Do you happen to know of a resource/forum-whatever, where I could hire someone to write me the 4-5 lines of code that should make this work for me?
     
  50. artfish

    artfish

    Joined:
    Aug 28, 2013
    Posts:
    34
    After 2 days of experimenting, and a ton of help from Eric, I finally got it. If anyone is interested, to import a sound that the player has saved, and play it in iOS, I had to do the following...

    I Added

    using System.IO;

    private WWW musicFile;
    public AudioSource musicPlayer;

    And to play it, I use

    void OpenFile (string pathToFile) {
    var fileIndex = pathToFile.LastIndexOf (pathChar);
    message = "You selected file: " + pathToFile.Substring (fileIndex+1, pathToFile.Length-fileIndex-1);
    Fade();

    musicFile = new WWW("file:///" + pathToFile);
    audio.clip = musicFile.GetAudioClip(false, false);

    musicPlayer.audio.Play ();

    Thanks for the great asset and support, Eric!
     
    Last edited: Oct 30, 2014