Giter Site home page Giter Site logo

anotherfilebrowser's Introduction

AnotherFileBrowser

Just another File Dialog for Unity, with easy implementation. Using Ookii Dialogs. Rather than putting everything in .dll, i've done this simply with a class, so you can extend it based on Ookii Dialogs.

alt-text

Getting Started

Download the latest release from Releases. Import it to Unity. Or, if you want download the project, just clone it.

After importing, change Change API Compatibility Level to .NET 4.x, from Project Settings -> Player -> Other Settings. And, change Scripting Backend to Mono.

Implementation

Implementation is quite easy, but before implementing let's know about BrowserProperties constructor.

BrowserProperties

public class BrowserProperties
{
    public string title; //Title of the Dialog
    public string initialDir; //Where dialog will be opened initially
    public string filter; //aka File Extension for filtering files
    public int filterIndex; //Index of filter, if there is multiple filter. Default is 0.
    public bool restoreDirectory = true; //Restore to last return directory


    public BrowserProperties() { }
    public BrowserProperties(string title) { this.title = title; }
}

Make sure to define AnotherFileBrowser.Windows namespace.

Picking a Single File

var bp = new BrowserProperties();
bp.filter = "txt files (*.txt)|*.txt|All Files (*.*)|*.*";
bp.filterIndex = 0;

new FileBrowser().OpenFileBrowser(bp, path =>
{
    //Do something with path(string)
    Debug.Log(path);
});

Picking Multiple File(s)

var bp = new BrowserProperties();
bp.filter = "txt files (*.txt)|*.txt|All Files (*.*)|*.*";
bp.filterIndex = 0;

new FileBrowser().OpenMultiSelectFileBrowser(bp, path =>
{
    //Do something with path(string[])
    string s = "";
    for (int i = 0; i < path.Length; i++)
    {
        s += path[i] + "\n";
    }

});

Picking Folder Path

var bp = new BrowserProperties();
bp.filter = "txt files (*.txt)|*.txt|All Files (*.*)|*.*";
bp.filterIndex = 0;

new FileBrowser().OpenFolderBrowser(bp, path =>
{
    //Do something with path(string)
    Debug.Log(path);
});

Picking Path for Saving File

var bp = new BrowserProperties();
bp.filter = "txt files (*.txt)|*.txt";
bp.filterIndex = 0;

new FileBrowser().SaveFileBrowser(bp, "test", ".txt", path =>
{
    //Do something with path(string)
    Debug.Log(path);
});

Picking and Loading Image

var bp = new BrowserProperties();
bp.filter = "Image files (*.jpg, *.jpeg, *.jpe, *.jfif, *.png) | *.jpg; *.jpeg; *.jpe; *.jfif; *.png";
bp.filterIndex = 0;

new FileBrowser().OpenFileBrowser(bp, path =>
{
    //Load image from local path with UWR
    StartCoroutine(LoadImage(path));
});

//Load Image from Local
IEnumerator LoadImage(string path)
{
    using (UnityWebRequest uwr = UnityWebRequestTexture.GetTexture(path))
    {
        yield return uwr.SendWebRequest();

        if (uwr.isNetworkError || uwr.isHttpError)
        {
            Debug.Log(uwr.error);
        }
        else
        {
            var uwrTexture = DownloadHandlerTexture.GetContent(uwr);
            //placeholderImage is an Image Component of Unity UI
            placeholderImage.sprite = Sprite.Create(uwrTexture, new Rect(0, 0, uwrTexture.width, uwrTexture.height), new Vector2(0, 0));
        }
    }
}

Pro-Tips

Use preprocessor for Platform Dependent Compilation, so there won't be any issue while building for other platforms.

IL2CPP Support

I'm facing crashes if try to open dialog from il2cpp build. If you want to try in il2cpp, you need to add Mono.Posix & Mono.WebBrowser from C:\Program Files\Unity\Editor\Data\MonoBleedingEdge\lib\mono\gac to \Plugins folder.

There must be a workaround, you can check crash logs after crash. I will try to fix it, if you already fixed it, open a PR, it would be highly appreciated.

Android Support

This is only for Windows. You can check out UnityNativeFilePicker by Yasirkula. There are plenty of native plugins, but this one support iOS too.

Contacts

Srejon Khan

Indie Game Programmer

Mail: [email protected]

anotherfilebrowser's People

Contributors

srejonkhan avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.