多轮审查和修复

This commit is contained in:
2026-05-12 15:34:08 +08:00
parent f55d2a57c3
commit ebbbb7332e
805 changed files with 838724 additions and 1905 deletions

View File

@@ -0,0 +1,51 @@
// Assets/Scripts/World/Puzzle/PuzzleWire.cs
// 逻辑连接器:将一组 PuzzleSwitch 连接到 PuzzleReceiverArchitecture 21_LiquidPuzzleModule §11
// 支持 AND / OR / XOR 激活逻辑Inspector 中配置,无需代码
using System.Linq;
using UnityEngine;
namespace BaseGames.Puzzle
{
public enum LogicType { AND, OR, XOR }
/// <summary>
/// 连接一个或多个 PuzzleSwitch 到 PuzzleReceiver。
/// 支持 AND / OR / XOR 激活逻辑。
/// 关卡设计师在 Inspector 中配置,无需编写代码。
/// </summary>
public class PuzzleWire : MonoBehaviour
{
[Header("输入开关")]
[SerializeField] private PuzzleSwitch[] _switches;
[Header("激活逻辑")]
[SerializeField] private LogicType _logic = LogicType.AND;
[Header("目标接收器")]
[SerializeField] private PuzzleReceiver _receiver;
private void Start()
{
if (_switches != null)
foreach (var sw in _switches)
if (sw != null) sw.OnStateChanged += _ => Evaluate();
Evaluate(); // 初始求值
}
private void Evaluate()
{
if (_switches == null || _receiver == null) return;
bool shouldActivate = _logic switch
{
LogicType.AND => System.Array.TrueForAll(_switches, s => s != null && s.IsActive),
LogicType.OR => System.Array.Exists(_switches, s => s != null && s.IsActive),
LogicType.XOR => _switches.Count(s => s != null && s.IsActive) % 2 == 1,
_ => false,
};
if (shouldActivate) _receiver.Activate();
else _receiver.Deactivate();
}
}
}