using System.Collections.Generic; using AibisDream.Framework; using UnityEngine; using Yarn.Unity; namespace AibisDream.FixSystem { [RequireComponent(typeof(BodyModuleSystem))] public class WhackMoleSystem : MonoBehaviour { private BodyModuleSystem _bodyModuleSystem; [SerializeField] private PipelineSystem pipelineSystem; [SerializeField] private VerificationCodeSystem verificationCodeSystem; private WhackMoleHandler _whackMoleHandler; private WhackMoleData _data; private Dictionary _moleModules; private void Awake() { _bodyModuleSystem = GetComponent(); FixSystemCenter.SystemDic.Register(this); } #region 打地鼠游戏流程控制 public void StartWhack(WhackMoleData levelData) { _data = levelData; // 打地鼠部分 WhackMoleHandler handler = new WhackMoleHandler(levelData); handler.OnBatchEnd += OnBatchEnd; handler.OnGameEnd += OnGameEnd; handler.Start(); // 流水线部分 if (levelData.HasPipeline()) { pipelineSystem.Init(levelData.checkRules, levelData.checkDatas); pipelineSystem.OnGameEnd += OnGameEnd; } // 赋值 _whackMoleHandler = handler; } private void OnBatchEnd() { if (_data.isAddVerifyCode) { verificationCodeSystem.StartVerification(); } } private void OnGameEnd() { // 打地鼠结果 _whackMoleHandler.EndWhackGame(); var whackRes = _whackMoleHandler.res; Debug.Log($"结果:共计{whackRes.totalMoleNum}个,成功击中{whackRes.hitMoleNum}个"); YarnVariableStorage.Instance.SetValue("$whackRes.totalMoleNum", whackRes.totalMoleNum); YarnVariableStorage.Instance.SetValue("$whackRes.hitMoleNum", whackRes.hitMoleNum); // 流水线结果 if (_data.HasPipeline()) { var pipelineRes = pipelineSystem.res; Debug.Log( $"流水线结果:共计{pipelineRes.totalProductNum}个,成功{pipelineRes.successNum}个,失败{pipelineRes.failNum}个"); YarnVariableStorage.Instance.SetValue("$whackRes.totalProductNum", pipelineRes.totalProductNum); YarnVariableStorage.Instance.SetValue("$whackRes.successNum", pipelineRes.successNum); YarnVariableStorage.Instance.SetValue("$whackRes.failNum", pipelineRes.failNum); } // 结束 DialogController.Instance?.StartDialogNode("打地鼠结束"); } #endregion #region 效果相关, 控制BodyModuleSystem实现 public void StartAllFlicker() { foreach (var module in _moleModules.Values) { module.StartFlicker(); } } public void StopAllFlicker() { foreach (var module in _moleModules.Values) { module.StopFlicker(); } } public Dictionary MoleModules { get { if (_moleModules == null) { _moleModules = new Dictionary(); foreach (var module in _bodyModuleSystem.BodyModules) { if (module is MoleModule moleModule) { _moleModules.Add(moleModule.data.moduleName, moleModule); } } } return _moleModules; } } #endregion } public static class WholeMoleCommand { private static WhackMoleSystem WhackMoleSystem => FixSystemCenter.SystemDic.Get(); [YarnCommand("start_whack_game")] public static void StartWhack(string levelName) { var levelData = ResourceKit.LoadAssetSync($"WhackMoleData/{levelName}.asset"); WhackMoleSystem.StartWhack(levelData); } } }