Skip to content

Commit d581661

Browse files
committed
Added new Input System support (requires manual modifications, see documentation)
1 parent f377168 commit d581661

File tree

8 files changed

+98
-20
lines changed

8 files changed

+98
-20
lines changed

.github/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ There are 5 ways to install this plugin:
3434
- *(via [OpenUPM](https://openupm.com))* after installing [openupm-cli](https://github.com/openupm/openupm-cli), run the following command:
3535
- `openupm add com.yasirkula.simplefilebrowser`
3636

37+
### NEW INPUT SYSTEM SUPPORT
38+
39+
This plugin supports Unity's new Input System but it requires some manual modifications (if both the legacy and the new input systems are active at the same time, no changes are needed):
40+
41+
- the plugin mustn't be installed as a package, i.e. it must reside inside the *Assets* folder and not the *Packages* folder (it can reside inside a subfolder of Assets like *Assets/Plugins*)
42+
- if Unity 2019.2.5 or earlier is used, add `ENABLE_INPUT_SYSTEM` compiler directive to **Player Settings/Scripting Define Symbols** (these symbols are platform specific, so if you change the active platform later, you'll have to add the compiler directive again)
43+
- add `Unity.InputSystem` assembly to **SimpleFileBrowser.Runtime** Assembly Definition File's *Assembly Definition References* list
44+
- open *SimpleFileBrowserCanvas* prefab, select *EventSystem* child object and replace *StandaloneInputModule* component with *InputSystemUIInputModule* component (or, if your scene(s) already have EventSystem objects, you can delete SimpleFileBrowserCanvas prefab's EventSystem child object)
45+
3746
## FAQ
3847

3948
- **Android build fails, it says "error: attribute android:requestLegacyExternalStorage not found" in Console**

Plugins/SimpleFileBrowser/README.txt

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,24 @@
33
Online documentation & example code available at: https://github.com/yasirkula/UnitySimpleFileBrowser
44
55

6-
1. ABOUT
6+
### ABOUT
77
This plugin helps you show save/load dialogs during gameplay with its uGUI based file browser.
88

99

10-
2. HOW TO
10+
### HOW TO
1111
The file browser can be shown either as a save dialog or a load dialog. In load mode, the returned path(s) always lead to existing files or folders. In save mode, the returned path(s) can point to non-existing files, as well.
1212

1313

14-
3. FAQ
14+
### NEW INPUT SYSTEM SUPPORT
15+
This plugin supports Unity's new Input System but it requires some manual modifications (if both the legacy and the new input systems are active at the same time, no changes are needed):
16+
17+
- the plugin mustn't be installed as a package, i.e. it must reside inside the Assets folder and not the Packages folder (it can reside inside a subfolder of Assets like Assets/Plugins)
18+
- if Unity 2019.2.5 or earlier is used, add ENABLE_INPUT_SYSTEM compiler directive to "Player Settings/Scripting Define Symbols" (these symbols are platform specific, so if you change the active platform later, you'll have to add the compiler directive again)
19+
- add "Unity.InputSystem" assembly to "SimpleFileBrowser.Runtime" Assembly Definition File's "Assembly Definition References" list
20+
- open SimpleFileBrowserCanvas prefab, select EventSystem child object and replace StandaloneInputModule component with InputSystemUIInputModule component (or, if your scene(s) already have EventSystem objects, you can delete SimpleFileBrowserCanvas prefab's EventSystem child object)
21+
22+
23+
### FAQ
1524
- Android build fails, it says "error: attribute android:requestLegacyExternalStorage not found" in Console
1625
"android:requestLegacyExternalStorage" attribute in AndroidManifest.xml grants full access to device's storage on Android 10 but requires you to update your Android SDK to at least SDK 29. If this isn't possible for you, you should open SimpleFileBrowser.aar with WinRAR or 7-Zip and then remove the "<application ... />" tag from AndroidManifest.xml.
1726

@@ -26,7 +35,7 @@ Declare the WRITE_EXTERNAL_STORAGE permission manually in your Plugins/Android/A
2635
You'll need to add the following attribute to the '<manifest ...>' element: xmlns:tools="http://schemas.android.com/tools"
2736

2837

29-
4. SCRIPTING API
38+
### SCRIPTING API
3039
Please see the online documentation for a more in-depth documentation of the Scripting API: https://github.com/yasirkula/UnitySimpleFileBrowser
3140

3241
NOTE: On Android Q (10) or later, it is impossible to work with File APIs. On these devices, SimpleFileBrowser uses Storage Access Framework (SAF) to browse the files. However, paths returned by SAF are not File API compatible. To simulate the behaviour of the File API on all devices (including SAF), you can check out the FileBrowserHelpers functions. For reference, here is an example SAF path: content://com.android.externalstorage.documents/tree/primary%3A/document/primary%3APictures

Plugins/SimpleFileBrowser/Scripts/FileBrowser.cs

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
using System.Collections;
77
using System.Collections.Generic;
88
using System.Text;
9+
#if ENABLE_INPUT_SYSTEM && !ENABLE_LEGACY_INPUT_MANAGER
10+
using UnityEngine.InputSystem;
11+
#endif
912

1013
namespace SimpleFileBrowser
1114
{
@@ -730,6 +733,13 @@ private void Awake()
730733

731734
if( !showResizeCursor )
732735
Destroy( resizeCursorHandler );
736+
737+
#if ENABLE_INPUT_SYSTEM && !ENABLE_LEGACY_INPUT_MANAGER
738+
// On new Input System, scroll sensitivity is much higher than legacy Input system
739+
filesScrollRect.scrollSensitivity *= 0.25f;
740+
quickLinksContainer.GetComponentInParent<ScrollRect>().scrollSensitivity *= 0.25f;
741+
filtersDropdownContainer.GetComponent<ScrollRect>().scrollSensitivity *= 0.25f;
742+
#endif
733743
}
734744

735745
private void OnRectTransformDimensionsChange()
@@ -758,14 +768,31 @@ private void LateUpdate()
758768
// Handle keyboard shortcuts
759769
if( !EventSystem.current.currentSelectedGameObject )
760770
{
761-
if( Input.GetKeyDown( KeyCode.Delete ) )
762-
DeleteSelectedFiles();
771+
#if ENABLE_INPUT_SYSTEM && !ENABLE_LEGACY_INPUT_MANAGER
772+
if( Keyboard.current != null )
773+
#endif
774+
{
775+
#if ENABLE_INPUT_SYSTEM && !ENABLE_LEGACY_INPUT_MANAGER
776+
if( Keyboard.current[Key.Delete].wasPressedThisFrame )
777+
#else
778+
if( Input.GetKeyDown( KeyCode.Delete ) )
779+
#endif
780+
DeleteSelectedFiles();
763781

764-
if( Input.GetKeyDown( KeyCode.F2 ) )
765-
RenameSelectedFile();
782+
#if ENABLE_INPUT_SYSTEM && !ENABLE_LEGACY_INPUT_MANAGER
783+
if( Keyboard.current[Key.F2].wasPressedThisFrame )
784+
#else
785+
if( Input.GetKeyDown( KeyCode.F2 ) )
786+
#endif
787+
RenameSelectedFile();
766788

767-
if( Input.GetKeyDown( KeyCode.A ) && ( Input.GetKey( KeyCode.LeftControl ) || Input.GetKey( KeyCode.LeftCommand ) ) )
768-
SelectAllFiles();
789+
#if ENABLE_INPUT_SYSTEM && !ENABLE_LEGACY_INPUT_MANAGER
790+
if( Keyboard.current[Key.A].wasPressedThisFrame && Keyboard.current.ctrlKey.isPressed )
791+
#else
792+
if( Input.GetKeyDown( KeyCode.A ) && ( Input.GetKey( KeyCode.LeftControl ) || Input.GetKey( KeyCode.LeftCommand ) ) )
793+
#endif
794+
SelectAllFiles();
795+
}
769796
}
770797
#endif
771798

@@ -1091,12 +1118,12 @@ public void OnMoreOptionsButtonClicked()
10911118
ShowContextMenuAt( rectTransform.InverseTransformPoint( moreOptionsContextMenuPosition.position ), true );
10921119
}
10931120

1094-
internal void OnContextMenuTriggered()
1121+
internal void OnContextMenuTriggered( Vector2 pointerPos )
10951122
{
10961123
filesScrollRect.velocity = Vector2.zero;
10971124

10981125
Vector2 position;
1099-
RectTransformUtility.ScreenPointToLocalPointInRectangle( rectTransform, Input.mousePosition, canvas.worldCamera, out position );
1126+
RectTransformUtility.ScreenPointToLocalPointInRectangle( rectTransform, pointerPos, canvas.worldCamera, out position );
11001127

11011128
ShowContextMenuAt( position, false );
11021129
}
@@ -1396,7 +1423,11 @@ public void OnItemSelected( FileBrowserItem item, bool isDoubleClick )
13961423
{
13971424
#if UNITY_EDITOR || UNITY_STANDALONE || UNITY_WEBGL || UNITY_WSA || UNITY_WSA_10_0
13981425
// When Shift key is held, all items from the pivot item to the clicked item will be selected
1426+
#if ENABLE_INPUT_SYSTEM && !ENABLE_LEGACY_INPUT_MANAGER
1427+
if( Keyboard.current != null && Keyboard.current.shiftKey.isPressed )
1428+
#else
13991429
if( Input.GetKey( KeyCode.LeftShift ) || Input.GetKey( KeyCode.RightShift ) )
1430+
#endif
14001431
{
14011432
multiSelectionPivotFileEntry = Mathf.Clamp( multiSelectionPivotFileEntry, 0, validFileEntries.Count - 1 );
14021433

@@ -1416,7 +1447,11 @@ public void OnItemSelected( FileBrowserItem item, bool isDoubleClick )
14161447

14171448
// When in toggle selection mode or Control key is held, individual items can be multi-selected
14181449
#if UNITY_EDITOR || UNITY_STANDALONE || UNITY_WEBGL || UNITY_WSA || UNITY_WSA_10_0
1450+
#if ENABLE_INPUT_SYSTEM && !ENABLE_LEGACY_INPUT_MANAGER
1451+
if( m_multiSelectionToggleSelectionMode || ( Keyboard.current != null && Keyboard.current.ctrlKey.isPressed ) )
1452+
#else
14191453
if( m_multiSelectionToggleSelectionMode || Input.GetKey( KeyCode.LeftControl ) || Input.GetKey( KeyCode.RightControl ) )
1454+
#endif
14201455
#else
14211456
if( m_multiSelectionToggleSelectionMode )
14221457
#endif

Plugins/SimpleFileBrowser/Scripts/FileBrowserDeleteConfirmationPanel.cs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
using System.Collections.Generic;
22
using UnityEngine;
33
using UnityEngine.UI;
4+
#if ENABLE_INPUT_SYSTEM && !ENABLE_LEGACY_INPUT_MANAGER
5+
using UnityEngine.InputSystem;
6+
#endif
47

58
namespace SimpleFileBrowser
69
{
@@ -80,12 +83,25 @@ internal void OnCanvasDimensionsChanged( Vector2 size )
8083
#if UNITY_EDITOR || UNITY_STANDALONE || UNITY_WSA || UNITY_WSA_10_0
8184
private void LateUpdate()
8285
{
83-
// Handle keyboard shortcuts
84-
if( Input.GetKeyDown( KeyCode.Return ) || Input.GetKeyDown( KeyCode.KeypadEnter ) )
85-
YesButtonClicked();
86+
#if ENABLE_INPUT_SYSTEM && !ENABLE_LEGACY_INPUT_MANAGER
87+
if( Keyboard.current != null )
88+
#endif
89+
{
90+
// Handle keyboard shortcuts
91+
#if ENABLE_INPUT_SYSTEM && !ENABLE_LEGACY_INPUT_MANAGER
92+
if( Keyboard.current[Key.Enter].wasPressedThisFrame || Keyboard.current[Key.NumpadEnter].wasPressedThisFrame )
93+
#else
94+
if( Input.GetKeyDown( KeyCode.Return ) || Input.GetKeyDown( KeyCode.KeypadEnter ) )
95+
#endif
96+
YesButtonClicked();
8697

87-
if( Input.GetKeyDown( KeyCode.Escape ) )
88-
NoButtonClicked();
98+
#if ENABLE_INPUT_SYSTEM && !ENABLE_LEGACY_INPUT_MANAGER
99+
if( Keyboard.current[Key.Escape].wasPressedThisFrame )
100+
#else
101+
if( Input.GetKeyDown( KeyCode.Escape ) )
102+
#endif
103+
NoButtonClicked();
104+
}
89105
}
90106
#endif
91107

Plugins/SimpleFileBrowser/Scripts/FileBrowserItem.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ public class FileBrowserItem : ListItem, IPointerClickHandler, IPointerDownHandl
3131
private Text nameText;
3232
#pragma warning restore 0649
3333

34+
#pragma warning disable 0414
3435
private bool isSelected;
36+
#pragma warning restore 0414
3537

3638
private float pressTime = Mathf.Infinity;
3739
private float prevClickTime;
@@ -98,7 +100,7 @@ public void OnPointerClick( PointerEventData eventData )
98100
}
99101

100102
// Then, show the context menu
101-
fileBrowser.OnContextMenuTriggered();
103+
fileBrowser.OnContextMenuTriggered( eventData.position );
102104
return;
103105
}
104106
#endif

Plugins/SimpleFileBrowser/Scripts/FileBrowserRenamedItem.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
using UnityEngine;
22
using UnityEngine.EventSystems;
33
using UnityEngine.UI;
4+
#if ENABLE_INPUT_SYSTEM && !ENABLE_LEGACY_INPUT_MANAGER
5+
using UnityEngine.InputSystem;
6+
#endif
47

58
namespace SimpleFileBrowser
69
{
@@ -38,7 +41,11 @@ public void Show( string initialFilename, Color backgroundColor, Sprite icon, On
3841
private void LateUpdate()
3942
{
4043
// Don't allow scrolling with mouse wheel while renaming a file or creating a folder
44+
#if ENABLE_INPUT_SYSTEM && !ENABLE_LEGACY_INPUT_MANAGER
45+
if( Mouse.current != null && Mouse.current.scroll.ReadValue().y != 0f )
46+
#else
4147
if( Input.mouseScrollDelta.y != 0f )
48+
#endif
4249
nameInputField.DeactivateInputField();
4350
}
4451
#endif

Plugins/SimpleFileBrowser/Scripts/SimpleRecycledListView/RecycledListView.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ public void OnPointerClick( PointerEventData eventData )
231231
if( eventData.button == PointerEventData.InputButton.Left )
232232
fileBrowser.DeselectAllFiles();
233233
else if( eventData.button == PointerEventData.InputButton.Right )
234-
fileBrowser.OnContextMenuTriggered();
234+
fileBrowser.OnContextMenuTriggered( eventData.position );
235235
}
236236
#endif
237237
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "com.yasirkula.simplefilebrowser",
33
"displayName": "Simple File Browser",
4-
"version": "1.4.3",
4+
"version": "1.4.4",
55
"documentationUrl": "https://github.com/yasirkula/UnitySimpleFileBrowser",
66
"changelogUrl": "https://github.com/yasirkula/UnitySimpleFileBrowser/releases",
77
"licensesUrl": "https://github.com/yasirkula/UnitySimpleFileBrowser/blob/master/LICENSE.txt",

0 commit comments

Comments
 (0)