From 544dd06856a1a7359ed9aff332f950d8a9849219 Mon Sep 17 00:00:00 2001 From: yasirkula Date: Sat, 10 Feb 2024 14:08:30 +0300 Subject: [PATCH] - Moved most UnityEvent registrations to the code (it fixes InputField.OnEndEdit being changed to InputField.OnSubmit on latest Unity versions, see: https://github.com/yasirkula/UnityTextToTextMeshProUpgradeTool/issues/2) - Minor memory optimization in RecycledListView - Attempted to simplify the example code --- .github/README.md | 48 ++-- Plugins/SimpleFileBrowser/README.txt | 2 +- .../Resources/SimpleFileBrowserCanvas.prefab | 253 ++---------------- .../SimpleFileBrowser/Scripts/FileBrowser.cs | 40 ++- .../FileBrowserAccessRestrictedPanel.cs | 7 +- .../Scripts/FileBrowserContextMenu.cs | 19 +- ...leBrowserFileOperationConfirmationPanel.cs | 36 +-- .../Scripts/FileBrowserRenamedItem.cs | 7 +- .../RecycledListView.cs | 9 +- package.json | 2 +- 10 files changed, 136 insertions(+), 287 deletions(-) diff --git a/.github/README.md b/.github/README.md index c8806ac..747c7cc 100644 --- a/.github/README.md +++ b/.github/README.md @@ -254,8 +254,10 @@ 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 @@ -263,7 +265,7 @@ public class FileBrowserTest : MonoBehaviour // 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 @@ -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 ); } } ``` diff --git a/Plugins/SimpleFileBrowser/README.txt b/Plugins/SimpleFileBrowser/README.txt index 6d16f0d..0dea457 100644 --- a/Plugins/SimpleFileBrowser/README.txt +++ b/Plugins/SimpleFileBrowser/README.txt @@ -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 diff --git a/Plugins/SimpleFileBrowser/Resources/SimpleFileBrowserCanvas.prefab b/Plugins/SimpleFileBrowser/Resources/SimpleFileBrowserCanvas.prefab index 398dcee..b91100b 100644 --- a/Plugins/SimpleFileBrowser/Resources/SimpleFileBrowserCanvas.prefab +++ b/Plugins/SimpleFileBrowser/Resources/SimpleFileBrowserCanvas.prefab @@ -2201,18 +2201,7 @@ MonoBehaviour: m_TargetGraphic: {fileID: 114000010862285312} m_OnClick: m_PersistentCalls: - m_Calls: - - m_Target: {fileID: 114000013689746302} - m_MethodName: OnBackButtonPressed - m_Mode: 1 - m_Arguments: - m_ObjectArgument: {fileID: 0} - m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine - m_IntArgument: 0 - m_FloatArgument: 0 - m_StringArgument: - m_BoolArgument: 0 - m_CallState: 2 + m_Calls: [] m_TypeName: UnityEngine.UI.Button+ButtonClickedEvent, UnityEngine.UI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null --- !u!114 &114000010382772448 @@ -2361,18 +2350,7 @@ MonoBehaviour: Culture=neutral, PublicKeyToken=null m_OnValueChanged: m_PersistentCalls: - m_Calls: - - m_Target: {fileID: 114000013689746302} - m_MethodName: OnSearchStringChanged - m_Mode: 0 - m_Arguments: - m_ObjectArgument: {fileID: 0} - m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine - m_IntArgument: 0 - m_FloatArgument: 0 - m_StringArgument: - m_BoolArgument: 0 - m_CallState: 2 + m_Calls: [] m_TypeName: UnityEngine.UI.InputField+OnChangeEvent, UnityEngine.UI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null m_CaretColor: {r: 0.19607843, g: 0.19607843, b: 0.19607843, a: 1} @@ -2655,18 +2633,7 @@ MonoBehaviour: m_Group: {fileID: 0} onValueChanged: m_PersistentCalls: - m_Calls: - - m_Target: {fileID: 114000013689746302} - m_MethodName: OnShowHiddenFilesToggleChanged - m_Mode: 1 - m_Arguments: - m_ObjectArgument: {fileID: 0} - m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine - m_IntArgument: 0 - m_FloatArgument: 0 - m_StringArgument: - m_BoolArgument: 0 - m_CallState: 2 + m_Calls: [] m_TypeName: UnityEngine.UI.Toggle+ToggleEvent, UnityEngine.UI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null m_IsOn: 0 @@ -2969,18 +2936,7 @@ MonoBehaviour: m_TargetGraphic: {fileID: 114000013270539482} m_OnClick: m_PersistentCalls: - m_Calls: - - m_Target: {fileID: 114000013689746302} - m_MethodName: OnForwardButtonPressed - m_Mode: 1 - m_Arguments: - m_ObjectArgument: {fileID: 0} - m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine - m_IntArgument: 0 - m_FloatArgument: 0 - m_StringArgument: - m_BoolArgument: 0 - m_CallState: 2 + m_Calls: [] m_TypeName: UnityEngine.UI.Button+ButtonClickedEvent, UnityEngine.UI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null --- !u!114 &114000012182958498 @@ -3324,18 +3280,7 @@ MonoBehaviour: m_TargetGraphic: {fileID: 114000011782691694} m_OnClick: m_PersistentCalls: - m_Calls: - - m_Target: {fileID: 114000013689746302} - m_MethodName: OnCancelButtonClicked - m_Mode: 1 - m_Arguments: - m_ObjectArgument: {fileID: 0} - m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine - m_IntArgument: 0 - m_FloatArgument: 0 - m_StringArgument: - m_BoolArgument: 0 - m_CallState: 2 + m_Calls: [] m_TypeName: UnityEngine.UI.Button+ButtonClickedEvent, UnityEngine.UI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null --- !u!114 &114000013266928238 @@ -3574,18 +3519,7 @@ MonoBehaviour: m_CharacterLimit: 0 m_OnEndEdit: m_PersistentCalls: - m_Calls: - - m_Target: {fileID: 114000013689746302} - m_MethodName: OnPathChanged - m_Mode: 0 - m_Arguments: - m_ObjectArgument: {fileID: 0} - m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine - m_IntArgument: 0 - m_FloatArgument: 0 - m_StringArgument: - m_BoolArgument: 0 - m_CallState: 2 + m_Calls: [] m_TypeName: UnityEngine.UI.InputField+SubmitEvent, UnityEngine.UI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null m_OnValueChanged: @@ -3954,7 +3888,9 @@ MonoBehaviour: filenameImage: {fileID: 114000011987843938} filtersDropdown: {fileID: 114000014203150582} showHiddenFilesToggle: {fileID: 114000011511084512} + submitButton: {fileID: 114000014005904746} submitButtonText: {fileID: 114000013382491478} + cancelButton: {fileID: 114000013207029700} allButtons: - {fileID: 114000014005904746} - {fileID: 114000013207029700} @@ -4035,18 +3971,7 @@ MonoBehaviour: m_TargetGraphic: {fileID: 114000013476289924} m_OnClick: m_PersistentCalls: - m_Calls: - - m_Target: {fileID: 114000013689746302} - m_MethodName: OnUpButtonPressed - m_Mode: 1 - m_Arguments: - m_ObjectArgument: {fileID: 0} - m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine - m_IntArgument: 0 - m_FloatArgument: 0 - m_StringArgument: - m_BoolArgument: 0 - m_CallState: 2 + m_Calls: [] m_TypeName: UnityEngine.UI.Button+ButtonClickedEvent, UnityEngine.UI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null --- !u!114 &114000013840550810 @@ -4165,18 +4090,7 @@ MonoBehaviour: m_TargetGraphic: {fileID: 114000012871191802} m_OnClick: m_PersistentCalls: - m_Calls: - - m_Target: {fileID: 114000013689746302} - m_MethodName: OnSubmitButtonClicked - m_Mode: 1 - m_Arguments: - m_ObjectArgument: {fileID: 0} - m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine - m_IntArgument: 0 - m_FloatArgument: 0 - m_StringArgument: - m_BoolArgument: 0 - m_CallState: 2 + m_Calls: [] m_TypeName: UnityEngine.UI.Button+ButtonClickedEvent, UnityEngine.UI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null --- !u!114 &114000014168093110 @@ -4260,18 +4174,7 @@ MonoBehaviour: m_Image: {fileID: 0} m_OnValueChanged: m_PersistentCalls: - m_Calls: - - m_Target: {fileID: 114000013689746302} - m_MethodName: OnFilterChanged - m_Mode: 1 - m_Arguments: - m_ObjectArgument: {fileID: 0} - m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine - m_IntArgument: 0 - m_FloatArgument: 0 - m_StringArgument: - m_BoolArgument: 0 - m_CallState: 2 + m_Calls: [] m_TypeName: UnityEngine.UI.Dropdown+DropdownEvent, UnityEngine.UI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null --- !u!114 &114000014287647564 @@ -4570,18 +4473,7 @@ MonoBehaviour: m_TargetGraphic: {fileID: 114398207703756688} m_OnClick: m_PersistentCalls: - m_Calls: - - m_Target: {fileID: 114966523907925700} - m_MethodName: YesButtonClicked - m_Mode: 1 - m_Arguments: - m_ObjectArgument: {fileID: 0} - m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine - m_IntArgument: 0 - m_FloatArgument: 0 - m_StringArgument: - m_BoolArgument: 0 - m_CallState: 2 + m_Calls: [] m_TypeName: UnityEngine.UI.Button+ButtonClickedEvent, UnityEngine.UI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null --- !u!114 &114094015756707196 @@ -4775,18 +4667,7 @@ MonoBehaviour: m_TargetGraphic: {fileID: 114979685639805002} m_OnClick: m_PersistentCalls: - m_Calls: - - m_Target: {fileID: 114581495326313396} - m_MethodName: OnDeleteButtonClicked - m_Mode: 1 - m_Arguments: - m_ObjectArgument: {fileID: 0} - m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine - m_IntArgument: 0 - m_FloatArgument: 0 - m_StringArgument: - m_BoolArgument: 0 - m_CallState: 2 + m_Calls: [] m_TypeName: UnityEngine.UI.Button+ButtonClickedEvent, UnityEngine.UI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null --- !u!114 &114144994822079520 @@ -4827,18 +4708,7 @@ MonoBehaviour: m_TargetGraphic: {fileID: 114938008637452676} m_OnClick: m_PersistentCalls: - m_Calls: - - m_Target: {fileID: 114000013689746302} - m_MethodName: OnMoreOptionsButtonClicked - m_Mode: 1 - m_Arguments: - m_ObjectArgument: {fileID: 0} - m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine - m_IntArgument: 0 - m_FloatArgument: 0 - m_StringArgument: - m_BoolArgument: 0 - m_CallState: 2 + m_Calls: [] m_TypeName: UnityEngine.UI.Button+ButtonClickedEvent, UnityEngine.UI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null --- !u!114 &114161038201393556 @@ -5478,18 +5348,7 @@ MonoBehaviour: m_TargetGraphic: {fileID: 114280106910162478} m_OnClick: m_PersistentCalls: - m_Calls: - - m_Target: {fileID: 114581495326313396} - m_MethodName: OnCreateFolderButtonClicked - m_Mode: 1 - m_Arguments: - m_ObjectArgument: {fileID: 0} - m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine - m_IntArgument: 0 - m_FloatArgument: 0 - m_StringArgument: - m_BoolArgument: 0 - m_CallState: 2 + m_Calls: [] m_TypeName: UnityEngine.UI.Button+ButtonClickedEvent, UnityEngine.UI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null --- !u!114 &114351978993012462 @@ -5581,18 +5440,7 @@ MonoBehaviour: m_TargetGraphic: {fileID: 114582105816722586} m_OnClick: m_PersistentCalls: - m_Calls: - - m_Target: {fileID: 114581495326313396} - m_MethodName: OnDeselectAllButtonClicked - m_Mode: 1 - m_Arguments: - m_ObjectArgument: {fileID: 0} - m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine - m_IntArgument: 0 - m_FloatArgument: 0 - m_StringArgument: - m_BoolArgument: 0 - m_CallState: 2 + m_Calls: [] m_TypeName: UnityEngine.UI.Button+ButtonClickedEvent, UnityEngine.UI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null --- !u!114 &114368152801369894 @@ -5667,18 +5515,7 @@ MonoBehaviour: m_TargetGraphic: {fileID: 114451388216889804} m_OnClick: m_PersistentCalls: - m_Calls: - - m_Target: {fileID: 114581495326313396} - m_MethodName: OnSelectAllButtonClicked - m_Mode: 1 - m_Arguments: - m_ObjectArgument: {fileID: 0} - m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine - m_IntArgument: 0 - m_FloatArgument: 0 - m_StringArgument: - m_BoolArgument: 0 - m_CallState: 2 + m_Calls: [] m_TypeName: UnityEngine.UI.Button+ButtonClickedEvent, UnityEngine.UI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null --- !u!114 &114386564521543982 @@ -5768,18 +5605,7 @@ MonoBehaviour: m_TargetGraphic: {fileID: 114202282007228346} m_OnClick: m_PersistentCalls: - m_Calls: - - m_Target: {fileID: 114581495326313396} - m_MethodName: OnRenameButtonClicked - m_Mode: 1 - m_Arguments: - m_ObjectArgument: {fileID: 0} - m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine - m_IntArgument: 0 - m_FloatArgument: 0 - m_StringArgument: - m_BoolArgument: 0 - m_CallState: 2 + m_Calls: [] m_TypeName: UnityEngine.UI.Button+ButtonClickedEvent, UnityEngine.UI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null --- !u!114 &114431454406163400 @@ -5830,18 +5656,7 @@ MonoBehaviour: m_CharacterLimit: 0 m_OnEndEdit: m_PersistentCalls: - m_Calls: - - m_Target: {fileID: 114205106981145908} - m_MethodName: OnInputFieldEndEdit - m_Mode: 0 - m_Arguments: - m_ObjectArgument: {fileID: 0} - m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine - m_IntArgument: 0 - m_FloatArgument: 0 - m_StringArgument: - m_BoolArgument: 0 - m_CallState: 2 + m_Calls: [] m_TypeName: UnityEngine.UI.InputField+SubmitEvent, UnityEngine.UI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null m_OnValueChanged: @@ -5894,18 +5709,7 @@ MonoBehaviour: m_TargetGraphic: {fileID: 114598182042052440} m_OnClick: m_PersistentCalls: - m_Calls: - - m_Target: {fileID: 114966523907925700} - m_MethodName: NoButtonClicked - m_Mode: 1 - m_Arguments: - m_ObjectArgument: {fileID: 0} - m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine - m_IntArgument: 0 - m_FloatArgument: 0 - m_StringArgument: - m_BoolArgument: 0 - m_CallState: 2 + m_Calls: [] m_TypeName: UnityEngine.UI.Button+ButtonClickedEvent, UnityEngine.UI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null --- !u!114 &114451388216889804 @@ -6756,18 +6560,7 @@ MonoBehaviour: m_TargetGraphic: {fileID: 114625667920685068} m_OnClick: m_PersistentCalls: - m_Calls: - - m_Target: {fileID: 114173655991101396} - m_MethodName: OKButtonClicked - m_Mode: 1 - m_Arguments: - m_ObjectArgument: {fileID: 0} - m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine - m_IntArgument: 0 - m_FloatArgument: 0 - m_StringArgument: - m_BoolArgument: 0 - m_CallState: 2 + m_Calls: [] m_TypeName: UnityEngine.UI.Button+ButtonClickedEvent, UnityEngine.UI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null --- !u!114 &114713076422221768 @@ -7193,8 +6986,8 @@ MonoBehaviour: - {fileID: 114339731131638318} targetItemsRest: {fileID: 1871003747564276} targetItemsRestLabel: {fileID: 114094015756707196} - yesButtonTransform: {fileID: 224859091447805236} - noButtonTransform: {fileID: 224366934613293246} + yesButton: {fileID: 114083312109309574} + noButton: {fileID: 114438238768779492} narrowScreenWidth: 500 --- !u!114 &114975456595458294 MonoBehaviour: diff --git a/Plugins/SimpleFileBrowser/Scripts/FileBrowser.cs b/Plugins/SimpleFileBrowser/Scripts/FileBrowser.cs index 03f02f9..a5ea060 100644 --- a/Plugins/SimpleFileBrowser/Scripts/FileBrowser.cs +++ b/Plugins/SimpleFileBrowser/Scripts/FileBrowser.cs @@ -501,9 +501,15 @@ private static FileBrowser Instance [SerializeField] private Toggle showHiddenFilesToggle; + [SerializeField] + private Button submitButton; + [SerializeField] private Text submitButtonText; + [SerializeField] + private Button cancelButton; + [SerializeField] private Button[] allButtons; @@ -842,8 +848,18 @@ private void Awake() forwardButton.interactable = false; upButton.interactable = false; + backButton.onClick.AddListener( OnBackButtonClicked ); + forwardButton.onClick.AddListener( OnForwardButtonClicked ); + upButton.onClick.AddListener( OnUpButtonClicked ); + moreOptionsButton.onClick.AddListener( OnMoreOptionsButtonClicked ); + submitButton.onClick.AddListener( OnSubmitButtonClicked ); + cancelButton.onClick.AddListener( OnCancelButtonClicked ); + pathInputField.onEndEdit.AddListener( OnPathChanged ); + searchInputField.onValueChanged.AddListener( OnSearchStringChanged ); filenameInputField.onValidateInput += OnValidateFilenameInput; filenameInputField.onValueChanged.AddListener( OnFilenameInputChanged ); + filtersDropdown.onValueChanged.AddListener( OnFilterChanged ); + showHiddenFilesToggle.onValueChanged.AddListener( OnShowHiddenFilesToggleChanged ); allFilesFilter = new Filter( AllFilesFilterText ); filters.Add( allFilesFilter ); @@ -1321,19 +1337,19 @@ private void RefreshSkin() #endregion #region Button Events - public void OnBackButtonPressed() + private void OnBackButtonClicked() { if( currentPathIndex > 0 ) CurrentPath = pathsFollowed[--currentPathIndex]; } - public void OnForwardButtonPressed() + private void OnForwardButtonClicked() { if( currentPathIndex < pathsFollowed.Count - 1 ) CurrentPath = pathsFollowed[++currentPathIndex]; } - public void OnUpButtonPressed() + private void OnUpButtonClicked() { #if !UNITY_EDITOR && UNITY_ANDROID if( FileBrowserHelpers.ShouldUseSAF ) @@ -1357,7 +1373,7 @@ public void OnUpButtonPressed() } } - public void OnMoreOptionsButtonClicked() + private void OnMoreOptionsButtonClicked() { ShowContextMenuAt( rectTransform.InverseTransformPoint( moreOptionsContextMenuPosition.position ), true ); } @@ -1399,7 +1415,7 @@ private void ShowContextMenuAt( Vector2 position, bool isMoreOptionsMenu ) contextMenu.Show( selectAllButtonVisible, deselectAllButtonVisible, deleteButtonVisible, renameButtonVisible, position, isMoreOptionsMenu ); } - public void OnSubmitButtonClicked() + private void OnSubmitButtonClicked() { string[] result = null; string filenameInput = filenameInputField.text.Trim(); @@ -1654,7 +1670,7 @@ public void OnSubmitButtonClicked() } } - public void OnCancelButtonClicked() + private void OnCancelButtonClicked() { OnOperationCanceled( true ); } @@ -1697,7 +1713,7 @@ private void OnOperationCanceled( bool invokeCancelCallback ) _onCancel(); } - public void OnPathChanged( string newPath ) + private void OnPathChanged( string newPath ) { // Fixes harmless NullReferenceException that occurs when Play button is clicked while SimpleFileBrowserCanvas prefab is open in prefab mode // https://github.com/yasirkula/UnitySimpleFileBrowser/issues/30 @@ -1707,7 +1723,7 @@ public void OnPathChanged( string newPath ) CurrentPath = newPath; } - public void OnSearchStringChanged( string newSearchString ) + private void OnSearchStringChanged( string newSearchString ) { if( !canvas ) // Same as OnPathChanged return; @@ -1716,17 +1732,17 @@ public void OnSearchStringChanged( string newSearchString ) SearchString = newSearchString; } - public void OnFilterChanged() + private void OnFilterChanged( int value ) { if( !canvas ) // Same as OnPathChanged return; bool extensionsSingleSuffixModeChanged = false; - if( filters != null && filtersDropdown.value < filters.Count ) + if( filters != null && value < filters.Count ) { bool allExtensionsHadSingleSuffix = AllExtensionsHaveSingleSuffix; - allFiltersHaveSingleSuffix = filters[filtersDropdown.value].allExtensionsHaveSingleSuffix; + allFiltersHaveSingleSuffix = filters[value].allExtensionsHaveSingleSuffix; extensionsSingleSuffixModeChanged = ( AllExtensionsHaveSingleSuffix != allExtensionsHadSingleSuffix ); } @@ -1734,7 +1750,7 @@ public void OnFilterChanged() RefreshFiles( extensionsSingleSuffixModeChanged ); } - public void OnShowHiddenFilesToggleChanged() + private void OnShowHiddenFilesToggleChanged( bool value ) { if( !canvas ) // Same as OnPathChanged return; diff --git a/Plugins/SimpleFileBrowser/Scripts/FileBrowserAccessRestrictedPanel.cs b/Plugins/SimpleFileBrowser/Scripts/FileBrowserAccessRestrictedPanel.cs index be4cfb5..be0a90c 100644 --- a/Plugins/SimpleFileBrowser/Scripts/FileBrowserAccessRestrictedPanel.cs +++ b/Plugins/SimpleFileBrowser/Scripts/FileBrowserAccessRestrictedPanel.cs @@ -20,6 +20,11 @@ public class FileBrowserAccessRestrictedPanel : MonoBehaviour private Button okButton; #pragma warning restore 0649 + private void Awake() + { + okButton.onClick.AddListener( OKButtonClicked ); + } + internal void Show() { gameObject.SetActive( true ); @@ -58,7 +63,7 @@ internal void RefreshSkin( UISkin skin ) skin.ApplyTo( messageLabel, skin.PopupPanelsTextColor ); } - public void OKButtonClicked() + private void OKButtonClicked() { gameObject.SetActive( false ); } diff --git a/Plugins/SimpleFileBrowser/Scripts/FileBrowserContextMenu.cs b/Plugins/SimpleFileBrowser/Scripts/FileBrowserContextMenu.cs index 364fbff..37a3408 100644 --- a/Plugins/SimpleFileBrowser/Scripts/FileBrowserContextMenu.cs +++ b/Plugins/SimpleFileBrowser/Scripts/FileBrowserContextMenu.cs @@ -37,6 +37,15 @@ public class FileBrowserContextMenu : MonoBehaviour private float minDistanceToEdges = 10f; #pragma warning restore 0649 + private void Awake() + { + selectAllButton.onClick.AddListener( OnSelectAllButtonClicked ); + deselectAllButton.onClick.AddListener( OnDeselectAllButtonClicked ); + createFolderButton.onClick.AddListener( OnCreateFolderButtonClicked ); + deleteButton.onClick.AddListener( OnDeleteButtonClicked ); + renameButton.onClick.AddListener( OnRenameButtonClicked ); + } + internal void Show( bool selectAllButtonVisible, bool deselectAllButtonVisible, bool deleteButtonVisible, bool renameButtonVisible, Vector2 position, bool isMoreOptionsMenu ) { selectAllButton.gameObject.SetActive( selectAllButtonVisible ); @@ -114,31 +123,31 @@ internal void RefreshSkin( UISkin skin ) allButtonSeparators[i].color = skin.ContextMenuSeparatorColor; } - public void OnSelectAllButtonClicked() + private void OnSelectAllButtonClicked() { Hide(); fileBrowser.SelectAllFiles(); } - public void OnDeselectAllButtonClicked() + private void OnDeselectAllButtonClicked() { Hide(); fileBrowser.DeselectAllFiles(); } - public void OnCreateFolderButtonClicked() + private void OnCreateFolderButtonClicked() { Hide(); fileBrowser.CreateNewFolder(); } - public void OnDeleteButtonClicked() + private void OnDeleteButtonClicked() { Hide(); fileBrowser.DeleteSelectedFiles(); } - public void OnRenameButtonClicked() + private void OnRenameButtonClicked() { Hide(); fileBrowser.RenameSelectedFile(); diff --git a/Plugins/SimpleFileBrowser/Scripts/FileBrowserFileOperationConfirmationPanel.cs b/Plugins/SimpleFileBrowser/Scripts/FileBrowserFileOperationConfirmationPanel.cs index b4531ad..ccf93d0 100644 --- a/Plugins/SimpleFileBrowser/Scripts/FileBrowserFileOperationConfirmationPanel.cs +++ b/Plugins/SimpleFileBrowser/Scripts/FileBrowserFileOperationConfirmationPanel.cs @@ -36,10 +36,10 @@ public enum OperationType { Delete = 0, Overwrite = 1 }; private Text targetItemsRestLabel; [SerializeField] - private RectTransform yesButtonTransform; + private Button yesButton; [SerializeField] - private RectTransform noButtonTransform; + private Button noButton; [SerializeField] private float narrowScreenWidth = 380f; @@ -47,6 +47,12 @@ public enum OperationType { Delete = 0, Overwrite = 1 }; private OnOperationConfirmed onOperationConfirmed; + private void Awake() + { + yesButton.onClick.AddListener( OnYesButtonClicked ); + noButton.onClick.AddListener( OnNoButtonClicked ); + } + internal void Show( FileBrowser fileBrowser, List items, OperationType operationType, OnOperationConfirmed onOperationConfirmed ) { Show( fileBrowser, items, null, operationType, onOperationConfirmed ); @@ -87,15 +93,15 @@ internal void OnCanvasDimensionsChanged( Vector2 size ) { if( size.x >= narrowScreenWidth ) { - yesButtonTransform.anchorMin = new Vector2( 0.5f, 0f ); - yesButtonTransform.anchorMax = new Vector2( 0.75f, 1f ); - noButtonTransform.anchorMin = new Vector2( 0.75f, 0f ); + ( yesButton.transform as RectTransform ).anchorMin = new Vector2( 0.5f, 0f ); + ( yesButton.transform as RectTransform ).anchorMax = new Vector2( 0.75f, 1f ); + ( noButton.transform as RectTransform ).anchorMin = new Vector2( 0.75f, 0f ); } else { - yesButtonTransform.anchorMin = Vector2.zero; - yesButtonTransform.anchorMax = new Vector2( 0.5f, 1f ); - noButtonTransform.anchorMin = new Vector2( 0.5f, 0f ); + ( yesButton.transform as RectTransform ).anchorMin = Vector2.zero; + ( yesButton.transform as RectTransform ).anchorMax = new Vector2( 0.5f, 1f ); + ( noButton.transform as RectTransform ).anchorMin = new Vector2( 0.5f, 0f ); } } @@ -112,14 +118,14 @@ private void LateUpdate() #else if( Input.GetKeyDown( KeyCode.Return ) || Input.GetKeyDown( KeyCode.KeypadEnter ) ) #endif - YesButtonClicked(); + OnYesButtonClicked(); #if ENABLE_INPUT_SYSTEM && !ENABLE_LEGACY_INPUT_MANAGER if( Keyboard.current[Key.Escape].wasPressedThisFrame ) #else if( Input.GetKeyDown( KeyCode.Escape ) ) #endif - NoButtonClicked(); + OnNoButtonClicked(); } } #endif @@ -133,11 +139,11 @@ internal void RefreshSkin( UISkin skin ) background.color = skin.PopupPanelsBackgroundColor; background.sprite = skin.PopupPanelsBackground; - RectTransform buttonsParent = (RectTransform) yesButtonTransform.parent; + RectTransform buttonsParent = yesButton.transform.parent as RectTransform; buttonsParent.sizeDelta = new Vector2( buttonsParent.sizeDelta.x, skin.RowHeight ); - skin.ApplyTo( yesButtonTransform.GetComponent