多轮审查和修复
This commit is contained in:
45
Assets/Scripts/Dialogue/InteractionPromptController.cs
Normal file
45
Assets/Scripts/Dialogue/InteractionPromptController.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user