-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileBrowser.cs
More file actions
76 lines (64 loc) · 2.42 KB
/
Copy pathFileBrowser.cs
File metadata and controls
76 lines (64 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
using System;
using UnityEngine;
namespace NativeFileBrowser
{
// any/all settings are allowed to be null
public struct FileBrowserSettings
{
public DialogKind DialogKind;
public MultiSelectKind MultiSelectKind;
// Title on MacOS sets NSOpenPanel.message, not title (because title is no longer displayed)
public string Title;
// Both Windows and Linux (GTK3) documentation strongly discourages setting InitialFolder,
// because the previous folder the user selected is remembered. Oh well. It's here if you want it.
public string InitialFolder;
public FileExtensionFilter[] FileExtensionFilters;
}
// any/all settings are allowed to be null
public struct FileExtensionFilter
{
// Name is ignored on MacOS
// Windows automatically displays Patterns after Name (e.g. "text file (*.txt;*.md)"), but Linux (GTK3) does not,
// so this library automatically appends $" ({string.Join(", ", Patterns)})" to Name on Linux (GTK3).
public string Name;
// Patterns must begin with "*." on MacOS (the MacOS API expects a string like "txt"
// to be provided here, so this library strips a "*." prefix off this field)
public string[] Patterns;
// MimeTypes is ignored on Windows and MacOS
public string[] MimeTypes;
public FileExtensionFilter(string name, string[] patterns, string[] mimeTypes)
{
Name = name;
Patterns = patterns;
MimeTypes = mimeTypes;
}
}
public enum DialogKind
{
File,
Folder,
}
public enum MultiSelectKind
{
Single,
Multiple,
}
public static class FileBrowser
{
// returns an empty array on cancel
public static string[] Pick(FileBrowserSettings settings)
{
switch (Application.platform)
{
case RuntimePlatform.WindowsEditor or RuntimePlatform.WindowsPlayer:
return WindowsCOMFileBrowser.Pick(settings);
case RuntimePlatform.OSXEditor or RuntimePlatform.OSXPlayer:
return MacOpenPanel.Pick(settings);
case RuntimePlatform.LinuxEditor or RuntimePlatform.LinuxPlayer:
return Gtk3FileDialog.Pick(settings);
default:
return Array.Empty<string>();
}
}
}
}