Skip to content

Commit

Permalink
- Moved most UnityEvent registrations to the code (it fixes InputFiel…
Browse files Browse the repository at this point in the history
…d.OnEndEdit being changed to InputField.OnSubmit on latest Unity versions, see: yasirkula/UnityTextToTextMeshProUpgradeTool#2)

- Minor memory optimization in RecycledListView
- Attempted to simplify the example code
  • Loading branch information
yasirkula committed Feb 10, 2024
1 parent c84d108 commit 544dd06
Show file tree
Hide file tree
Showing 10 changed files with 136 additions and 287 deletions.
48 changes: 28 additions & 20 deletions .github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,16 +254,18 @@ public class FileBrowserTest : MonoBehaviour
// Path: C:\Users
// Icon: default (folder icon)
FileBrowser.AddQuickLink( "Users", "C:\\Users", null );

// !!! Uncomment any of the examples below to show the file browser !!!
// Show a save file dialog
// Example 1: Show a save file dialog using callback approach
// onSuccess event: not registered (which means this dialog is pretty useless)
// onCancel event: not registered
// Save file/folder: file, Allow multiple selection: false
// Initial path: "C:\", Initial filename: "Screenshot.png"
// Title: "Save As", Submit button text: "Save"
// FileBrowser.ShowSaveDialog( null, null, FileBrowser.PickMode.Files, false, "C:\\", "Screenshot.png", "Save As", "Save" );
// Show a select folder dialog
// Example 2: Show a select folder dialog using callback approach
// onSuccess event: print the selected folder's path
// onCancel event: print "Canceled"
// Load file/folder: folder, Allow multiple selection: false
Expand All @@ -273,36 +275,42 @@ public class FileBrowserTest : MonoBehaviour
// () => { Debug.Log( "Canceled" ); },
// FileBrowser.PickMode.Folders, false, null, null, "Select Folder", "Select" );
// Coroutine example
StartCoroutine( ShowLoadDialogCoroutine() );
// Example 3: Show a select file dialog using coroutine approach
// StartCoroutine( ShowLoadDialogCoroutine() );
}

IEnumerator ShowLoadDialogCoroutine()
{
// Show a load file dialog and wait for a response from user
// Load file/folder: both, Allow multiple selection: true
// Load file/folder: file, Allow multiple selection: true
// Initial path: default (Documents), Initial filename: empty
// Title: "Load File", Submit button text: "Load"
yield return FileBrowser.WaitForLoadDialog( FileBrowser.PickMode.FilesAndFolders, true, null, null, "Load Files and Folders", "Load" );
yield return FileBrowser.WaitForLoadDialog( FileBrowser.PickMode.Files, true, null, null, "Select Files", "Load" );

// Dialog is closed
// Print whether the user has selected some files/folders or cancelled the operation (FileBrowser.Success)
// Print whether the user has selected some files or cancelled the operation (FileBrowser.Success)
Debug.Log( FileBrowser.Success );

if( FileBrowser.Success )
{
// Print paths of the selected files (FileBrowser.Result) (null, if FileBrowser.Success is false)
for( int i = 0; i < FileBrowser.Result.Length; i++ )
Debug.Log( FileBrowser.Result[i] );

// Read the bytes of the first file via FileBrowserHelpers
// Contrary to File.ReadAllBytes, this function works on Android 10+, as well
byte[] bytes = FileBrowserHelpers.ReadBytesFromFile( FileBrowser.Result[0] );

// Or, copy the first file to persistentDataPath
string destinationPath = Path.Combine( Application.persistentDataPath, FileBrowserHelpers.GetFilename( FileBrowser.Result[0] ) );
FileBrowserHelpers.CopyFile( FileBrowser.Result[0], destinationPath );
}
OnFilesSelected( FileBrowser.Result ); // FileBrowser.Result is null, if FileBrowser.Success is false
}

void OnFilesSelected( string[] filePaths )
{
// Print paths of the selected files
for( int i = 0; i < filePaths.Length; i++ )
Debug.Log( filePaths[i] );

// Get the file path of the first selected file
string filePath = filePaths[0];

// Read the bytes of the first file via FileBrowserHelpers
// Contrary to File.ReadAllBytes, this function works on Android 10+, as well
byte[] bytes = FileBrowserHelpers.ReadBytesFromFile( filePath );

// Or, copy the first file to persistentDataPath
string destinationPath = Path.Combine( Application.persistentDataPath, FileBrowserHelpers.GetFilename( filePath ) );
FileBrowserHelpers.CopyFile( filePath, destinationPath );
}
}
```
2 changes: 1 addition & 1 deletion Plugins/SimpleFileBrowser/README.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
= Simple File Browser (v1.6.4) =
= Simple File Browser (v1.6.5) =

Documentation: https://github.com/yasirkula/UnitySimpleFileBrowser
FAQ: https://github.com/yasirkula/UnitySimpleFileBrowser#faq
Expand Down
Loading

0 comments on commit 544dd06

Please sign in to comment.