using UnityEngine; using BaseGames.Core; using BaseGames.Player; using BaseGames.Localization; namespace BaseGames.Tutorial { /// /// 情境化教程触发器(架构 21_LiquidPuzzleModule §18)。 /// 当玩家进入 Trigger 碰撞体范围时,向 TutorialManager 请求显示提示。 /// 若 _requiresAbility = true,只在玩家拥有 _requiredAbility 后才触发。 /// 每个触发器只触发一次(触发后禁用自身)。 /// [RequireComponent(typeof(Collider2D))] public class ContextualHintTrigger : MonoBehaviour { [Header("提示配置")] [SerializeField] private string _hintId = ""; [SerializeField] private string _hintLocKey = ""; // 本地化 Key(Table_UI) [SerializeField] private float _displayDuration = 4f; [Header("能力门控")] [SerializeField] private bool _requiresAbility = false; [SerializeField] private AbilityType _requiredAbility = AbilityType.None; private void Awake() { var col = GetComponent(); col.isTrigger = true; } private void OnTriggerEnter2D(Collider2D other) { if (!other.CompareTag("Player")) return; var tm = ServiceLocator.GetOrDefault(); if (tm == null) return; // 能力门控检查 if (_requiresAbility) { var stats = other.GetComponent(); 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); } } }