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

Simple File Browser [Open Source]

Discussion in 'Assets and Asset Store' started by yasirkula, Nov 19, 2016.

  1. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,865
    SimpleFileBrowser doesn't have that functionality built-in since it requires implementing a texture caching system, which can be really complex.
     
  2. RafaelDev

    RafaelDev

    Joined:
    Feb 15, 2017
    Posts:
    12
    How I can open a file externally iOS? OpenURL doesn't work anymore and FileProvider only work for Android.
     
  3. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,865
    I also don't know the answer to this question.
     
  4. RafaelDev

    RafaelDev

    Joined:
    Feb 15, 2017
    Posts:
    12
    iOS have a NSFileProvider for that. But yes, need a native plugin anyway. Thanks
     
  5. batvink

    batvink

    Joined:
    Sep 26, 2019
    Posts:
    61
    Hi,
    this looks like a useful addition, but I can't get it to work. I am using it in the most simple way, but I cannot even get the first line of configuration to succeed.

    Error message:

    Code (csharp):
    1. NullReferenceException: Object reference not set to an instance of an object
    2. SimpleFileBrowser.FileBrowser.get_Instance () (at Assets/Plugins/SimpleFileBrowser/Scripts/FileBrowser.cs:139)
    3. SimpleFileBrowser.FileBrowser.SetFiltersPreProcessing (System.Boolean showAllFilesFilter) (at Assets/Plugins/SimpleFileBrowser/Scripts/FileBrowser.cs:1385)
    4. SimpleFileBrowser.FileBrowser.SetFilters (System.Boolean showAllFilesFilter, SimpleFileBrowser.FileBrowser+Filter[] filters) (at Assets/Plugins/SimpleFileBrowser/Scripts/FileBrowser.cs:1369)
    5. GlobalConfig.LoadDataFile () (at Assets/Scripts/GlobalConfig.cs:46)
    6. UnityEngine.Events.InvokableCall.Invoke ()
    The line of code I am running:
    Code (CSharp):
    1. FileBrowser.SetFilters(true, new FileBrowser.Filter("Game Data Files", ".dat"));
    The FileBrowser code that fails is below. It is the first line that failed and returns null. The error is then recorded for the second line when it tries to refer to m_instance.

    Code (CSharp):
    1. m_instance = Instantiate( Resources.Load<GameObject>( "SimpleFileBrowserCanvas" ) ).GetComponent<FileBrowser>();
    2. DontDestroyOnLoad( m_instance.gameObject );
    3.  
     
  6. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,865
    Does SimpleFileBrowserCanvas prefab exist at Plugins/SimpleFileBrowser/Resources? And does it have a FileBrowser component attached? If not, you can try deleting the plugin and reimporting it.
     
  7. batvink

    batvink

    Joined:
    Sep 26, 2019
    Posts:
    61
    @yasirkula The canvas existed, but the script wasn't attached. I manually added the script and it still failed.
    So I deleted the folder and all scripts, and re-imported. It worked straight away :)

    While I was learning how it worked, I added one of the scripts to an empty game object, and then deleted it later. Maybe this caused problems along the way.

    Thanks for your help, fantastic asset!
     
    yasirkula likes this.
  8. mib1700

    mib1700

    Joined:
    Jun 9, 2018
    Posts:
    1
    This works great! Thanks so much for the asset.
    Is there any way to select multiple files at once?
     
  9. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,865
    It is not supported at the moment.
     
  10. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,865
  11. RafaelDev

    RafaelDev

    Joined:
    Feb 15, 2017
    Posts:
    12
    Damn I downloaded some fork since you said that multi selection was not in your todo list :oops:

    SimpleFileBrowser limits the file list somehow? In any platform, are showing only 12 files at max.

    And a generic question: You know how I can open the root(or media) folder on mobile? Looks like each system version has their own path
     
  12. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,865
  13. RafaelDev

    RafaelDev

    Joined:
    Feb 15, 2017
    Posts:
    12
    No errors.

    At the end of the RefreshFiles function, validItems count is 52, but the listView.contentTransform.childCount is 12 always
     
  14. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,865
    File browser creates items for only the files that are visible in the scroll view. The 12 items in your case are reused when you scroll.
     
  15. RafaelDev

    RafaelDev

    Joined:
    Feb 15, 2017
    Posts:
    12
    Well, so the problem must be that the scroll is not pooling. I can see only 12 items always, no scroll
     
  16. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,865
    On which Unity version does this issue occur? If you have multiple Unity versions, do other versions also suffer the same issue? I am not sure why I am not having this issue.
     
  17. RafaelDev

    RafaelDev

    Joined:
    Feb 15, 2017
    Posts:
    12
    I noticed the error in Unity 2019.1.5 and still occurs in Unity 2019.3.15

    I tried to create a new UI to the FileBrowser so I'm not using your default prefab.

    Maybe I wrong configurated something? Still testing here.
     
  18. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,865
    Can you import the plugin to a new project without any modifications and see if it also has this issue? If not, probably something is different in your own UI. I'd recommend you to compare the scroll view and its child objects with your own UI to see if there are any non-UI differences.
     
  19. RafaelDev

    RafaelDev

    Joined:
    Feb 15, 2017
    Posts:
    12
    Well, basically:

    -ListView and ScrollRect must be in the same GameObject
    -The content window cannot have ContentSizeFitter either VerticalLayout
    -The item's anchor must be in the top left
     
  20. naagi

    naagi

    Joined:
    Nov 27, 2014
    Posts:
    13
    dear sir, thank you for you work, this asset really help me until now

    but i have a problem, the asset works fine in the android Pie and below, but when i use the apps in android Q some buttons in the file browser window are not showing up ( the right arrow button and Up arrow button).

    do you know why this is happen? and how to fix it?

    i have some screenshoot to show this problem below

    android Pie window ( all button show and working normally)


    android Q window ( missing right and up arrow, cannot select any file)


    thank you for your help
     
  21. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,865
    Android Q uses Storage Access Framework. It doesn't use System.IO.File APIs since they are forbidden for most directories on Android Q+. SimpleFileBrowser can access only the directories that user manually picks via the "Pick Folder" button. Up arrow is disabled for two reasons:

    1. Unless user has picked the parent folder with "Pick Folder", that folder will be inaccessible.
    2. Storage Access Framework doesn't use file paths and in that system, you can't determine the parent folder's path by looking at the current directory's path. Here's an example path used in Storage Access Framework: content://com.android.externalstorage.documents/tree/primary%3A/document/primary%3APictures

    Left and right arrows should work as usual, though.
     
  22. shinkuan

    shinkuan

    Joined:
    Mar 11, 2020
    Posts:
    1
    Is there a option to force the user to select only ONE file?

    Edit:
    Sorry, what a stupid question. I found the parameter!

    Your asset is really amazing.
     
    Last edited: Jun 11, 2020
    yasirkula likes this.
  23. said123sawn

    said123sawn

    Joined:
    Oct 31, 2019
    Posts:
    26
    hello, i want to create a folder in the selected folder with your plugin on android

    how can I do that?
     
  24. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,865
  25. said123sawn

    said123sawn

    Joined:
    Oct 31, 2019
    Posts:
    26
    CreateFolderInDirectory (string directoryPath, string folderName); I tried the code but I couldn't do it again
     
  26. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,865
    Yes, you should use that function. Can I see your code? Does it throw any error messages to logcat?
     
  27. said123sawn

    said123sawn

    Joined:
    Oct 31, 2019
    Posts:
    26
    does not show error message but does not work for android only works for windows
    Code (CSharp):
    1.         FileBrowserHelpers.CreateFolderInDirectory("/storge/emulated/0", "NewFolder");
     
  28. said123sawn

    said123sawn

    Joined:
    Oct 31, 2019
    Posts:
    26
    I tried to do this by taking the path in your plugin's browser, but I don't know exactly how to do it.
    like this
    Code (CSharp):
    1.         if (FileBrowser.Success)
    2.         {
    3.             for (int i = 0; i < FileBrowser.Result.Length; i++)
    4.             {
    5.                 Debug.Log(FileBrowser.Result[i]);
    6.                 FileBrowserHelpers.CreateFolderInDirectory(FileBrowser.Result[i], "MyFolder");
    7.             }
    8.  
    9.             byte[] bytes = FileBrowserHelpers.ReadBytesFromFile(FileBrowser.Result[0]);
    10.  
    11.         }
     
  29. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,865
    You must set folderMode to true and pass the path of the folder that FileBrowser returns to directoryPath, which you do in your second code. It creates a folder named MyFolder inside the picked folder(s). But you can't read bytes of a directory, so line 9 will fail.
     
  30. said123sawn

    said123sawn

    Joined:
    Oct 31, 2019
    Posts:
    26
    Creating files was successful when foldermode is true, but when I write the code below, I cannot create a file
    Code (CSharp):
    1. FileBrowserHelpers.CreateFolderInDirectory("/storge/emulated/0", "NewFolder");
    the path I wrote is the same as the browser's path

    thank you for your efforts:oops:
     
  31. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,865
    You have a typo: storge (should be storage). But that path isn't the same for all Android devices, so this approach won't work for all devices. FileBrowserHelpers functions aren't guaranteed to work with manually typed paths.
     
  32. RafaelDev

    RafaelDev

    Joined:
    Feb 15, 2017
    Posts:
    12
    By default, iOS build open the persistentDataPath, which is the app's folder. CanI change it? To something like Documents? I don't know iOS paths
     
  33. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,865
    iOS doesn't allow access to most directories outside of the app's own folder. You can try assigning a value to the initialPath parameter of ShowSaveDialog/ShowLoadDialog but I don't know any special iOS paths either.
     
  34. RafaelDev

    RafaelDev

    Joined:
    Feb 15, 2017
    Posts:
    12
    I'm getting this error:

    UnauthorizedAccessException: Access to the path "/var/containers/Bundle/Application/appID/appName.app/Documents" is denied.
    System.IO.Directory.CreateDirectoriesInternal (System.String path) (at <00000000000000000000000000000000>:0)
    Manager_FileBrowser.SaveFile (DATA_File infos, System.Byte[] bytes) (at <00000000000000000000000000000000>:0)

    I'm using an asset to show debugs in the iPhone(https://assetstore.unity.com/packages/tools/gui/in-game-debug-console-68068)
     
  35. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,865
    Is this path a predefined path like persistentDataPath? If not, how did you find/navigate to this directory?
     
  36. unity_FOBkcrfCSVB5uw

    unity_FOBkcrfCSVB5uw

    Joined:
    Mar 5, 2020
    Posts:
    4
    Hello, first of all thank you for your package, it is really well done ! I just have a question, is there a way to not display the dialog browser when I open a specific scene ? I'd like to only open the dialog browser if I click in a specific button of my scene, which I can. So how do I disable showing it when I reach a scene ? I tried with the Start method but didn't result...
     
  37. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,865
    File browser won't show up until you call ShowSaveDialog or ShowLoadDialog. You might be calling one of these functions when scene starts. Also, if you had manually placed the file browser prefab to your scene, you should either deactivate it when scene starts or delete it (since it is automatically instantiated by the plugin).
     
  38. unity_FOBkcrfCSVB5uw

    unity_FOBkcrfCSVB5uw

    Joined:
    Mar 5, 2020
    Posts:
    4
    Yes I indeed call ShowLoadDialog in Start method, so you're saying I need to call ShowLoadDialog somewhere else (on click of button) and not in Start method ?
     
  39. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,865
    Yes, only when you want to display the dialog.
     
  40. MohsenJamaliL

    MohsenJamaliL

    Joined:
    Nov 13, 2017
    Posts:
    12
    Hi
    I'm running this on Android 9 but I'm getting this error
    07-10 17:38:26.461: E/Unity(9779): AndroidJavaException: java.lang.ClassNotFoundException: com.yasirkula.unity.FileBrowser
    any idea
     
  41. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,865
    If your project uses ProGuard, try adding the following line to ProGuard filters:
    -keep class com.yasirkula.unity.* { *; }
     
  42. TheWebExpert

    TheWebExpert

    Joined:
    Apr 14, 2015
    Posts:
    198
    FileBrowser.SetFilters(true, new FileBrowser.Filter("SuperOthello game files", ".SAV"));
    FileBrowser.SetDefaultFilter("*.SAV");

    I'm trying to set the default extension for the dialog. However, it's still coming up with "All files (.*)" ... what am I missing? Do these lines have to be in the Coroutine?
     
  43. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,865
    Try
    FileBrowser.SetDefaultFilter(".SAV");
    . If that doesn't work, try
    FileBrowser.SetDefaultFilter(".sav");
     
  44. TheWebExpert

    TheWebExpert

    Joined:
    Apr 14, 2015
    Posts:
    198
    Neither of those worked. I have this:

    yield return FileBrowser.WaitForLoadDialog(false, true, Application.persistentDataPath, "Load Saved Game", "Load");

    inside the coroutine.
     
  45. TheWebExpert

    TheWebExpert

    Joined:
    Apr 14, 2015
    Posts:
    198
    Ok, I re-did it and got the result. What I have now is this:

    FileBrowser.SetFilters(true, new FileBrowser.Filter( "*.SAV", ".SAV"));
    FileBrowser.SetDefaultFilter( ".sav" );

    thanks for your help.
     
  46. TheWebExpert

    TheWebExpert

    Joined:
    Apr 14, 2015
    Posts:
    198
    Doesn't FileBrowserHelpers.ReadTextFromFile(FileBrowser.Result[0]) read the ENTIRE contents of the text file? This seems to be reading only one line.

    If I have to repeat this command for each line, that's fine... but I need to know what I'm doing. I really need this to be in text format.
     
  47. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,865
    ReadTextFromFile uses File.ReadAllText, so it should read the whole contents at once. If you are outputting the result to Unity's console, you may have to click the log to see the rest of the lines.
     
  48. TheWebExpert

    TheWebExpert

    Joined:
    Apr 14, 2015
    Posts:
    198
    Ah. I didn't know that. I just saw the first line and figured that was it... ok, it was all there. Thanks again!
     
    yasirkula likes this.
  49. yiduoke

    yiduoke

    Joined:
    Jun 22, 2020
    Posts:
    2
    Hi!

    Thank you so much for providing this for free! I have a question, I'm trying to build this for a VR headset (OS is Android), and you told us to set write permissions to external for it to work, but this headset doesn't have an SD card and I'm not planning on getting one, sp can I still save and load files on this headset's internal storage?

    Thanks!
     
  50. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,865
    Yes. "External (SDCard)" is a misleading name, it actually means being able to access files that are located outside the app's internal folders.