com.koiusa.filepicker
v0.4.1
Published
Coroutine-based native open, save, and document-export APIs for Unity Editor, Windows, macOS, and iOS, with an optional persistent file library.
Readme
Koiusa File Picker
Provides coroutine-based APIs for opening files, choosing save destinations, and exporting documents in Unity Editor, Windows, macOS, and iOS. Application-specific processing such as archive extraction is intentionally handled by the consuming project.
Dependencies
- Unity 6000.3 or newer
- No additional UPM package dependencies
Opening a file
var request = FilePicker.Pick(new FilePickerOptions
{
Title = "Select model",
InitialDirectory = directory,
Filters = new[] { new FilePickerFilter("MMD model", "pmx", "pmd") }
});
yield return request;
if (request.Status == FilePickerStatus.Selected)
Debug.Log(request.Path);
else if (request.Status == FilePickerStatus.Failed)
Debug.LogException(request.Error);Saving a file
Save uses the same FilePickerRequest and FilePickerStatus coroutine pattern
as Pick. On Windows, macOS, and in the Unity Editor, callers can request only a
destination and write after selection:
var request = FilePicker.Save(new FilePickerSaveOptions
{
Title = "Export configuration",
InitialDirectory = directory,
SuggestedFileName = "offaxisprojection.json",
DefaultExtension = "json",
Filters = new[] { new FilePickerFilter("JSON configuration", "json") }
});
yield return request;
if (request.Status == FilePickerStatus.Selected)
ExportConfiguration(request.Path);
else if (request.Status == FilePickerStatus.Failed)
Debug.LogException(request.Error);Native save dialogs confirm replacement of existing files, do not change the process current directory, and remember the last selected directory.
Writing or exporting through the request
Set WriteToStream to let the request perform the write, or set SourcePath to
export an existing file. These properties are optional on desktop and in the
Editor. Do not specify both.
var request = FilePicker.Save(new FilePickerSaveOptions
{
SuggestedFileName = "configuration.json",
DefaultExtension = "json",
WriteToStream = stream => WriteConfiguration(stream)
});
yield return request;iOS does not expose an arbitrary writable destination path. Consequently, iOS
requires either WriteToStream or SourcePath and presents the platform's
standard document export picker. A successful request means the prepared
document was exported; callers must not attempt to write to the returned path.
Status and compatibility
Both operations return FilePickerRequest with one of these states:
Pending: the operation is still runningSelected: a file or destination was selected, or an iOS export completedCancelled: the user dismissed the dialogFailed: the operation failed; details are available throughError
The public entry point remains the single FilePicker facade. Open and save
options and provider contracts are separate, so existing implementations of
IFilePickerProvider remain source-compatible. Providers that support saving
additionally implement IFilePickerSaveProvider.
File library
FileLibrary provides an optional persistent library of categorized file
references. On iOS it imports files into persistentDataPath; a configurable
category can import a directory tree to preserve sidecar resources. Pass
directoryImportRoot when the directory to preserve is above the selected
file's immediate parent (for example, the root of an extracted model archive).
The selected file's relative path within that root is retained in the imported
library entry.
