using System.Collections; using UnityEngine; using BaseGames.Feedback; using BaseGames.Player; namespace BaseGames.World { /// /// 能力解锁触发物(Prefab)。 /// 玩家进入触发区后播放解锁演出,然后调用 PlayerStats.UnlockAbility()。 /// [RequireComponent(typeof(Collider2D))] public class AbilityUnlock : MonoBehaviour { [Header("解锁配置")] [SerializeField] private AbilityType _abilityToUnlock; [SerializeField] private bool _destroyAfterUnlock = true; [Header("演出配置")] [SerializeField] private SceneFeedback _unlockFeedback; [SerializeField] private float _cutsceneDuration = 1.5f; [Header("Event Channel")] [SerializeField] private AbilityTypeEventChannelSO _onAbilityUnlocked; // EVT_AbilityUnlocked private bool _used; private void OnTriggerEnter2D(Collider2D other) { if (_used || !other.CompareTag("Player")) return; var stats = other.GetComponentInParent(); if (stats == null || stats.HasAbility(_abilityToUnlock)) return; StartCoroutine(UnlockSequence(stats)); } private IEnumerator UnlockSequence(PlayerStats stats) { _used = true; _unlockFeedback?.Play(); yield return new WaitForSeconds(_cutsceneDuration); stats.UnlockAbility(_abilityToUnlock); _onAbilityUnlocked?.Raise(_abilityToUnlock); if (_destroyAfterUnlock) Destroy(gameObject); } } }