打地鼠重置
This commit is contained in:
@@ -1,24 +1,40 @@
|
||||
using UnityEngine;
|
||||
using System;
|
||||
using AibisDream.Kit;
|
||||
using DG.Tweening;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AibisDream.FixSystem
|
||||
{
|
||||
public class MoleModule : BodyModule
|
||||
{
|
||||
private static WhackMoleSystem WhackMoleSystem => FixSystemCenter.SystemDic.Get<WhackMoleSystem>();
|
||||
#region 效果组件
|
||||
|
||||
private Material _picMaterial;
|
||||
|
||||
private TMP_Text _screenText;
|
||||
private SpriteRenderer _processBar;
|
||||
|
||||
#endregion
|
||||
|
||||
public bool isInMoleGame;
|
||||
public bool isLightOn;
|
||||
private static readonly int SineGlowFade = Shader.PropertyToID("_SineGlowFade");
|
||||
private static readonly int AddColorFade = Shader.PropertyToID("_AddColorFade");
|
||||
private static readonly int AddColorColor = Shader.PropertyToID("_AddColorColor");
|
||||
|
||||
private float _countDownPct;
|
||||
private Tween _countDownTween;
|
||||
|
||||
public event Action<MoleModule, bool> OnLightMoleEnd;
|
||||
|
||||
protected override void InitReference()
|
||||
{
|
||||
base.InitReference();
|
||||
_picMaterial = transform.Find("Module Pic").GetComponent<SpriteRenderer>().material;
|
||||
_screenText = transform.Find("Screen Text").GetComponent<TMP_Text>();
|
||||
_processBar = transform.Find("Process Bar").GetComponent<SpriteRenderer>();
|
||||
}
|
||||
|
||||
|
||||
// 重写PlugIn和PlugOut就好了
|
||||
public override void PlugIn()
|
||||
{
|
||||
@@ -26,13 +42,13 @@ namespace AibisDream.FixSystem
|
||||
{
|
||||
base.PlugIn();
|
||||
}
|
||||
else
|
||||
else if (isLightOn)
|
||||
{
|
||||
// 触发WhackMoleSystem的插入事件
|
||||
WhackMoleSystem.OnPlugIn(data.moduleName);
|
||||
// 打中了
|
||||
HitMole();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public override void PlugOut()
|
||||
{
|
||||
// TODO 拔出来会有效果吗?存疑
|
||||
@@ -42,23 +58,78 @@ namespace AibisDream.FixSystem
|
||||
|
||||
public void StartFlicker()
|
||||
{
|
||||
_screenText.text = "Checking...";
|
||||
_picMaterial.SetFloat(SineGlowFade, 1);
|
||||
}
|
||||
|
||||
|
||||
public void StopFlicker()
|
||||
{
|
||||
_picMaterial.SetFloat(SineGlowFade, 0);
|
||||
}
|
||||
|
||||
public void LightOn(Color color)
|
||||
public void LightOn(float lightTime)
|
||||
{
|
||||
_picMaterial.SetColor(AddColorColor, color);
|
||||
// 视觉部分
|
||||
StartFlicker();
|
||||
_picMaterial.SetColor(AddColorColor, Color.red);
|
||||
_picMaterial.SetFloat(AddColorFade, 1);
|
||||
_processBar.color = Color.red;
|
||||
_processBar.transform.localScale = Vector3.one;
|
||||
|
||||
// 逻辑部分
|
||||
isLightOn = true;
|
||||
_countDownPct = 100;
|
||||
_countDownTween = DOTween.To(() => _countDownPct, value => _countDownPct = value, 0, lightTime)
|
||||
.OnUpdate(CountingDown)
|
||||
.OnComplete(OverTime);
|
||||
}
|
||||
|
||||
public void LightOff()
|
||||
private void CountingDown()
|
||||
{
|
||||
// TODO 显示倒计时
|
||||
_screenText.text = $"{_countDownPct:F1}%";
|
||||
_processBar.transform.localScale = new Vector3(_countDownPct / 100, 1, 1);
|
||||
}
|
||||
|
||||
private void OverTime()
|
||||
{
|
||||
// TODO 超时
|
||||
isLightOn = false;
|
||||
LightOff();
|
||||
OnLightMoleEnd?.Invoke(this, false);
|
||||
OnLightMoleEnd = null;
|
||||
_countDownTween = null;
|
||||
}
|
||||
|
||||
private void LightOff()
|
||||
{
|
||||
_picMaterial.SetFloat(AddColorFade, 0);
|
||||
_processBar.color = Color.clear;
|
||||
// TODO 继续闪烁
|
||||
StartFlicker();
|
||||
}
|
||||
|
||||
private void HitMole()
|
||||
{
|
||||
_countDownTween.Kill();
|
||||
isLightOn = false;
|
||||
// 命中后成功反馈
|
||||
ActionKit.Sequence()
|
||||
.Callback(() =>
|
||||
{
|
||||
if (ColorUtility.TryParseHtmlString("#67C23A", out var color))
|
||||
{
|
||||
_picMaterial.SetColor(AddColorColor, color);
|
||||
}
|
||||
})
|
||||
.Callback(() => _processBar.color = Color.green)
|
||||
.Callback(() => _screenText.text = "Success")
|
||||
.Delay(0.7f)
|
||||
.Callback(LightOff)
|
||||
.Start(this);
|
||||
|
||||
OnLightMoleEnd?.Invoke(this, true);
|
||||
OnLightMoleEnd = null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
Reference in New Issue
Block a user