using QFramework; using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using XMLTool; public class ScoreController : MonoSingleton { public class Data { public Dictionary scoreDict; } public Dictionary moduleDict; public override void OnSingletonInit() { base.OnSingletonInit(); InitData(); } public void Init() { if (Global.Instance.curModule.type == "Exam" || Global.Instance.curModule.type == "All") { TypeEventSystem.Global.Register(OnStart); TypeEventSystem.Global.Register(OnQuit); } } public void InitData() { moduleDict = new Dictionary(); foreach (var item in Global.Instance.appData.Modules) { if (item.type == "Exam" || item.type == "All") { Data data = new Data() { scoreDict = new Dictionary() }; moduleDict.Add(item.ModuleName, data); } } } private void OnStart(OnModuleStart start) { var data = moduleDict[Global.Instance.curModule.ModuleName]; data.scoreDict.Clear(); foreach (var item in Global.Instance.curModule.score.scores) { item.value = 0; data.scoreDict.Add(item.step + item.name, item); } } public Dictionary GetCurScore() { var data = moduleDict[Global.Instance.curModule.ModuleName]; return data.scoreDict; } public void Add(string key, float value) { var data = moduleDict[Global.Instance.curModule.ModuleName]; var scoreDict = data.scoreDict; 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; } } else { Debug.LogError("没有找到 评分点:" + key); } } public void Set(string key, float value) { var data = moduleDict[Global.Instance.curModule.ModuleName]; var scoreDict = data.scoreDict; if (scoreDict.ContainsKey(key)) { scoreDict[key].value = value; } } private void OnQuit(OnModuleQuit quit) { TypeEventSystem.Global.UnRegister(OnStart); TypeEventSystem.Global.UnRegister(OnQuit); } }