45 lines
1.5 KiB
C#
45 lines
1.5 KiB
C#
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
#if ENABLE_INPUT_SYSTEM
|
|
using UnityEngine.InputSystem.UI;
|
|
#endif
|
|
|
|
namespace Invector
|
|
{
|
|
/// <summary>
|
|
/// Selects a single UI input backend, preferring the Input System when both are available.
|
|
/// Keeps the StandaloneInputModule configuration for projects using the legacy backend.
|
|
/// </summary>
|
|
[DisallowMultipleComponent]
|
|
[RequireComponent(typeof(EventSystem))]
|
|
[DefaultExecutionOrder(-1000)]
|
|
public class vEventSystemInputBackend : MonoBehaviour
|
|
{
|
|
private void Awake()
|
|
{
|
|
Configure();
|
|
}
|
|
|
|
public void Configure()
|
|
{
|
|
var legacy = GetComponent<StandaloneInputModule>();
|
|
#if ENABLE_INPUT_SYSTEM
|
|
if (legacy != null) legacy.enabled = false;
|
|
var current = GetComponent<InputSystemUIInputModule>();
|
|
if (current == null) current = gameObject.AddComponent<InputSystemUIInputModule>();
|
|
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<BaseInputModule>())
|
|
{
|
|
if (module.GetType().FullName == "UnityEngine.InputSystem.UI.InputSystemUIInputModule")
|
|
module.enabled = false;
|
|
}
|
|
if (legacy == null) legacy = gameObject.AddComponent<StandaloneInputModule>();
|
|
legacy.enabled = true;
|
|
#endif
|
|
}
|
|
}
|
|
}
|