Tanoda
StandaloneFileBrowser.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3
4namespace TriLibCore.SFB
5{
8 {
9#if UNITY_EDITOR
10#if UNITY_EDITOR_OSX
11 private static readonly IStandaloneFileBrowser<ItemWithStream> _platformWrapper =
12 new StandaloneFileBrowserMac();
13 #elif UNITY_EDITOR_LINUX
14 private static readonly IStandaloneFileBrowser<ItemWithStream> _platformWrapper =
15 new StandaloneFileBrowserLinux();
16 #elif UNITY_EDITOR_WIN
17 private static readonly IStandaloneFileBrowser<ItemWithStream> _platformWrapper =
18 new StandaloneFileBrowserWindows();
19#else
20 private static IStandaloneFileBrowser<ItemWithStream> _platformWrapper = new StandaloneFileBrowserEditor();
21#endif
22#else
23 #if UNITY_WSA
24 private static readonly IStandaloneFileBrowser<ItemWithStream> _platformWrapper =
25 new StandaloneFileBrowserWinRT();
26 #elif UNITY_ANDROID
27 private static readonly IStandaloneFileBrowser<ItemWithStream> _platformWrapper =
28 new StandaloneFileBrowserAndroid();
29 #elif UNITY_WEBGL
30 private static readonly IStandaloneFileBrowser<ItemWithStream> _platformWrapper =
31 new StandaloneFileBrowserWebGL();
32 #elif UNITY_STANDALONE_OSX
33 private static readonly IStandaloneFileBrowser<ItemWithStream> _platformWrapper =
34 new StandaloneFileBrowserMac();
35 #elif UNITY_IOS
36 private static readonly IStandaloneFileBrowser<ItemWithStream> _platformWrapper =
37 new StandaloneFileBrowserIOS();
38 #elif UNITY_STANDALONE_WIN
39 private static readonly IStandaloneFileBrowser<ItemWithStream> _platformWrapper =
40 new StandaloneFileBrowserWindows();
41 #elif UNITY_STANDALONE_LINUX
42 private static readonly IStandaloneFileBrowser<ItemWithStream> _platformWrapper =
43 new StandaloneFileBrowserLinux();
44 #else
45 private static readonly IStandaloneFileBrowser<ItemWithStream> _platformWrapper = null;
46 #endif
47#endif
56 public static IList<ItemWithStream> OpenFilePanel(string title, string directory, string extension,
57 bool multiselect)
58 {
59 var extensions = string.IsNullOrEmpty(extension) ? null : new[] {new ExtensionFilter("", extension)};
60 return OpenFilePanel(title, directory, extensions, multiselect);
61 }
62
71 public static IList<ItemWithStream> OpenFilePanel(string title, string directory, ExtensionFilter[] extensions,
72 bool multiselect)
73 {
74 return _platformWrapper.OpenFilePanel(title, directory, extensions, multiselect);
75 }
76
85 public static void OpenFilePanelAsync(string title, string directory, string extension, bool multiselect,
86 Action<IList<ItemWithStream>> cb)
87 {
88 var extensions = string.IsNullOrEmpty(extension) ? null : new[] {new ExtensionFilter("", extension)};
89 OpenFilePanelAsync(title, directory, extensions, multiselect, cb);
90 }
91
100 public static void OpenFilePanelAsync(string title, string directory, ExtensionFilter[] extensions,
101 bool multiselect, Action<IList<ItemWithStream>> cb)
102 {
103 _platformWrapper.OpenFilePanelAsync(title, directory, extensions, multiselect, cb);
104 }
105
113 public static IList<ItemWithStream> OpenFolderPanel(string title, string directory, bool multiselect)
114 {
115 return _platformWrapper.OpenFolderPanel(title, directory, multiselect);
116 }
117
125 public static void OpenFolderPanelAsync(string title, string directory, bool multiselect,
126 Action<IList<ItemWithStream>> cb)
127 {
128 _platformWrapper.OpenFolderPanelAsync(title, directory, multiselect, cb);
129 }
130
139 public static ItemWithStream SaveFilePanel(string title, string directory, string defaultName, string extension)
140 {
141 var extensions = string.IsNullOrEmpty(extension) ? null : new[] {new ExtensionFilter("", extension)};
142 return SaveFilePanel(title, directory, defaultName, extensions);
143 }
144
153 public static ItemWithStream SaveFilePanel(string title, string directory, string defaultName,
154 ExtensionFilter[] extensions)
155 {
156 return _platformWrapper.SaveFilePanel(title, directory, defaultName, extensions);
157 }
158
167 public static void SaveFilePanelAsync(string title, string directory, string defaultName, string extension,
168 Action<ItemWithStream> cb)
169 {
170 var extensions = string.IsNullOrEmpty(extension) ? null : new[] {new ExtensionFilter("", extension)};
171 SaveFilePanelAsync(title, directory, defaultName, extensions, cb);
172 }
173
182 public static void SaveFilePanelAsync(string title, string directory, string defaultName,
183 ExtensionFilter[] extensions, Action<ItemWithStream> cb)
184 {
185 _platformWrapper.SaveFilePanelAsync(title, directory, defaultName, extensions, cb);
186 }
187 }
188}
Represents a platform-specific file with a Stream.
Represents a platform-specific file browser.
static void OpenFilePanelAsync(string title, string directory, string extension, bool multiselect, Action< IList< ItemWithStream > > cb)
Native open file dialog async
static void OpenFolderPanelAsync(string title, string directory, bool multiselect, Action< IList< ItemWithStream > > cb)
Native open folder dialog async
static ItemWithStream SaveFilePanel(string title, string directory, string defaultName, ExtensionFilter[] extensions)
Native save file dialog
static IList< ItemWithStream > OpenFilePanel(string title, string directory, ExtensionFilter[] extensions, bool multiselect)
Native open file dialog
static void SaveFilePanelAsync(string title, string directory, string defaultName, string extension, Action< ItemWithStream > cb)
Native save file dialog async
static void SaveFilePanelAsync(string title, string directory, string defaultName, ExtensionFilter[] extensions, Action< ItemWithStream > cb)
Native save file dialog async
static IList< ItemWithStream > OpenFolderPanel(string title, string directory, bool multiselect)
Native open folder dialog
static IList< ItemWithStream > OpenFilePanel(string title, string directory, string extension, bool multiselect)
Native open file dialog
static void OpenFilePanelAsync(string title, string directory, ExtensionFilter[] extensions, bool multiselect, Action< IList< ItemWithStream > > cb)
Native open file dialog async
static ItemWithStream SaveFilePanel(string title, string directory, string defaultName, string extension)
Native save file dialog
Represents a series of methods to operate platform-specific file pickers.
Represents a file picker extension filter.