多轮审查和修复
This commit is contained in:
57
Assets/Scripts/World/Puzzle/PuzzleReceiver.cs
Normal file
57
Assets/Scripts/World/Puzzle/PuzzleReceiver.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
// Assets/Scripts/World/Puzzle/PuzzleReceiver.cs
|
||||
using BaseGames.World;
|
||||
using MoreMountains.Feedbacks;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BaseGames.Puzzle
|
||||
{
|
||||
/// <summary>
|
||||
/// 谜题接收器,由 PuzzleWire 驱动。
|
||||
/// 挂在谜题目标物件上(门/平台等),实现 IActivatable。
|
||||
/// 子类覆写 OnActivate / OnDeactivate 实现具体行为。
|
||||
/// </summary>
|
||||
public class PuzzleReceiver : MonoBehaviour, IActivatable
|
||||
{
|
||||
[SerializeField] private bool _startsActivated = false;
|
||||
[SerializeField] private string _receiverId; // 持久化唯一 ID(空串则不持久化)
|
||||
[SerializeField] private MMFeedbacks _activateFeedback;
|
||||
[SerializeField] private MMFeedbacks _deactivateFeedback;
|
||||
|
||||
[Header("持久化(SO 注入,非 Instance 单例)")]
|
||||
[SerializeField] private WorldStateRegistry _worldState;
|
||||
|
||||
private bool _isActivated;
|
||||
public bool IsActivated => _isActivated;
|
||||
|
||||
protected virtual void Start()
|
||||
{
|
||||
_isActivated = _startsActivated;
|
||||
if (_isActivated) OnActivate();
|
||||
}
|
||||
|
||||
public void Activate()
|
||||
{
|
||||
if (_isActivated) return;
|
||||
_isActivated = true;
|
||||
_activateFeedback?.PlayFeedbacks();
|
||||
OnActivate();
|
||||
|
||||
if (!string.IsNullOrEmpty(_receiverId))
|
||||
_worldState?.SetFlag("receiver_" + _receiverId);
|
||||
}
|
||||
|
||||
public void Deactivate()
|
||||
{
|
||||
if (!_isActivated) return;
|
||||
_isActivated = false;
|
||||
_deactivateFeedback?.PlayFeedbacks();
|
||||
OnDeactivate();
|
||||
|
||||
if (!string.IsNullOrEmpty(_receiverId))
|
||||
_worldState?.ClearFlag("receiver_" + _receiverId);
|
||||
}
|
||||
|
||||
protected virtual void OnActivate() { }
|
||||
protected virtual void OnDeactivate() { }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user