重构
This commit is contained in:
@@ -2,6 +2,7 @@ using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Architecture.Core;
|
||||
|
||||
namespace GameFramework
|
||||
{
|
||||
@@ -32,7 +33,7 @@ namespace GameFramework
|
||||
|
||||
/// <summary>
|
||||
/// 得分管理器(持久单例)。
|
||||
/// 维护当前局得分,通过事件通知 UI,并管理 Top-10 排行榜存档。
|
||||
/// 维护当前局得分,通过 SO 事件通道通知 UI,并管理 Top-10 排行榜存档。
|
||||
/// </summary>
|
||||
public class ScoreManager : PersistentSingleton<ScoreManager>
|
||||
{
|
||||
@@ -42,10 +43,9 @@ namespace GameFramework
|
||||
// 当前局得分
|
||||
int currentScore = 0;
|
||||
|
||||
// 当得分变化时触发,参数为最新得分(动画过程中的中间值也会触发)
|
||||
public static event Action<int> onScoreChanged;
|
||||
// 当得分完成最终增加时触发,参数为最终得分
|
||||
public static event Action<int> onScoreSettled;
|
||||
[Header("SO 事件通道(替代 static onScoreChanged / onScoreSettled 事件,Inspector 拖入对应资产)")]
|
||||
[SerializeField] private IntEvent scoreChangedEvent;
|
||||
[SerializeField] private IntEvent scoreSettledEvent;
|
||||
|
||||
/// <summary>当前得分(只读)。</summary>
|
||||
public int CurrentScore => currentScore;
|
||||
@@ -75,8 +75,8 @@ namespace GameFramework
|
||||
public void SetScore(int value)
|
||||
{
|
||||
currentScore = Mathf.Max(0, value);
|
||||
onScoreChanged?.Invoke(currentScore);
|
||||
onScoreSettled?.Invoke(currentScore);
|
||||
scoreChangedEvent?.Raise(currentScore);
|
||||
scoreSettledEvent?.Raise(currentScore);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -85,8 +85,8 @@ namespace GameFramework
|
||||
public void ResetScore()
|
||||
{
|
||||
currentScore = 0;
|
||||
onScoreChanged?.Invoke(0);
|
||||
onScoreSettled?.Invoke(0);
|
||||
scoreChangedEvent?.Raise(0);
|
||||
scoreSettledEvent?.Raise(0);
|
||||
}
|
||||
|
||||
IEnumerator ScoreCountUpCoroutine(int from, int to)
|
||||
@@ -100,12 +100,12 @@ namespace GameFramework
|
||||
elapsed += Time.unscaledDeltaTime;
|
||||
float t = Mathf.Clamp01(elapsed / duration);
|
||||
int display = Mathf.RoundToInt(Mathf.Lerp(from, to, t));
|
||||
onScoreChanged?.Invoke(display);
|
||||
scoreChangedEvent?.Raise(display);
|
||||
yield return null;
|
||||
}
|
||||
|
||||
onScoreChanged?.Invoke(to);
|
||||
onScoreSettled?.Invoke(to);
|
||||
scoreChangedEvent?.Raise(to);
|
||||
scoreSettledEvent?.Raise(to);
|
||||
}
|
||||
|
||||
#region 排行榜
|
||||
|
||||
Reference in New Issue
Block a user