Gameplay Ingredients是一组用于 Unity 游戏的运行时和编辑器工具:一组脚本的集合,可在制作游戏和原型时简化简单的任务。
您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

54 行
1.7 KiB

using NaughtyAttributes;
using UnityEngine;
using UnityEngine.EventSystems;
#if ENABLE_INPUT_SYSTEM
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.UI;
using UnityEngine.UI;
#endif
namespace GameplayIngredients
{
[AddComponentMenu(ComponentMenu.managersPath + "UI Event Manager")]
[RequireComponent(typeof(EventSystem))]
#if ENABLE_LEGACY_INPUT_MANAGER
[RequireComponent(typeof(StandaloneInputModule))]
#endif
#if ENABLE_INPUT_SYSTEM
[RequireComponent(typeof(InputSystemUIInputModule))]
#endif
[ManagerDefaultPrefab("UIEventManager")]
public class UIEventManager : Manager
{
[SerializeField]
private EventSystem m_EventSystem;
private void OnEnable()
{
m_EventSystem = GetComponent<EventSystem>();
if (TryGetComponent(out StandaloneInputModule im))
#if !ENABLE_LEGACY_INPUT_MANAGER
im.enabled = false;
#else
im.enabled = true;
#endif
#if ENABLE_INPUT_SYSTEM
if (!TryGetComponent(out InputSystemUIInputModule ism))
Debug.LogWarning("You are using the new Input System but the UI Event Manager prefab is not configured to use input from this package. In order to fix the issue, please add and configure a InputSystemUIInputModule component to your Assets/Resources/UIEventManagerPrefab. If the prefab is not present, use the Gameplay Ingredients Wizard located at Window/Gameplay Ingredients/Setup Wizard");
#endif
}
public void FocusUI(Selectable selectable)
{
// Before selecting, we ensure that there's no selection in the EventSystem
m_EventSystem.SetSelectedGameObject(null);
if(selectable != null)
selectable.Select();
}
}
}