Files
zeling_v2/Assets/_Game/Scripts/Dialogue/InteractionPromptController.cs

46 lines
1.4 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.UI;
namespace BaseGames.Dialogue
{
/// <summary>
/// 交互提示 UI 控制器(架构 14_NarrativeModule §2
/// 挂载在每个 IInteractable GameObject 的子节点Prefab 实例),默认隐藏。
/// 根据当前活跃输入设备自动切换图标(键盘/手柄)。
/// </summary>
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);
}
/// <summary>显示交互提示,根据输入设备选择图标。</summary>
public void Show()
{
if (_promptRoot == null) return;
_promptRoot.SetActive(true);
UpdateIcon();
}
/// <summary>隐藏交互提示。</summary>
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;
}
}
}