114 lines
3.2 KiB
C#
114 lines
3.2 KiB
C#
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using UnityEngine;
|
|
|
|
public class ScoreManager : MonoSingleton<ScoreManager>
|
|
{
|
|
|
|
public List<ScoreBase> scoreSubjectList;
|
|
|
|
private void Awake()
|
|
{
|
|
scoreSubjectList = transform.GetComponentsInChildren<ScoreBase>(true).ToList();
|
|
DontDestroyOnLoad(this);
|
|
}
|
|
|
|
|
|
|
|
public ScoreBase GetScoreBaseBySchemeID(int _schemeID)
|
|
{
|
|
return scoreSubjectList.Find(a => a.schemeId == _schemeID);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 提交
|
|
/// </summary>
|
|
private void OnSubmit()
|
|
{
|
|
Debug.Log("OnCompelete");
|
|
if (GameManager.RunModelMgr.ModeType == E_ModeType.Study)
|
|
{
|
|
GameManager.NetMgr.SendResult(null);
|
|
}
|
|
else if (GameManager.RunModelMgr.ModeType == E_ModeType.Practice || GameManager.RunModelMgr.ModeType == E_ModeType.Exam)
|
|
{
|
|
ScoreModel scoreModel = GetScore(GameManager.RunModelMgr.schemeID);
|
|
string resultData = JsonConvert.SerializeObject(scoreModel);
|
|
Debug.Log(resultData);
|
|
GameManager.NetMgr.SendResult(resultData);
|
|
if (GameManager.RunModelMgr.ModeType == E_ModeType.Exam)
|
|
{
|
|
///
|
|
}
|
|
}
|
|
}
|
|
void Update()
|
|
{
|
|
if (Input.GetKeyDown(KeyCode.L))
|
|
{
|
|
OnSubmit();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 重置数据
|
|
/// </summary>
|
|
public void ReInit()
|
|
{
|
|
Debug.Log("重置计分脚本");
|
|
scoreSubjectList.ForEach(a => { a.Init(); });
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 检测分数
|
|
/// </summary>
|
|
/// <param name="systemctlid"></param>
|
|
/// <param name="schemeid"></param>
|
|
/// <param name="subProcessid">步骤</param>
|
|
public void Check(string triggerName, object para, int systemctlid = 0, int schemeid = 0)
|
|
{
|
|
if (systemctlid == 0)
|
|
systemctlid = GameManager.Instance.systemId;
|
|
if (schemeid == 0)
|
|
schemeid = GameManager.RunModelMgr.schemeID;
|
|
|
|
ScoreBase sb = scoreSubjectList.Find(a => a.systemId == systemctlid && a.schemeId == schemeid);
|
|
sb.CheckScore(triggerName, para);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据方案/科目ID获取总分
|
|
/// </summary>
|
|
/// <param name="subjectid"></param>
|
|
/// <returns></returns>
|
|
public ScoreModel GetScore(int subjectid)
|
|
{
|
|
ScoreBase sb = scoreSubjectList.Find(a => a.schemeId == subjectid);
|
|
ScoreModel scoreModel = new ScoreModel();
|
|
scoreModel.time = (DateTime.Now - GameManager.RunModelMgr.startTime).TotalSeconds.ToString();
|
|
scoreModel.score = sb.GetTotalScore();
|
|
var step = sb.GetStepScore();
|
|
foreach (var item in step)
|
|
{
|
|
ScoreInfo scoreInfo = new ScoreInfo();
|
|
scoreInfo.setScore = item.Value.currentScore;
|
|
scoreInfo.defaultScore = item.Value.maxScore;
|
|
scoreInfo.stepName = item.Value.subProcessName;
|
|
scoreInfo.testPoint = item.Value.tips;
|
|
scoreInfo.isKey = item.Value.isOneVoteVeto;
|
|
scoreModel.stepList.Add(scoreInfo);
|
|
}
|
|
|
|
return scoreModel;
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
Debug.Log("scoreManger.destroy");
|
|
|
|
}
|
|
} |