109 lines
2.6 KiB
C#
109 lines
2.6 KiB
C#
using QFramework;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using XMLTool;
|
|
|
|
public class ScoreController : MonoSingleton<ScoreController>
|
|
{
|
|
public class Data
|
|
{
|
|
public Dictionary<string, ScoreStep> scoreDict;
|
|
}
|
|
|
|
public Dictionary<string, Data> 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<OnModuleStart>(OnStart);
|
|
TypeEventSystem.Global.Register<OnModuleQuit>(OnQuit);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
public void InitData()
|
|
{
|
|
moduleDict = new Dictionary<string, Data>();
|
|
foreach (var item in Global.Instance.appData.Modules)
|
|
{
|
|
if (item.type == "Exam" || item.type == "All")
|
|
{
|
|
Data data = new Data() { scoreDict = new Dictionary<string, ScoreStep>() };
|
|
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<string, ScoreStep> 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;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
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<OnModuleStart>(OnStart);
|
|
TypeEventSystem.Global.UnRegister<OnModuleQuit>(OnQuit);
|
|
}
|
|
|
|
|
|
}
|