158 lines
6.1 KiB
C#
158 lines
6.1 KiB
C#
using CG.UTility;
|
|
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
#if UNITY_EDITOR || UNITY_STANDALONE_WIN
|
|
using System.IO;
|
|
using System.Text;
|
|
#endif
|
|
using UnityEngine;
|
|
/*******************************************************************************
|
|
*Create By CG
|
|
*Function 安装部署
|
|
*******************************************************************************/
|
|
namespace ZXK.LouDiXvMuNiu
|
|
{
|
|
public class DataNiuHandler
|
|
{
|
|
public BindablePropertyRef<NiuData> CurNiuHandler = new BindablePropertyRef<NiuData>()
|
|
{
|
|
Value = new NiuData()
|
|
};
|
|
|
|
private List<NiuData> _niuDataArray = new List<NiuData>();
|
|
public List<NiuData> NiuDataArray { get => _niuDataArray; }
|
|
|
|
private Dictionary<string, List<NiuData>> _niuStepTypeDic = new Dictionary<string, List<NiuData>>();
|
|
public Dictionary<string, List<NiuData>> NiuStepTypeDic { get => _niuStepTypeDic; }
|
|
|
|
/// <summary>
|
|
/// 考核分数管理
|
|
/// [模块内容[三级任务名称,得分]]
|
|
/// </summary>
|
|
private Dictionary<string, Dictionary<string, float>> _examScore = new Dictionary<string, Dictionary<string, float>>();
|
|
|
|
public DataNiuHandler()
|
|
{
|
|
InitAppData();
|
|
}
|
|
|
|
public void InitAppData()
|
|
{
|
|
//#if UNITY_EDITOR || UNITY_STANDALONE_WIN
|
|
// string[] excelList = Directory.GetFiles(Application.streamingAssetsPath + ConstCtrl.EXCEL_PATH, "*.xlsx");
|
|
// ExcelUtility excel = new ExcelUtility(excelList[0]);
|
|
// excel.ConvertToJson(Application.streamingAssetsPath + ConstCtrl.JSON_PATH + Path.GetFileNameWithoutExtension(excelList[0]) + ".txt", new UTF8Encoding(false));
|
|
//#endif
|
|
string Niupath = Application.streamingAssetsPath + ConstCtrl.JSON_PATH + "NiuData.txt";
|
|
TxtFileHandle.ReadAllTxt(Niupath, (string vul) =>
|
|
{
|
|
_niuDataArray = JsonConvert.DeserializeObject<List<NiuData>>(vul);
|
|
|
|
for (int i = 0; i < _niuDataArray.Count; i++)
|
|
{
|
|
if (string.IsNullOrEmpty(_niuDataArray[i].TaskName)) continue;
|
|
if (_niuStepTypeDic.ContainsKey(_niuDataArray[i].ModuleName))
|
|
{
|
|
_niuStepTypeDic[_niuDataArray[i].ModuleName].Add(_niuDataArray[i]);
|
|
}
|
|
else
|
|
{
|
|
List<NiuData> temp = new List<NiuData>();
|
|
temp.Add(_niuDataArray[i]);
|
|
_niuStepTypeDic.Add(_niuDataArray[i].ModuleName, temp);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
public NiuData GetNextStep(NiuData curStep=null)
|
|
{
|
|
if (curStep == null) curStep = CurNiuHandler.Value;
|
|
List<NiuData> tempData = GameManager.Instance._DataNiuHandler.NiuStepTypeDic[GameManager.Instance._CurModelType];
|
|
for (int i = 0; i < tempData.Count; i++)
|
|
{
|
|
if (tempData[i].id == curStep.id + 1)
|
|
{
|
|
return tempData[i];
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public NiuData GetNextStep(int nextID)
|
|
{
|
|
List<NiuData> tempData = GameManager.Instance._DataNiuHandler.NiuStepTypeDic[GameManager.Instance._CurModelType];
|
|
for (int i = 0; i < tempData.Count; i++)
|
|
{
|
|
if (tempData[i].id == nextID)
|
|
{
|
|
NiuSceneMng._Instance.StepSetCameraTR(CurNiuHandler.Value, tempData[i]);
|
|
return tempData[i];
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据成绩单布局返回成绩
|
|
/// </summary>
|
|
/// <returns>[模块内容,三级任务名称,总成绩,实际成绩]</returns>
|
|
public Queue<string[]> GetExamScore()
|
|
{
|
|
Queue<string[]> scoreFinish = new Queue<string[]>();
|
|
|
|
NiuData curstep = null;
|
|
NiuData nextstep = null;
|
|
float curStepChildTotalScore = 0;
|
|
float realityScore = 0;
|
|
|
|
for (int i = 0; i < _niuDataArray.Count; i++)
|
|
{
|
|
if (string.IsNullOrEmpty(_niuDataArray[i].TaskName)|| _niuDataArray[i].TaskName==ConstCtrl.TaskName_JieShao) continue;
|
|
curstep = _niuDataArray[i];
|
|
if (i == _niuDataArray.Count - 1)
|
|
{
|
|
nextstep = null;
|
|
}
|
|
else
|
|
{
|
|
nextstep = _niuDataArray[i + 1];
|
|
}
|
|
curStepChildTotalScore += curstep.Score;
|
|
if (nextstep == null || !nextstep.ThreeTaskName.Equals(curstep.ThreeTaskName))
|
|
{
|
|
realityScore = 0;
|
|
if (_examScore.ContainsKey(curstep.ModuleName) && _examScore[curstep.ModuleName].ContainsKey(curstep.ThreeTaskName))
|
|
{
|
|
realityScore = _examScore[curstep.ModuleName][curstep.ThreeTaskName];
|
|
}
|
|
scoreFinish.Enqueue(new string[] { curstep.ModuleName, curstep.ThreeTaskName, curStepChildTotalScore.ToString(), realityScore.ToString() });
|
|
curStepChildTotalScore = 0;
|
|
}
|
|
}
|
|
return scoreFinish;
|
|
}
|
|
/// <summary>
|
|
/// 操作正确步骤后得分
|
|
/// </summary>
|
|
/// <param name="bigStepName">模块内容</param>
|
|
/// <param name="smallStepName">三级任务名称</param>
|
|
/// <param name="score">当前步骤可得分数</param>
|
|
/// <returns></returns>
|
|
public float AddScore(string bigStepName, string smallStepName, float score)
|
|
{
|
|
if (!_examScore.ContainsKey(bigStepName))
|
|
{
|
|
_examScore.Add(bigStepName, new Dictionary<string, float>());
|
|
}
|
|
if (!_examScore[bigStepName].ContainsKey(smallStepName))
|
|
{
|
|
_examScore[bigStepName].Add(smallStepName, 0);
|
|
}
|
|
_examScore[bigStepName][smallStepName] += score;
|
|
return _examScore[bigStepName][smallStepName];
|
|
}
|
|
}
|
|
} |