Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Standalone File Browser

Discussion in 'Assets and Asset Store' started by gkngkc, Jan 17, 2017.

  1. gkngkc

    gkngkc

    Joined:
    Feb 4, 2013
    Posts:
    17
    Hi everyone,

    I wrote a simple wrapper for Windows/Mac native file dialogs. Works in editor and runtime.

    Features:
    • Open file/folder, save file dialogs supported.
    • Multiple file selection.
    • File type filter
    You can check it out here: https://github.com/gkngkc/UnityStandaloneFileBrowser

    Cheers!
     
  2. kelvin-w

    kelvin-w

    Joined:
    Nov 25, 2016
    Posts:
    74
    hi there!

    it really looks nice but there are so many things on it that i dont need. i only want the save file as txt option.
    i cant get it to work without all the other parts and scripts. is there a faster way of doing this instead of using all the options/scripts???

    thanks alot,
    kelvin
     
    TS-Fujikawa likes this.
  3. gkngkc

    gkngkc

    Joined:
    Feb 4, 2013
    Posts:
    17
    Hi,

    I'm not sure what do you mean by other parts and scripts but simplest way to set extension is like this;

    var path = StandaloneFileBrowser.SaveFilePanel("", "", "", "txt");

    But its just a syntactically simplified version, creates a new filter extension array under the hood.
     
  4. kelvin-w

    kelvin-w

    Joined:
    Nov 25, 2016
    Posts:
    74
    okay i fixed it by removing almost every thing (code for the mac and codes for the "open file" option. now i can use it again.

    but i have another question. it doesnt actualy save a file. how and where can i set the data that it should save?

    thanks alot for standalone file browser btw!!!! it looks really good
     
  5. gkngkc

    gkngkc

    Joined:
    Feb 4, 2013
    Posts:
    17
    Yes it won't save anything, its just returns selected path. You need to save file by yourself, like;

    System.IO.File.WriteAllText(path, yourText);

    You're welcome. I'm glad it helped
     
  6. kelvin-w

    kelvin-w

    Joined:
    Nov 25, 2016
    Posts:
    74
    okay thanks alot!!!!!
     
  7. kelvin-w

    kelvin-w

    Joined:
    Nov 25, 2016
    Posts:
    74
    sorry but im back. i want to force that it opens the directory of the .EXE (yes i know how to do this) but where in your script could i do that?

    also may i ask what these mean:
    the " " after the "save file"?
    the extentionList?
    in this part of the code:
    Code (CSharp):
    1.  _path = StandaloneFileBrowser.SaveFilePanel("Save File", "", "MySaveFile", extensionList);
    thanks alot!
     
  8. yc960

    yc960

    Joined:
    Apr 30, 2015
    Posts:
    228
    is there a way of the browser to work in full screen mode?
     
  9. helferapp

    helferapp

    Joined:
    May 17, 2016
    Posts:
    12
    Hi, thank your for great package!

    I'm using StandaloneFileBrowser.OpenFilePanel to load a file in an Unity Windows Standalone App.
    There is one problem: when I use my program in "fullscreen", after return from OpenFileDialog, Windows does'nt return to my program, just shows the Windows desktop.
    The user needs to find my program in the taskbar and click it.

    This may not be a great thing for "normal" users, but my app is used by mentally disabled people, every interrupt of flow is difficulty.

    How can I bring my Unity program back to front after opening a file?
     
  10. gkngkc

    gkngkc

    Joined:
    Feb 4, 2013
    Posts:
    17
    Hi,

    I did some fixes for windows fullscreen support. You can check last commit.

    Thanks
     
    CrandellWS likes this.
  11. helferapp

    helferapp

    Joined:
    May 17, 2016
    Posts:
    12
    Great! Works perfect!
     
    CrandellWS likes this.
  12. Jamsa78

    Jamsa78

    Joined:
    Mar 29, 2017
    Posts:
    96
    Hi

    I'm trying to get it to compile, but no matter what I try, Unity won't accept the scripts.

    Even though VS can see the ass. refs., unity won't. How can I fix it??

    I'm using Unity 5.5.2f1/VS 2017.
     
  13. gkngkc

    gkngkc

    Joined:
    Feb 4, 2013
    Posts:
    17
    Hi,

    I'm not sure but probably its because of plugins. Be sure Ookii.Dialogs.dll and System.Windows.Forms.dll platform dependencies are correct, Editor & Standalone ( Windows ) settings should checked
     
  14. Jamsa78

    Jamsa78

    Joined:
    Mar 29, 2017
    Posts:
    96
    Sorry, didn't see your reply before now..

    Hmm...I'm not really sure what you mean. How do I check it? I've placed the dll's in Assets\plugins\StandaloneFileBrowser\Plugins (including the entire project). Is that what's wrong?

    I want to use this in my project using the Simple Node Editor by Seneral: https://forum.unity3d.com/threads/simple-node-editor.189230
     
  15. gkngkc

    gkngkc

    Joined:
    Feb 4, 2013
    Posts:
    17
    No, directory of dll's shouldn't be a problem. I was talking about import settings

    sfb.jpeg

    But again, i'm just guessing the problem. If you can write the error message, i'll try to understand what's wrong.
     
  16. Jamsa78

    Jamsa78

    Joined:
    Mar 29, 2017
    Posts:
    96
    Ah, ok! Lol, didn't even know that was something I had to deal with. :D

    Anyway, I changed the settings to match your pic. But as you can see, it still gives me errors. Though it's a new kind! I haven't seen those before...?
     

    Attached Files:

  17. gkngkc

    gkngkc

    Joined:
    Feb 4, 2013
    Posts:
    17
    Hmm, i really don't know what's going on never see this error before, looks like some project issue. Maybe you can try removing all file browser files and re-import package
     
  18. Jamsa78

    Jamsa78

    Joined:
    Mar 29, 2017
    Posts:
    96
    Hum, I just noticed that I had the files in two folders. So I deleted one of them and got rid of the warnings, but not the errors.

    Hmm...closed VS, did a reimport, and now it compiles! Yay. :)
     
    Last edited: May 9, 2017
  19. Jamsa78

    Jamsa78

    Joined:
    Mar 29, 2017
    Posts:
    96
    Ok, so I'm using this:
    Code (CSharp):
    1. WriteResult(StandaloneFileBrowser.OpenFilePanel("Open File", "", extensions, true));
    2.  
    3.                 Debug.Log("_path: '" + _path + "'");
    And the output_log shows this:
    _path: 'C:\Udvikling\custom editor\builds\test\test.hop
    '

    Yup, that's a linebreak at the end. But why!? :O :D It causes my code to break when I use path.getfilname().

    I can fix the var myself, but I thought you'd like to know. :)
     
  20. gkngkc

    gkngkc

    Joined:
    Feb 4, 2013
    Posts:
    17
    Thanks for the heads up! It's because of this helper method, default usage should be something like this;
    Code (CSharp):
    1. var paths = StandaloneFileBrowser.OpenFilePanel("Open File", "", extensions, true));                
    2. Debug.Log("_path: '" + paths[0] + "'");
     
    CrandellWS and Jamsa78 like this.
  21. eco_bach

    eco_bach

    Joined:
    Jul 8, 2013
    Posts:
    1,601
    Great utility, thanks for sharing! This should be built in to Unity. However get the following 3 errors the moment I target Windows in Build settings

    Assets/StandaloneFileBrowser/StandaloneFileBrowserWindows.cs(5,14): error CS0234: The type or namespace name Windows' does not exist in the namespaceSystem'. Are you missing an assembly reference?

    Assets/StandaloneFileBrowser/StandaloneFileBrowserWindows.cs(7,7): error CS0246: The type or namespace name `Ookii' could not be found. Are you missing an assembly reference?

    Assets/StandaloneFileBrowser/StandaloneFileBrowserWindows.cs(15,34): error CS0246: The type or namespace name `IWin32Window' could not be found. Are you missing an assembly reference?

    Is it possible the plugins became somehow corrupted when I downloaded the repo?
    Posted as issue here
    https://github.com/gkngkc/UnityStandaloneFileBrowser/issues/14
     
  22. gkngkc

    gkngkc

    Joined:
    Feb 4, 2013
    Posts:
    17
    I commented on the issue. Somehow dll import settings are getting lost when people uses unitypackage i submitted, i don't know what causing this.
     
  23. CharactersArt

    CharactersArt

    Joined:
    Dec 23, 2015
    Posts:
    37
    Hi!
    Excellent work!
    But not working in case of OpenGL build on Windows in Fullscreen mode.
    Tested in Windows 10 64bit.
    Problem is the File dialog not receive focus on open.
    Can you fix it?
    Thank you!
     
    Last edited: Jun 21, 2017
  24. CharactersArt

    CharactersArt

    Joined:
    Dec 23, 2015
    Posts:
    37
    Hello...
    Can you fix it?
    Thank you!
     
  25. gkngkc

    gkngkc

    Joined:
    Feb 4, 2013
    Posts:
    17
    Hi,

    Sorry for late response. I've looked into it but couldn't find a fix or workaround. It's looks like an old opengl problem and probably i can't do much from c# script. If it's a critical issue for you, maybe you can try submit a bug to unity.
     
  26. Wot

    Wot

    Joined:
    Oct 16, 2017
    Posts:
    2
    Hi.
    so i'm still pretty new at this so i could be an idiot but i am having an error compileing with this. i think i set the settings as you said and i tryed this on a second demo project and got the same error, any help guys?

    ""ArgumentException: The Assembly System.Drawing is referenced by System.Windows.Forms ('Assets/StandaloneFileBrowser/Plugins/System.Windows.Forms.dll'). But the dll is not allowed to be included or could not be found.
    UnityEditor.AssemblyHelper.AddReferencedAssembliesRecurse (System.String assemblyPath, System.Collections.Generic.List`1 alreadyFoundAssemblies, System.String[] allAssemblyPaths, System.String[] foldersToSearch, System.Collections.Generic.Dictionary`2 cache, BuildTarget target) (at C:/buildslave/unity/build/Editor/Mono/AssemblyHelper.cs:152)
    UnityEditor.AssemblyHelper.AddReferencedAssembliesRecurse (System.String assemblyPath, System.Collections.Generic.List`1 alreadyFoundAssemblies, System.String[] allAssemblyPaths, System.String[] foldersToSearch, System.Collections.Generic.Dictionary`2 cache, BuildTarget target) (at C:/buildslave/unity/build/Editor/Mono/AssemblyHelper.cs:158)
    UnityEditor.AssemblyHelper.AddReferencedAssembliesRecurse (System.String assemblyPath, System.Collections.Generic.List`1 alreadyFoundAssemblies, System.String[] allAssemblyPaths, System.String[] foldersToSearch, System.Collections.Generic.Dictionary`2 cache, BuildTarget target) (at C:/buildslave/unity/build/Editor/Mono/AssemblyHelper.cs:158)
    UnityEditor.AssemblyHelper.FindAssembliesReferencedBy (System.String[] paths, System.String[] foldersToSearch, BuildTarget target) (at C:/buildslave/unity/build/Editor/Mono/AssemblyHelper.cs:192)
    UnityEngine.GUIUtility:processEvent(Int32, IntPtr)""
     
  27. gkngkc

    gkngkc

    Joined:
    Feb 4, 2013
    Posts:
    17
    No problem :) You should select ".NET 2.0" from Player Settings / Api Compatibility Level
     
  28. Wot

    Wot

    Joined:
    Oct 16, 2017
    Posts:
    2
    that did it thanks ;)
     
    gkngkc likes this.
  29. Dam-Pete

    Dam-Pete

    Joined:
    Jun 11, 2010
    Posts:
    53
    Hey, I have used the System.Windows.Forms DLLs to load the Save/Open dialogs, but my window comes with an older looking version. Also when in the Editor, when I run my project for the second time and beyond, I get the annoying "Oops" error prompt, how did you get the newer look and remove the "Oops" prompts? I ask because I'm currently trying to open Windows Forms dialogs (now that we have 4.6 support) and I can get it fine, but they come with that same old looking style...
     
  30. gkngkc

    gkngkc

    Joined:
    Feb 4, 2013
    Posts:
    17
    Hi, i used ookii dialogs dll to show newer dialog style, but i don't know what causing oops errors. I don't remember seeing that kind of error.
     
  31. BenEvansCSIRO

    BenEvansCSIRO

    Joined:
    Jun 7, 2017
    Posts:
    1
    Looks like spaces are being replaced by % in the resulting path. This makes it pretty much unusable for any file system that allows spaces in the file name. Only tested on macOS but last time I tried on Windows I didn't notice such a problem. Do you know where this replacement might be occurring? No mention of it in the code so I'm guessing it's in the native bundle.
     
  32. Razek07

    Razek07

    Joined:
    Sep 10, 2014
    Posts:
    4
    Hi! thank you for this gkngkc!

    I´m getting work file browsing, but i have a doubt if async methods are working?
    Because ever i open a file browser dialog frezzes all my background application.

    Do you have any idea why this happen?

    Thank you in advace
     
  33. domdev

    domdev

    Joined:
    Feb 2, 2015
    Posts:
    375
    anyone using async? cause when I tried it in windows it did not save or any..popup was working BTW
     
  34. Gillissie

    Gillissie

    Joined:
    May 16, 2011
    Posts:
    294
    Hey gkngkc, thanks for the library! I'm developing on a Mac, and the functionality works great. However, I can't make a Windows standalone build on my Mac without getting this error:

    ArgumentException: The Assembly Mono.WebBrowser is referenced by System.Windows.Forms ('Assets/StandaloneFileBrowser/Plugins/System.Windows.Forms.dll'). But the dll is not allowed to be included or could not be found.


    Is this a new issue, or will this only build from the Windows version of Unity?
     
  35. ActiveSim

    ActiveSim

    Joined:
    May 10, 2019
    Posts:
    58
    Same here on Windows for Windows!
     
  36. rayD8

    rayD8

    Joined:
    Mar 7, 2018
    Posts:
    32
    I get the same error, but it runs in the editor.
    "Fixed"
    I had to move the dll to the main Plugins folder and restart - made no difference.
    Then I realized the dll was targeted for .NET 3.5..... still got the same errors on build.
    Restarted... got a build with no errors. Quit Unity.
    Went back to double-check the .NET target and scripting API... (to post)
    It was back to being set to 4.5 ???
    Tried another build... and it worked fine now with .NET 4.5
    No idea how or what hoop I flopped through.
     
    Last edited: Sep 22, 2019
  37. NSJacob

    NSJacob

    Joined:
    Nov 23, 2018
    Posts:
    1
    I also noticed Ooki.Dialogs.DLL and System.Windows.Forms.DLL are targetting .NET 3.5, and I get errors when building for Windows Standalone with scripting runtime version 4.x equivalent. Any plans to update DLL targets?
     
  38. hippogames

    hippogames

    Joined:
    Feb 5, 2015
    Posts:
    228
    A workaround suggested here doesn't work for me in Unity 2019.2.4

    So I've made my own workaround and can suggest you to add it to the repo:
    • replace System.Windows.Forms (targeting .NET 3.5) to C:\Windows\Microsoft.NET\Framework\v4.0.30319 (targeting .NET 4)
    • add System.Deployment.dll (as required by System.Windows.Forms)
    • set Scripting Backend 'Mono'
    • build

    https://github.com/gkngkc/UnityStandaloneFileBrowser/issues/71
     
    tuckerlangseth likes this.
  39. kamekichizz

    kamekichizz

    Joined:
    Nov 19, 2019
    Posts:
    1
    2019.2.15f1
    I cannot build with errors.

    UnityEditor.BuildPlayerWindow+BuildMethodException: 3 errors
    at UnityEditor.BuildPlayerWindow+DefaultBuildMethods.BuildPlayer (UnityEditor.BuildPlayerOptions options) [0x00242] in C:\buildslave\unity\build\Editor\Mono\BuildPlayerWindowBuildMethods.cs:190
    at UnityEditor.BuildPlayerWindow.CallBuildMethods (System.Boolean askForBuildLocation, UnityEditor.BuildOptions defaultBuildOptions) [0x0007f] in C:\buildslave\unity\build\Editor\Mono\BuildPlayerWindowBuildMethods.cs:95
     
  40. Zashelowsky

    Zashelowsky

    Joined:
    Sep 19, 2019
    Posts:
    2
    Hello! Sorry for my bad english.

    I have some errors: when switch platform from windows to linux, or MacOs, i get this:

    DllNotFoundException: StandaloneFileBrowser
    SFB.StandaloneFileBrowserLinux..ctor () (at Assets/StandaloneFileBrowser/StandaloneFileBrowserLinux.cs:36)
    SFB.StandaloneFileBrowser..cctor () (at Assets/StandaloneFileBrowser/StandaloneFileBrowser.cs:23)
    Rethrow as TypeInitializationException: The type initializer for 'SFB.StandaloneFileBrowser' threw an exception.
    BasicSample.OnGUI () (at Assets/StandaloneFileBrowser/Sample/BasicSample.cs:20)

    How i can solve this?

    Unity 2018.4.13f1.
     
  41. akeplinger

    akeplinger

    Joined:
    Oct 26, 2008
    Posts:
    56
    This is set up for windows but doesn't work for Windows Universal, at least the current version Unity3d. Working in Editor when Universal build is selected, but when the app is built the # if UNITY_STANDALONE_WIN directives are not triggered, so the windows code does not get loaded. Is WSA out of scope or is there some setting that I'm missing?
     
  42. MNNoxMortem

    MNNoxMortem

    Joined:
    Sep 11, 2016
    Posts:
    723
    As this package seems to be not maintained anymore, and the new Entities Code expects .NET 2.0 Standard, and all other filebrowsers I have found require 4.6 compatibility level:

    Has anyone found a working replacement for this library? A working replacement for Windows Standalone would be a good start. A cross plattform replacement would be even better.
     
  43. Tobl4

    Tobl4

    Joined:
    Nov 22, 2018
    Posts:
    1
    I also ran into the:
    ArgumentException: The Assembly Mono.WebBrowser is referenced by System.Windows.Forms ('Assets/StandaloneFileBrowser/Plugins/System.Windows.Forms.dll'). But the dll is not allowed to be included or could not be found.
    In my case (Unity 2019.2.19f1 on Windows), this was fixed by setting the scripting backend to NET 4.x
     
  44. OMGitsAJZ

    OMGitsAJZ

    Joined:
    Dec 27, 2017
    Posts:
    4
    Hello,

    I have been using the Standalone file browser successfully for a few weeks now, and I recently discovered that attempting to overwrite a file when saving it causes a crash.

    Here's my little code:

    Code (CSharp):
    1. public static string SaveDialog()
    2. {
    3.     string path = StandaloneFileBrowser.SaveFilePanel("Save Level", "", "level.lvl", "lvl");
    4.     return path;
    5. }
    So if I enter a file name that already exists, my entire build crashes.
    I linked the error log here, and I can't seem to get any useful info out of it myself.
    https://drive.google.com/file/d/1-Gk_3SG9D3908acg-zIChjPSodM_p3x9/view?usp=sharing

    My guess is that is has something to do with Windows trying to open a dialog saying, "Are you sure you want to overwrite a file?" but the SaveFilePanel method was not ready for it, but I'm just guessing.

    Any help would be appreciated! I'll provide more info if needed.
     
  45. ElieC

    ElieC

    Joined:
    Jun 3, 2020
    Posts:
    2
    Hi!
    I'm running into the exact same problem as unity_qYu7U2im6OLsjQ
    I was using The StandAlone file browser for more than one year without any problem.

    But I discovered that after a build I'm not able anymore to overwrite an existing file without getting a crash. This might happen since I recently updated my project from Unity 2018.3.5f1 to Unity 2019.3.9f1. (Previously saved older builds do not crash)

    The file browser works fine in editor mode and for Linux builds. However, a Windows build crashes anytime I try to overwrite a file, with the same error log as the post above. (writing access violation, seems to be)

    I guess it might be an incompatibility between the code of the file browser and updates in Unity. I'll try to look for a solution and post there if I make any progress. But that's too bad if the file browser is not compatible anymore with some given version of Unity.
     
    OMGitsAJZ likes this.
  46. ElieC

    ElieC

    Joined:
    Jun 3, 2020
    Posts:
    2
    Ok,

    My bad, I did not make enough research before posting cause it seems that the issue has already been kind of solved.
    In case some others reach this thread with the same problem, here are two solutions:

    As unity_qYu7U2im6OLsjQ said, the problem is somehow related to the Dialog prompt which confirms overwrite.

    One (bad) solution I've first found was to modify the code of the FileBrowser to deactivate this DialogPrompt using the settable property OverwritePrompt of the SaveFileDialog (https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.savefiledialog.overwriteprompt)

    But then i've finally discovered that this issue was already discussed directly on the github project : https://github.com/gkngkc/UnityStandaloneFileBrowser/issues/64
    Changing the ookii lib as described in the thread is enough to make things work perfectly fine!
     
    OMGitsAJZ likes this.
  47. Chuebueb

    Chuebueb

    Joined:
    Jul 30, 2019
    Posts:
    2
    I used this solution for some projects and it was great until IL2CPP came along...
    Anyway, if you want to spare you the hassle, I'm now using this asset:
    https://assetstore.unity.com/packages/slug/98713

    It costs a little, but it works great and is supported ;)
     
  48. OMGitsAJZ

    OMGitsAJZ

    Joined:
    Dec 27, 2017
    Posts:
    4
    Awesome! Thanks for the reply, I will also post here if I find a solution.
     
  49. OMGitsAJZ

    OMGitsAJZ

    Joined:
    Dec 27, 2017
    Posts:
    4
    Thank you ElieC, I missed your most recent post, I will look into this and report back soon on whether it fixed the problem for me as well. Much appreciated!
     
  50. OMGitsAJZ

    OMGitsAJZ

    Joined:
    Dec 27, 2017
    Posts:
    4
    Yess, that ookii dialog dll file was perfect, everything works as expected now :) finally done with that old bug!