Files
zeling_v2/Assets/_Game/Scripts/Tutorial/ContextualHintTrigger.cs
2026-05-25 11:54:37 +08:00

54 lines
2.0 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 BaseGames.Core;
using BaseGames.Player;
using BaseGames.Localization;
namespace BaseGames.Tutorial
{
/// <summary>
/// 情境化教程触发器(架构 21_LiquidPuzzleModule §18
/// 当玩家进入 Trigger 碰撞体范围时,向 TutorialManager 请求显示提示。
/// 若 _requiresAbility = true只在玩家拥有 _requiredAbility 后才触发。
/// 每个触发器只触发一次(触发后禁用自身)。
/// </summary>
[RequireComponent(typeof(Collider2D))]
public class ContextualHintTrigger : MonoBehaviour
{
[Header("提示配置")]
[SerializeField] private string _hintId = "";
[SerializeField] private string _hintLocKey = ""; // 本地化 KeyTable_UI
[SerializeField] private float _displayDuration = 4f;
[Header("能力门控")]
[SerializeField] private bool _requiresAbility = false;
[SerializeField] private AbilityType _requiredAbility = AbilityType.None;
private void Awake()
{
var col = GetComponent<Collider2D>();
col.isTrigger = true;
}
private void OnTriggerEnter2D(Collider2D other)
{
if (!other.CompareTag("Player")) return;
var tm = ServiceLocator.GetOrDefault<ITutorialService>();
if (tm == null) return;
// 能力门控检查
if (_requiresAbility)
{
var stats = other.GetComponent<PlayerStats>();
if (stats == null || !stats.HasAbility(_requiredAbility)) return;
}
string text = LocalizationManager.Get(_hintLocKey, LocalizationTable.UI);
tm.ShowHint(_hintId, text, _displayDuration);
tm.CompleteHint(_hintId); // 写入 SaveData防止场景重载后重复触发
// 单次触发后禁用(避免重复弹出)
gameObject.SetActive(false);
}
}
}