Class StandaloneFileBrowser
Provides a platform-specific file browser interface for opening and saving files and folders using native dialogs. This static class delegates file browsing operations to an underlying platform‐ specific implementation of IStandaloneFileBrowser<T>.
Inherited Members
Namespace: TriLibCore.SFB
Assembly: Assembly-CSharp.dll
Syntax
public class StandaloneFileBrowser
Remarks
The StandaloneFileBrowser
class wraps various native file dialog implementations based on the
target platform (e.g., Unity Editor, Windows, Mac, Linux, Android, iOS, WebGL, UWP). At compile time,
the appropriate platform-specific implementation is assigned to the internal _platformWrapper
field.
If no implementation is available for the target platform, the file browsing operations will not function.
The class exposes both synchronous and asynchronous methods for opening files, opening folders, and saving files, with support for extension filters to limit file types. Asynchronous methods use callbacks to return user selections.
Methods
OpenFilePanel(string, string, string, bool)
Opens a native file dialog for selecting files.
Declaration
public static IList<ItemWithStream> OpenFilePanel(string title, string directory, string extension, bool multiselect)
Parameters
Type | Name | Description |
---|---|---|
string | title | The title of the dialog window. |
string | directory | The initial directory to display. |
string | extension | A string representing the allowed file extension (e.g., "png"). |
bool | multiselect | If |
Returns
Type | Description |
---|---|
IList<ItemWithStream> | An IList<T> containing the selected items, or an empty list if the dialog is cancelled. |
OpenFilePanel(string, string, ExtensionFilter[], bool)
Opens a native file dialog for selecting files.
Declaration
public static IList<ItemWithStream> OpenFilePanel(string title, string directory, ExtensionFilter[] extensions, bool multiselect)
Parameters
Type | Name | Description |
---|---|---|
string | title | The title of the dialog window. |
string | directory | The initial directory to display. |
ExtensionFilter[] | extensions | An array of ExtensionFilter objects specifying allowed file types (e.g.,
|
bool | multiselect | If |
Returns
Type | Description |
---|---|
IList<ItemWithStream> | An IList<T> containing the selected items, or an empty list if the dialog is cancelled. |
OpenFilePanelAsync(string, string, string, bool, Action<IList<ItemWithStream>>)
Opens a native file dialog asynchronously for selecting files.
Declaration
public static void OpenFilePanelAsync(string title, string directory, string extension, bool multiselect, Action<IList<ItemWithStream>> cb)
Parameters
Type | Name | Description |
---|---|---|
string | title | The title of the dialog window. |
string | directory | The initial directory to display. |
string | extension | A string representing the allowed file extension (e.g., "png"). |
bool | multiselect | If |
Action<IList<ItemWithStream>> | cb | A callback action to be invoked with the list of selected items (or an empty list if cancelled). |
OpenFilePanelAsync(string, string, ExtensionFilter[], bool, Action<IList<ItemWithStream>>)
Opens a native file dialog asynchronously for selecting files.
Declaration
public static void OpenFilePanelAsync(string title, string directory, ExtensionFilter[] extensions, bool multiselect, Action<IList<ItemWithStream>> cb)
Parameters
Type | Name | Description |
---|---|---|
string | title | The title of the dialog window. |
string | directory | The initial directory to display. |
ExtensionFilter[] | extensions | An array of ExtensionFilter objects specifying allowed file types. |
bool | multiselect | If |
Action<IList<ItemWithStream>> | cb | A callback action to be invoked with the list of selected items (or an empty list if cancelled). |
OpenFolderPanel(string, string, bool)
Opens a native folder dialog for selecting a folder.
Declaration
public static IList<ItemWithStream> OpenFolderPanel(string title, string directory, bool multiselect)
Parameters
Type | Name | Description |
---|---|---|
string | title | The title of the folder dialog. |
string | directory | The initial directory to display. |
bool | multiselect | If |
Returns
Type | Description |
---|---|
IList<ItemWithStream> | An IList<T> containing the selected folder(s), or an empty list if cancelled. |
OpenFolderPanelAsync(string, string, bool, Action<IList<ItemWithStream>>)
Opens a native folder dialog asynchronously for selecting a folder.
Declaration
public static void OpenFolderPanelAsync(string title, string directory, bool multiselect, Action<IList<ItemWithStream>> cb)
Parameters
Type | Name | Description |
---|---|---|
string | title | The title of the folder dialog. |
string | directory | The initial directory to display. |
bool | multiselect | If |
Action<IList<ItemWithStream>> | cb | A callback action to be invoked with the list of selected folder items (or an empty list if cancelled). |
SaveFilePanel(string, string, string, string)
Opens a native save file dialog.
Declaration
public static ItemWithStream SaveFilePanel(string title, string directory, string defaultName, string extension)
Parameters
Type | Name | Description |
---|---|---|
string | title | The title of the save dialog. |
string | directory | The initial directory to display. |
string | defaultName | The default file name to pre-populate in the dialog. |
string | extension | A string representing the allowed file extension (e.g., "txt"). |
Returns
Type | Description |
---|---|
ItemWithStream | An ItemWithStream representing the chosen file, or |
SaveFilePanel(string, string, string, ExtensionFilter[])
Opens a native save file dialog.
Declaration
public static ItemWithStream SaveFilePanel(string title, string directory, string defaultName, ExtensionFilter[] extensions)
Parameters
Type | Name | Description |
---|---|---|
string | title | The title of the save dialog. |
string | directory | The initial directory to display. |
string | defaultName | The default file name to pre-populate in the dialog. |
ExtensionFilter[] | extensions | An array of ExtensionFilter objects specifying allowed file types. |
Returns
Type | Description |
---|---|
ItemWithStream | An ItemWithStream representing the chosen file, or |
SaveFilePanelAsync(string, string, string, string, Action<ItemWithStream>, byte[])
Opens a native save file dialog asynchronously.
Declaration
public static void SaveFilePanelAsync(string title, string directory, string defaultName, string extension, Action<ItemWithStream> cb, byte[] data = null)
Parameters
Type | Name | Description |
---|---|---|
string | title | The title of the save file dialog. |
string | directory | The initial directory to display. |
string | defaultName | The default file name to pre-populate in the dialog. |
string | extension | A string representing the allowed file extension. |
Action<ItemWithStream> | cb | A callback action that is invoked with the selected file item, or |
byte[] | data | Optional data to be saved (used on WebGL platform). |
SaveFilePanelAsync(string, string, string, ExtensionFilter[], Action<ItemWithStream>, byte[])
Opens a native save file dialog asynchronously.
Declaration
public static void SaveFilePanelAsync(string title, string directory, string defaultName, ExtensionFilter[] extensions, Action<ItemWithStream> cb, byte[] data = null)
Parameters
Type | Name | Description |
---|---|---|
string | title | The title of the save file dialog. |
string | directory | The initial directory to display. |
string | defaultName | The default file name to pre-populate in the dialog. |
ExtensionFilter[] | extensions | An array of ExtensionFilter objects specifying allowed file types. |
Action<ItemWithStream> | cb | A callback action that is invoked with the selected file item, or |
byte[] | data | Optional data to be saved (used on WebGL platform). |