Skip to content

Commit a4baa2c

Browse files
committed
Fixed #18
1 parent a670cb9 commit a4baa2c

File tree

1 file changed

+23
-15
lines changed

1 file changed

+23
-15
lines changed

Assets/Plugins/SimpleFileBrowser/Scripts/FileBrowser.cs

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -243,10 +243,11 @@ private static FileBrowser Instance
243243
#pragma warning disable 0414
244244
[SerializeField]
245245
private QuickLink[] quickLinks;
246+
private static bool quickLinksInitialized;
246247
#pragma warning restore 0414
247248

248-
private HashSet<string> excludedExtensionsSet;
249-
private HashSet<string> addedQuickLinksSet;
249+
private readonly HashSet<string> excludedExtensionsSet = new HashSet<string>();
250+
private readonly HashSet<string> addedQuickLinksSet = new HashSet<string>();
250251

251252
[SerializeField]
252253
private bool generateQuickLinksForDrives = true;
@@ -489,9 +490,6 @@ private void Awake()
489490

490491
filenameInputField.onValidateInput += OnValidateFilenameInput;
491492

492-
InitializeQuickLinks();
493-
quickLinks = null;
494-
495493
allFilesFilter = new Filter( ALL_FILES_FILTER_TEXT );
496494
filters.Add( allFilesFilter );
497495

@@ -573,8 +571,6 @@ private void InitializeFiletypeIcons()
573571

574572
private void InitializeQuickLinks()
575573
{
576-
addedQuickLinksSet = new HashSet<string>();
577-
578574
Vector2 anchoredPos = new Vector2( 0f, -quickLinksContainer.sizeDelta.y );
579575

580576
#if !UNITY_EDITOR && UNITY_ANDROID
@@ -584,10 +580,6 @@ private void InitializeQuickLinks()
584580
if( generateQuickLinksForDrives )
585581
{
586582
#if !UNITY_EDITOR && UNITY_ANDROID
587-
// Fetching the list of external drives is only possible with the READ_EXTERNAL_STORAGE permission granted on Android
588-
if( AskPermissions )
589-
RequestPermission();
590-
591583
string drivesList = FileBrowserHelpers.AJC.CallStatic<string>( "GetExternalDrives" );
592584
if( drivesList != null && drivesList.Length > 0 )
593585
{
@@ -652,6 +644,8 @@ private void InitializeQuickLinks()
652644

653645
AddQuickLink( quickLink.icon, quickLink.name, quickLinkPath, ref anchoredPos );
654646
}
647+
648+
quickLinks = null;
655649
#endif
656650
#if !UNITY_EDITOR && UNITY_ANDROID
657651
}
@@ -983,6 +977,12 @@ public void Show( string initialPath )
983977
if( AskPermissions )
984978
RequestPermission();
985979

980+
if( !quickLinksInitialized )
981+
{
982+
quickLinksInitialized = true;
983+
InitializeQuickLinks();
984+
}
985+
986986
SelectedFile = null;
987987

988988
m_searchString = string.Empty;
@@ -1283,6 +1283,17 @@ public static bool AddQuickLink( string name, string path, Sprite icon = null )
12831283
return false;
12841284
#endif
12851285

1286+
if( !quickLinksInitialized )
1287+
{
1288+
quickLinksInitialized = true;
1289+
1290+
// Fetching the list of external drives is only possible with the READ_EXTERNAL_STORAGE permission granted on Android
1291+
if( AskPermissions )
1292+
RequestPermission();
1293+
1294+
Instance.InitializeQuickLinks();
1295+
}
1296+
12861297
Vector2 anchoredPos = new Vector2( 0f, -Instance.quickLinksContainer.sizeDelta.y );
12871298

12881299
if( Instance.AddQuickLink( icon, name, path, ref anchoredPos ) )
@@ -1296,10 +1307,7 @@ public static bool AddQuickLink( string name, string path, Sprite icon = null )
12961307

12971308
public static void SetExcludedExtensions( params string[] excludedExtensions )
12981309
{
1299-
if( Instance.excludedExtensionsSet == null )
1300-
Instance.excludedExtensionsSet = new HashSet<string>();
1301-
else
1302-
Instance.excludedExtensionsSet.Clear();
1310+
Instance.excludedExtensionsSet.Clear();
13031311

13041312
if( excludedExtensions != null )
13051313
{

0 commit comments

Comments
 (0)