using UnityEngine; using UnityEngine.EventSystems; #if ENABLE_INPUT_SYSTEM using UnityEngine.InputSystem.UI; #endif namespace Invector { /// /// Selects a single UI input backend, preferring the Input System when both are available. /// Keeps the StandaloneInputModule configuration for projects using the legacy backend. /// [DisallowMultipleComponent] [RequireComponent(typeof(EventSystem))] [DefaultExecutionOrder(-1000)] public class vEventSystemInputBackend : MonoBehaviour { private void Awake() { Configure(); } public void Configure() { var legacy = GetComponent(); #if ENABLE_INPUT_SYSTEM if (legacy != null) legacy.enabled = false; var current = GetComponent(); if (current == null) current = gameObject.AddComponent(); if (current.actionsAsset == null) current.AssignDefaultActions(); current.enabled = true; #else // A serialized Input System module can remain after switching to legacy-only input. foreach (var module in GetComponents()) { if (module.GetType().FullName == "UnityEngine.InputSystem.UI.InputSystemUIInputModule") module.enabled = false; } if (legacy == null) legacy = gameObject.AddComponent(); legacy.enabled = true; #endif } } }