using QFramework; using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using XMLTool; public class ScoreController : MonoSingleton { public Dictionary scoreDict; public override void OnSingletonInit() { base.OnSingletonInit(); scoreDict = new Dictionary(); TypeEventSystem.Global.Register(OnStart).UnRegisterWhenGameObjectDestroyed(gameObject); TypeEventSystem.Global.Register(OnQuit).UnRegisterWhenGameObjectDestroyed(gameObject); } private void OnStart(OnModuleStart start) { foreach (var item in Global.Instance.curModule.score.scores) { item.value = 0; scoreDict.Add(item.step + item.name, item); } } public void Add(string key, float value) { if (scoreDict.ContainsKey(key)) { scoreDict[key].value += value; var sumScore = float.Parse(scoreDict[key].sum); if (scoreDict[key].value > sumScore) { scoreDict[key].value = sumScore; } if (scoreDict[key].value <= 0) { scoreDict[key].value = 0; } } } public void Set(string key, float value) { if (scoreDict.ContainsKey(key)) { scoreDict[key].value = value; } } private void OnQuit(OnModuleQuit quit) { scoreDict.Clear(); } }