162 lines
4.8 KiB
C#
162 lines
4.8 KiB
C#
using ReadyPlayerMe.Core.WebView;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using UnityEngine;
|
|
using static MainCanvasManager;
|
|
|
|
/// <summary>
|
|
/// 评分管理
|
|
/// </summary>
|
|
public class ScoreManager : MonoSingleton<ScoreManager>
|
|
{
|
|
/// <summary>
|
|
/// 步骤id对应api匹配规则
|
|
/// </summary>
|
|
Dictionary<string, List<ApidetailScore>> step_id_to_apis = new Dictionary<string, List<ApidetailScore>>();
|
|
/// <summary>
|
|
/// 步骤id对应分数
|
|
/// </summary>
|
|
Dictionary<string, float> step_id_to_score = new Dictionary<string, float>();
|
|
|
|
public float total_score;
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
//InitScoreData();
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 初始化评分规则数据
|
|
/// </summary>
|
|
public void InitScoreData()
|
|
{
|
|
for (int j = 0; j < task_panel.task_item_data.task_steplist.Count; j++)
|
|
{
|
|
var _task_step = task_panel.task_item_data.task_steplist[j];
|
|
Debug.Log(_task_step.id + "评分id123");
|
|
if (!step_id_to_apis.ContainsKey(_task_step.id))
|
|
step_id_to_apis.Add(_task_step.id,new List<ApidetailScore>());
|
|
if (!step_id_to_score.ContainsKey(_task_step.id))
|
|
step_id_to_score.Add(_task_step.id, 0);
|
|
for (int k = 0; k < _task_step.apiDetailList.Count; k++)
|
|
{
|
|
var _api_detail = _task_step.apiDetailList[k];
|
|
Debug.Log(_task_step.apiDetailList[k].apiFunction + "具体功能123");
|
|
step_id_to_apis[_task_step.id].Add(new ApidetailScore { functioName = _api_detail.apiFunction , isGET=false});
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 更新分数
|
|
/// </summary>
|
|
/// <param name="_api_name"></param>
|
|
public void UpdateScore(string _api_name)
|
|
{
|
|
if (GameManager.current_main_menu_type == MainMenuType.课程任务)
|
|
{
|
|
var _keys = FindKey(_api_name);
|
|
//对可能的步骤更新
|
|
for (int i = 0; i < _keys.Count; i++)
|
|
{
|
|
if (step_id_to_score[_keys[i]] == 0)
|
|
{
|
|
var _step = task_panel.task_item_data.task_steplist.Find(x => x.id == _keys[i]);
|
|
if (_step != null)
|
|
{
|
|
//得分
|
|
total_score += float.Parse(_step.stepScore);
|
|
step_id_to_score[_keys[i]] = float.Parse(_step.stepScore);
|
|
//提交步骤得分
|
|
Task_Setp_Back.instance.StepBack(_step, step_id_to_score[_keys[i]]);
|
|
}
|
|
}
|
|
}
|
|
if (MiniCanvasManager.Instance)
|
|
MiniCanvasManager.Instance.task_panel.score_text.text = "分数:" + total_score.ToString();
|
|
task_panel.score_text.text = "分数:" + total_score.ToString();
|
|
//把当前分数传递给客户端
|
|
WebSocketServerManager.Instance.SendScore(total_score.ToString());
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据api名称找到对应的步骤id
|
|
/// </summary>
|
|
/// <param name="_value"></param>
|
|
/// <returns>返回得分的步骤</returns>
|
|
public List<string> FindKey(string _value)
|
|
{
|
|
var _key = new List<string>();
|
|
foreach (var item in step_id_to_apis)
|
|
{
|
|
ApidetailScore apiscore=item.Value.Find(a => a.functioName == _value);
|
|
if (apiscore != null)
|
|
{
|
|
//满足当前api
|
|
apiscore.isGET = true;
|
|
//全部满足则得分
|
|
if (item.Value.All(a => a.isGET))
|
|
{
|
|
_key.Add(item.Key);
|
|
}
|
|
}
|
|
}
|
|
return _key;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 重置分数
|
|
/// </summary>
|
|
public void ResetScore()
|
|
{
|
|
total_score = 0;
|
|
var keys = step_id_to_score.Keys.ToList();
|
|
keys.ForEach(x =>
|
|
{
|
|
if (step_id_to_score.ContainsKey(x))
|
|
{
|
|
step_id_to_score[x] = 0;
|
|
}
|
|
});
|
|
|
|
var keys2=step_id_to_apis.Keys.ToList();
|
|
keys2.ForEach(x =>
|
|
{
|
|
step_id_to_apis[x].ForEach(b =>
|
|
{
|
|
b.isGET = false;
|
|
});
|
|
});
|
|
|
|
if (MiniCanvasManager.Instance)
|
|
MiniCanvasManager.Instance.task_panel.score_text.text = "分数:" + total_score.ToString();
|
|
task_panel.score_text.text = "分数:" + total_score.ToString();
|
|
//把当前分数传递给客户端
|
|
WebSocketServerManager.Instance.SendScore(total_score.ToString());
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// api判分类
|
|
/// </summary>
|
|
public class ApidetailScore
|
|
{
|
|
/// <summary>
|
|
/// 方法名称
|
|
/// </summary>
|
|
public string functioName;
|
|
/// <summary>
|
|
/// 是否得分
|
|
/// </summary>
|
|
public bool isGET;
|
|
}
|