using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using XFramework; using XFramework.Objects; //科目1 科目2 训练使用的窗口 public class AppraiseWindow1 : AppraiseWindowBase { //显示评分 public Text text_score; float transportScore;//转运时间评分 该评分根据教员端设定的最短时间计算 float weightScore;//受权重影响的指标评价总分数 float otherScore;//传回的评分中不受权重调节的部分 例如距离水源的距离 答题扣分等等 XDictionary deductMsg;//转运时间之外的评估项和对应基础得分 XDictionary deductWeight;//转运时间之外的评估项和对应权重 public Transform deductPointParent;//评价指标父物体 附带 Group组件 可以自动确定子物体的位置 //转运时间展示器 public TransportScoreCtrl timeScoreCtrl; public override void SetResultMsg(NetAnswerSheet value, OnlineStudent onlineStudent) { base.SetResultMsg(value, onlineStudent); CreatAppraisePoints(value.deductMsg); otherScore = value.score- CalculateTotleScore();//计算不受权重影响的评分 transportScore = ShowTransportTime(value.transportTime); ShowScore(); } //创建评价指标 记录指标对应的权重值 权重范围为0-2 private void CreatAppraisePoints(XDictionary deductMsg) { if (deductMsg == null) return; deductWeight = new XDictionary(); this.deductMsg = deductMsg; foreach (var item in deductMsg) { deductWeight[item.Key] = ResourcesCreater.InstantiatePrefab("评价指标", deductPointParent).GetComponent().InjectInitData(item.Key, WeightChanged);//记录当前因素对应的权重值 } } //权重变化 private void WeightChanged(string age0, float value) { deductWeight[age0] = value; CalculateTotleScore(); } /// /// 显示转运用时 /// private float ShowTransportTime(int time) { if (time == 0)//无效数据 不显示 非展开科目 或者展开科目展开未完成时为0 { timeScoreCtrl.gameObject.SetActive(false); return 0; } timeScoreCtrl.gameObject.SetActive(true); return timeScoreCtrl.GetComponent().InjectTimeGetScore(time, TransportTimeScoreChanged); } //转运时间扣分 值发生变化 private void TransportTimeScoreChanged( float score) { transportScore = score; ShowScore(); } //计算受权重影响的评价指标 private float CalculateTotleScore() { weightScore = 0; foreach (var item in deductMsg) { if (deductWeight.ContainsKey(item.Key)) { weightScore += item.Value * deductWeight[item.Key]; } else { weightScore += item.Value; } } ShowScore(); return weightScore; } //显示扣除的总分 private void ShowScore() { text_score.text = (weightScore+ transportScore+otherScore).ToString("0.00"); } //界面隐藏时 初始化界面 protected override void Clear() { base.Clear(); Transform[] deductPoints = deductPointParent.GetComponentsInChildren(); for (int i = 0; i < deductPoints.Length; i++)//关闭时回收所有的权重滑块和分数 { ObjectPool.Instance.Destroy(deductPoints[i].gameObject); } timeScoreCtrl.gameObject.SetActive(false);//隐藏转运部分扣分项 } }