Skip to content

RuyeRuye/UnityStandaloneFileBrowser

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

78 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Unity Standalone File Browser

openupm

A simple wrapper for native file dialogs on Windows/Mac/Linux, plus a dedicated WebGL browser file API.

Installation

Add from OpenUPM | via scoped registry, recommended

To add OpenUPM to your project:

  • open Edit/Project Settings/Package Manager
  • add a new Scoped Registry:
Name: OpenUPM
URL:  https://package.openupm.com/
Scope(s): io.github.gkngkc.unity-standalone-file-browser
  • click Save
  • open Package Manager
  • Select My Registries in dropdown top left
  • Select Unity Standalone File Browser and click Install
Add from GitHub | not recommended, no updates through PackMan

You can also add it directly from GitHub on Unity 2019.4+. Note that you won't be able to receive updates through Package Manager this way, you'll have to update manually.

  • open Package Manager
  • click +
  • select Add from Git URL
  • paste https://github.com/shiena/UnityStandaloneFileBrowser.git?path=Packages/StandaloneFileBrowser#upm
  • click Add

Example usage:

// Open file
var paths = StandaloneFileBrowser.OpenFilePanel("Open File", "", "", false);

// Open file async
StandaloneFileBrowser.OpenFilePanelAsync("Open File", "", "", false, (string[] paths) => {  });

// Open file with filter
var extensions = new [] {
    new ExtensionFilter("Image Files", "png", "jpg", "jpeg" ),
    new ExtensionFilter("Sound Files", "mp3", "wav" ),
    new ExtensionFilter("All Files", "*" ),
};
var paths = StandaloneFileBrowser.OpenFilePanel("Open File", "", extensions, true);

// Save file
var path = StandaloneFileBrowser.SaveFilePanel("Save File", "", "", "");

// Save file async
StandaloneFileBrowser.SaveFilePanelAsync("Save File", "", "", "", (string path) => {  });

// Save file with filter
var extensionList = new [] {
    new ExtensionFilter("Binary", "bin"),
    new ExtensionFilter("Text", "txt"),
};
var path = StandaloneFileBrowser.SaveFilePanel("Save File", "", "MySaveFile", extensionList);

See Sample/BasicSampleScene.unity for more detailed examples.

Mac Screenshot Alt text

Windows Screenshot Alt text

Linux Screenshot Alt text

Notes:

  • Windows

    • Requires .NET 3.5 or higher api compatibility level
    • Async dialog opening not implemented, ..Async methods simply calls regular sync methods.
    • Plugin import settings should be like this;

    Alt text Alt text

  • Mac

    • Sync calls are throws an exception at development build after native panel loses and gains focus. Use async calls to avoid this.

WebGL:

  • WebGL uses the dedicated StandaloneFileBrowserWebGL API instead of the desktop StandaloneFileBrowser path-based API.
  • The desktop StandaloneFileBrowser API is intentionally unavailable in WebGL builds; use explicit platform branching.
  • Opening files returns temporary browser file references (WebGLFileReference) with ObjectUrl, Name, Size, MimeType, and LastModifiedUnixMs metadata.
  • Recommended read path is ObjectUrl + UnityWebRequest / UnityWebRequestTexture, then explicit Release(...) after the read completes.
  • Saving uses SaveFileAsync(fileName, data[, mimeType]) and triggers a browser download rather than a native save dialog.
  • File filters are picker hints only.
  • Browser limitations still apply: meaningful title / default-directory semantics are not available, and open/save should be triggered directly from a user gesture (OnPointerDown).
  • If open is triggered outside a valid user gesture, it returns Error with an explanatory message; save returns BlockedByBrowser.
  • First-version concurrency is one open request and one save request at a time.

Example WebGL usage:

using System.Collections;
using SFB;
using UnityEngine;
using UnityEngine.Networking;

public void OpenTextFile() {
    StandaloneFileBrowserWebGL.OpenFilePanelAsync("txt", false, result => {
        if (result.Status != WebGLFileSelectionStatus.Success || result.Files.Length == 0) {
            return;
        }

        var file = result.Files[0];
        StartCoroutine(ReadTextAndRelease(file));
    });
}

private IEnumerator ReadTextAndRelease(WebGLFileReference file) {
    var request = UnityWebRequest.Get(file.ObjectUrl);
    yield return request.SendWebRequest();

    if (request.result == UnityWebRequest.Result.Success) {
        Debug.Log(request.downloadHandler.text);
    }

    StandaloneFileBrowserWebGL.Release(file);
}

public void SaveTextFile(byte[] bytes) {
    StandaloneFileBrowserWebGL.SaveFileAsync("sample.txt", bytes, result => {
        Debug.Log(result.Status);
    });
}

Live Demo: https://gkngkc.github.io/

About

A native file browser for unity standalone platforms

Resources

License

Stars

1 star

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • C# 62.3%
  • Objective-C++ 14.2%
  • C 11.4%
  • JavaScript 10.9%
  • Other 1.2%