using UnityEngine; using UnityEngine.InputSystem; using UnityEngine.UI; namespace BaseGames.Dialogue { /// /// 交互提示 UI 控制器(架构 14_NarrativeModule §2)。 /// 挂载在每个 IInteractable GameObject 的子节点(Prefab 实例),默认隐藏。 /// 根据当前活跃输入设备自动切换图标(键盘/手柄)。 /// public class InteractionPromptController : MonoBehaviour { [SerializeField] private GameObject _promptRoot; [SerializeField] private Image _icon; [SerializeField] private Sprite _keyboardIcon; [SerializeField] private Sprite _gamepadIcon; private void Awake() { if (_promptRoot != null) _promptRoot.SetActive(false); } /// 显示交互提示,根据输入设备选择图标。 public void Show() { if (_promptRoot == null) return; _promptRoot.SetActive(true); UpdateIcon(); } /// 隐藏交互提示。 public void Hide() { if (_promptRoot != null) _promptRoot.SetActive(false); } private void UpdateIcon() { if (_icon == null) return; bool isGamepad = Gamepad.current != null && Gamepad.current.enabled; _icon.sprite = isGamepad ? _gamepadIcon : _keyboardIcon; } } }