89 lines
2.5 KiB
C#
89 lines
2.5 KiB
C#
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;
|
|
|
|
private Dictionary<string, MoleModule> _moleModules;
|
|
|
|
private void Awake()
|
|
{
|
|
_bodyModuleSystem = GetComponent<BodyModuleSystem>();
|
|
FixSystemCenter.SystemDic.Register(this);
|
|
}
|
|
|
|
#region 打地鼠游戏流程控制
|
|
|
|
public void StartWhack(WhackMoleData levelData)
|
|
{
|
|
WhackMoleHandler handler = new WhackMoleHandler(levelData);
|
|
handler.OnGameEnd += OnGameEnd;
|
|
handler.Start();
|
|
}
|
|
|
|
private void OnGameEnd(WhackMoleRes res)
|
|
{
|
|
Debug.Log($"结果:共计{res.totalMoleNum}个,成功击中{res.hitMoleNum}个");
|
|
}
|
|
|
|
#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<string, MoleModule> MoleModules
|
|
{
|
|
get
|
|
{
|
|
if (_moleModules == null)
|
|
{
|
|
_moleModules = new Dictionary<string, MoleModule>();
|
|
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<WhackMoleSystem>();
|
|
|
|
[YarnCommand("start_whack_game")]
|
|
public static void StartWhack(string levelName)
|
|
{
|
|
var levelData = ResourceKit.LoadAssetSync<WhackMoleData>($"WhackMoleData/{levelName}.asset");
|
|
WhackMoleSystem.StartWhack(levelData);
|
|
}
|
|
}
|
|
} |