55 lines
2.0 KiB
C#
55 lines
2.0 KiB
C#
using System.Collections;
|
||
using UnityEngine;
|
||
using TMPro;
|
||
|
||
namespace BaseGames.Tutorial
|
||
{
|
||
/// <summary>
|
||
/// 教程提示 UI 组件(架构 21_LiquidPuzzleModule §17)。
|
||
/// 负责显示/隐藏提示面板和文字;duration ≤ 0 时不自动消隐。
|
||
/// </summary>
|
||
public class TutorialHintUI : MonoBehaviour
|
||
{
|
||
[SerializeField] private GameObject _panel;
|
||
[SerializeField] private TMP_Text _label;
|
||
#pragma warning disable CS0414
|
||
[SerializeField] private float _fadeSpeed = 4f;
|
||
#pragma warning restore CS0414
|
||
|
||
private Coroutine _autoHideCoroutine;
|
||
|
||
// ── 公共 API ──────────────────────────────────────────────────────
|
||
/// <summary>显示提示文字。duration ≤ 0 时不自动消隐。</summary>
|
||
public void Show(string text, float duration = 0f)
|
||
{
|
||
if (_panel != null) _panel.SetActive(true);
|
||
if (_label != null) _label.text = text;
|
||
|
||
if (_autoHideCoroutine != null)
|
||
StopCoroutine(_autoHideCoroutine);
|
||
|
||
if (duration > 0f)
|
||
_autoHideCoroutine = StartCoroutine(AutoHideRoutine(duration));
|
||
}
|
||
|
||
/// <summary>立即隐藏提示面板。</summary>
|
||
public void Hide()
|
||
{
|
||
if (_autoHideCoroutine != null)
|
||
{
|
||
StopCoroutine(_autoHideCoroutine);
|
||
_autoHideCoroutine = null;
|
||
}
|
||
if (_panel != null) _panel.SetActive(false);
|
||
}
|
||
|
||
// ── 内部 ──────────────────────────────────────────────────────────
|
||
private IEnumerator AutoHideRoutine(float duration)
|
||
{
|
||
yield return new WaitForSeconds(duration);
|
||
Hide();
|
||
_autoHideCoroutine = null;
|
||
}
|
||
}
|
||
}
|