#if UNITY_ANDROID && !UNITY_EDITOR using System; using System.Collections; using System.Collections.Generic; using System.IO; using UnityEngine; namespace TriLibCore.SFB { public class StandaloneFileBrowserAndroidListener : AndroidJavaProxy { private Action> _multipleFilesCallback; public StandaloneFileBrowserAndroidListener(Action> onMultipleFilesSelected) : base("com.sfb.standalonefilebrowser.StandaloneFileBrowserAndroidListener") { _multipleFilesCallback = onMultipleFilesSelected; } public void onFilesSelected(string filenames) { if (_multipleFilesCallback != null) { var files = filenames.Split('|'); var itemsWithStream = new ItemWithStream[files.Length]; for (var i = 0; i < itemsWithStream.Length; i++) { itemsWithStream[i] = new ItemWithStream() { Name = files[i] }; } _multipleFilesCallback(itemsWithStream); } } } public class StandaloneFileBrowserAndroid : IStandaloneFileBrowser { private AndroidJavaClass _standaloneFileBrowser; private AndroidJavaObject _activity; public StandaloneFileBrowserAndroid() { using (AndroidJavaObject unityClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer")) { _activity = unityClass.GetStatic("currentActivity"); _standaloneFileBrowser = new AndroidJavaClass("com.sfb.standalonefilebrowser.StandaloneFileBrowser"); } } public IList OpenFilePanel(string title, string directory, ExtensionFilter[] extensions, bool multiselect) { throw new NotSupportedException(); } public void OpenFilePanelAsync(string title, string directory, ExtensionFilter[] extensions, bool multiselect, Action> cb) { var listener = new StandaloneFileBrowserAndroidListener(cb); var args = new object[] {_activity, title, multiselect, listener}; _standaloneFileBrowser.CallStatic("showOpenFileDialog", args); } public IList OpenFolderPanel(string title, string directory, bool multiselect) { throw new NotSupportedException(); } public void OpenFolderPanelAsync(string title, string directory, bool multiselect, Action> cb) { throw new NotSupportedException(); } public ItemWithStream SaveFilePanel(string title, string directory, string defaultName, ExtensionFilter[] extensions) { throw new NotSupportedException(); } public void SaveFilePanelAsync(string title, string directory, string defaultName, ExtensionFilter[] extensions, Action cb) { throw new NotSupportedException(); } } } #endif