Skip to content

Commit 544dd06

Browse files
committed
- Moved most UnityEvent registrations to the code (it fixes InputField.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
1 parent c84d108 commit 544dd06

File tree

10 files changed

+136
-287
lines changed

10 files changed

+136
-287
lines changed

.github/README.md

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -254,16 +254,18 @@ public class FileBrowserTest : MonoBehaviour
254254
// Path: C:\Users
255255
// Icon: default (folder icon)
256256
FileBrowser.AddQuickLink( "Users", "C:\\Users", null );
257+
258+
// !!! Uncomment any of the examples below to show the file browser !!!
257259
258-
// Show a save file dialog
260+
// Example 1: Show a save file dialog using callback approach
259261
// onSuccess event: not registered (which means this dialog is pretty useless)
260262
// onCancel event: not registered
261263
// Save file/folder: file, Allow multiple selection: false
262264
// Initial path: "C:\", Initial filename: "Screenshot.png"
263265
// Title: "Save As", Submit button text: "Save"
264266
// FileBrowser.ShowSaveDialog( null, null, FileBrowser.PickMode.Files, false, "C:\\", "Screenshot.png", "Save As", "Save" );
265267
266-
// Show a select folder dialog
268+
// Example 2: Show a select folder dialog using callback approach
267269
// onSuccess event: print the selected folder's path
268270
// onCancel event: print "Canceled"
269271
// Load file/folder: folder, Allow multiple selection: false
@@ -273,36 +275,42 @@ public class FileBrowserTest : MonoBehaviour
273275
// () => { Debug.Log( "Canceled" ); },
274276
// FileBrowser.PickMode.Folders, false, null, null, "Select Folder", "Select" );
275277
276-
// Coroutine example
277-
StartCoroutine( ShowLoadDialogCoroutine() );
278+
// Example 3: Show a select file dialog using coroutine approach
279+
// StartCoroutine( ShowLoadDialogCoroutine() );
278280
}
279281

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

288290
// Dialog is closed
289-
// Print whether the user has selected some files/folders or cancelled the operation (FileBrowser.Success)
291+
// Print whether the user has selected some files or cancelled the operation (FileBrowser.Success)
290292
Debug.Log( FileBrowser.Success );
291293

292294
if( FileBrowser.Success )
293-
{
294-
// Print paths of the selected files (FileBrowser.Result) (null, if FileBrowser.Success is false)
295-
for( int i = 0; i < FileBrowser.Result.Length; i++ )
296-
Debug.Log( FileBrowser.Result[i] );
297-
298-
// Read the bytes of the first file via FileBrowserHelpers
299-
// Contrary to File.ReadAllBytes, this function works on Android 10+, as well
300-
byte[] bytes = FileBrowserHelpers.ReadBytesFromFile( FileBrowser.Result[0] );
301-
302-
// Or, copy the first file to persistentDataPath
303-
string destinationPath = Path.Combine( Application.persistentDataPath, FileBrowserHelpers.GetFilename( FileBrowser.Result[0] ) );
304-
FileBrowserHelpers.CopyFile( FileBrowser.Result[0], destinationPath );
305-
}
295+
OnFilesSelected( FileBrowser.Result ); // FileBrowser.Result is null, if FileBrowser.Success is false
296+
}
297+
298+
void OnFilesSelected( string[] filePaths )
299+
{
300+
// Print paths of the selected files
301+
for( int i = 0; i < filePaths.Length; i++ )
302+
Debug.Log( filePaths[i] );
303+
304+
// Get the file path of the first selected file
305+
string filePath = filePaths[0];
306+
307+
// Read the bytes of the first file via FileBrowserHelpers
308+
// Contrary to File.ReadAllBytes, this function works on Android 10+, as well
309+
byte[] bytes = FileBrowserHelpers.ReadBytesFromFile( filePath );
310+
311+
// Or, copy the first file to persistentDataPath
312+
string destinationPath = Path.Combine( Application.persistentDataPath, FileBrowserHelpers.GetFilename( filePath ) );
313+
FileBrowserHelpers.CopyFile( filePath, destinationPath );
306314
}
307315
}
308316
```

Plugins/SimpleFileBrowser/README.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
= Simple File Browser (v1.6.4) =
1+
= Simple File Browser (v1.6.5) =
22

33
Documentation: https://github.com/yasirkula/UnitySimpleFileBrowser
44
FAQ: https://github.com/yasirkula/UnitySimpleFileBrowser#faq

0 commit comments

Comments
 (0)