From 6d57445267d6ef5bd435d5a5b089d5d6cd5e4aa4 Mon Sep 17 00:00:00 2001 From: yasirkula Date: Sat, 30 Sep 2023 18:19:03 +0300 Subject: [PATCH] New Input System no longer requires any manual modifications (closed #55) --- .github/README.md | 19 +++++++++---------- Plugins/SimpleFileBrowser/README.txt | 9 --------- .../Scripts/EventSystemHandler.cs | 15 +++++++++++++++ .../SimpleFileBrowser.Runtime.asmdef | 7 +++++-- 4 files changed, 29 insertions(+), 21 deletions(-) diff --git a/.github/README.md b/.github/README.md index a6f30da..554e972 100644 --- a/.github/README.md +++ b/.github/README.md @@ -37,15 +37,6 @@ There are 5 ways to install this plugin: - *(via [OpenUPM](https://openupm.com))* after installing [openupm-cli](https://github.com/openupm/openupm-cli), run the following command: - `openupm add com.yasirkula.simplefilebrowser` -### NEW INPUT SYSTEM SUPPORT - -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): - -- 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*) -- 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) -- add `Unity.InputSystem` assembly to **SimpleFileBrowser.Runtime** Assembly Definition File's *Assembly Definition References* list -- 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) - ## FAQ - **File browser doesn't show any files on Mac when sandboxing is enabled** @@ -54,7 +45,7 @@ This is a known issue but I can't give an ETA for a solution at the moment: http - **File browser doesn't show any files on Android 10+** -File browser uses *Storage Access Framework* on these Android versions and users must first click the *Browse...* button in the quick links section +File browser uses *Storage Access Framework* on these Android versions and users must first click the *Browse...* button in the quick links section. - **File browser doesn't show any files on Oculus Quest** @@ -64,6 +55,14 @@ Please see: https://github.com/yasirkula/UnitySimpleFileBrowser/issues/87 Please see: https://github.com/yasirkula/UnitySimpleFileBrowser/issues/70 +- **New Input System isn't supported on Unity 2019.2.5 or earlier** + +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). + +- **"Unity.InputSystem" assembly can't be resolved on Unity 2018.4 or earlier** + +Remove `Unity.InputSystem` assembly from **SimpleFileBrowser.Runtime** Assembly Definition File's *Assembly Definition References* list. + - **Android build fails, it says "error: attribute android:requestLegacyExternalStorage not found" in Console** `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 `` tag from _AndroidManifest.xml_. diff --git a/Plugins/SimpleFileBrowser/README.txt b/Plugins/SimpleFileBrowser/README.txt index df2f2df..82ac3c8 100644 --- a/Plugins/SimpleFileBrowser/README.txt +++ b/Plugins/SimpleFileBrowser/README.txt @@ -16,15 +16,6 @@ File browser comes bundled with two premade skins in the Skins directory: LightS - By changing the value of FileBrowser.Skin property from a C# script -### NEW INPUT SYSTEM SUPPORT -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): - -- 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) -- 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) -- add "Unity.InputSystem" assembly to "SimpleFileBrowser.Runtime" Assembly Definition File's "Assembly Definition References" list -- 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) - - ### FAQ - Android build fails, it says "error: attribute android:requestLegacyExternalStorage not found" in Console "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 "" tag from AndroidManifest.xml. diff --git a/Plugins/SimpleFileBrowser/Scripts/EventSystemHandler.cs b/Plugins/SimpleFileBrowser/Scripts/EventSystemHandler.cs index 3b2f60a..7bbb83c 100644 --- a/Plugins/SimpleFileBrowser/Scripts/EventSystemHandler.cs +++ b/Plugins/SimpleFileBrowser/Scripts/EventSystemHandler.cs @@ -1,6 +1,9 @@ using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.SceneManagement; +#if ENABLE_INPUT_SYSTEM && !ENABLE_LEGACY_INPUT_MANAGER +using UnityEngine.InputSystem.UI; +#endif namespace SimpleFileBrowser { @@ -13,6 +16,18 @@ public class EventSystemHandler : MonoBehaviour private GameObject embeddedEventSystem; #pragma warning restore 0649 +#if ENABLE_INPUT_SYSTEM && !ENABLE_LEGACY_INPUT_MANAGER + private void Awake() + { + StandaloneInputModule legacyInputModule = embeddedEventSystem.GetComponent(); + if( legacyInputModule ) + { + DestroyImmediate( legacyInputModule ); + embeddedEventSystem.AddComponent(); + } + } +#endif + private void OnEnable() { SceneManager.sceneLoaded -= OnSceneLoaded; diff --git a/Plugins/SimpleFileBrowser/SimpleFileBrowser.Runtime.asmdef b/Plugins/SimpleFileBrowser/SimpleFileBrowser.Runtime.asmdef index a13c242..08444f3 100644 --- a/Plugins/SimpleFileBrowser/SimpleFileBrowser.Runtime.asmdef +++ b/Plugins/SimpleFileBrowser/SimpleFileBrowser.Runtime.asmdef @@ -1,3 +1,6 @@ { - "name": "SimpleFileBrowser.Runtime" -} + "name": "SimpleFileBrowser.Runtime", + "references": [ + "Unity.InputSystem" + ] +} \ No newline at end of file