多轮审查和修复
This commit is contained in:
57
Assets/Scripts/World/AbilityUnlock.cs
Normal file
57
Assets/Scripts/World/AbilityUnlock.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using MoreMountains.Tools;
|
||||
using BaseGames.Player;
|
||||
|
||||
namespace BaseGames.World
|
||||
{
|
||||
/// <summary>
|
||||
/// 能力解锁触发物(Prefab)。
|
||||
/// 玩家进入触发区后播放解锁演出,然后调用 PlayerStats.UnlockAbility()。
|
||||
/// </summary>
|
||||
[RequireComponent(typeof(Collider2D))]
|
||||
public class AbilityUnlock : MonoBehaviour
|
||||
{
|
||||
[Header("解锁配置")]
|
||||
[SerializeField] private AbilityType _abilityToUnlock;
|
||||
[SerializeField] private bool _destroyAfterUnlock = true;
|
||||
|
||||
[Header("演出配置")]
|
||||
[SerializeField] private Component _unlockFeedback; // Assign MMF_Player or compatible component
|
||||
[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<PlayerStats>();
|
||||
if (stats == null || stats.HasAbility(_abilityToUnlock)) return;
|
||||
StartCoroutine(UnlockSequence(stats));
|
||||
}
|
||||
|
||||
private IEnumerator UnlockSequence(PlayerStats stats)
|
||||
{
|
||||
_used = true;
|
||||
|
||||
PlayFeedback(_unlockFeedback);
|
||||
yield return new WaitForSeconds(_cutsceneDuration);
|
||||
|
||||
stats.UnlockAbility(_abilityToUnlock);
|
||||
_onAbilityUnlocked?.Raise(_abilityToUnlock);
|
||||
|
||||
if (_destroyAfterUnlock)
|
||||
Destroy(gameObject);
|
||||
}
|
||||
|
||||
private static void PlayFeedback(Component feedback)
|
||||
{
|
||||
if (feedback == null) return;
|
||||
var method = feedback.GetType().GetMethod("PlayFeedbacks", System.Type.EmptyTypes);
|
||||
method?.Invoke(feedback, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user