评分面板代码,主要功能:显示错误信息详情,扣分,错误类型;最终得分以及操作的评价
思路是:获取错误信息的表,里面记录了错误的信息情况;最后传递这个错误数据model给ui显示的view代码;对于ui的操作就是这个view干的事情,我写的是一页记录三行错误详情,多余的通过翻页来观看,翻页的信息展示主要通过标识也来确定,第几页就更新显示错误数据中的几条错误详情;下面是我这个思路VR面板显示的代码翻页是采用vr方向键控制的,下面代码仅供参考,具体的变量会不同。

using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using DG.Tweening; using UnityEngine.Events; public class VR_EvaluationPanel : Panel { private WrongDetail[] wrongListShow; private int maxRow = 3; private int maxPage = 0; private int currentPage = 1; private int BeforePage = 0; private Button leftDirect; private Button rightDirect; private Text leftPage; private Text rightPage; private bool isStartDerection = false; private Task currentTask; private VRController rightController; protected override void Awake() { base.Awake(); } public override void SetPanelDisplay(bool display) { Init(); this.DelayToDo(0.1f, () => { isDisplay = display; isStartDerection = true; }); myRectTransfrom.gameObject.SetActive(display); } private void Update() { DirectionController(); UpdateShowError(); } private void UpdateShowError() { if (BeforePage != currentPage && isStartDerection) { for (int i = 0; i < wrongListShow.Length; i++) { wrongListShow[i].UpdateScore("", "", ""); } int j = 0; for (int i = 0; i < currentTask.ErrorList.Count; i++) { if ((currentPage - 1) * maxRow <= i && currentPage * maxRow > i) { //if (j >= maxRow) return; Debug.Log("j" + " " + j); Debug.Log(" wrongListShow[j]" + " " + wrongListShow.Length); wrongListShow[j].UpdateScore(currentTask.ErrorList[i].errorType.ToString(), currentTask.ErrorList[i].errorInformation, currentTask.ErrorList[i].score.ToString()); j++; } } BeforePage = currentPage; } } private void DirectionController() { if (isStartDerection) { if (rightController == null) rightController = VRManager.Instance.GetController(ControllerType.Right); rightController.OnTouchPadPressDown(() => { }, () => { }, () => { currentPage = Mathf.Clamp(currentPage - 1, 1, maxPage); leftPage.text = currentPage + ""; }, () => { currentPage = Mathf.Clamp(currentPage + 1, 1, maxPage); leftPage.text = currentPage + ""; }); } } public void SetOpenEvalutionPanel(bool isOpen, Task currentTask) { this.currentTask = currentTask; SetPanelDisplay(isOpen); } protected override void OnDestroy() { base.OnDestroy(); } private void Init() { if (currentTask.ErrorList.Count % maxRow != 0) { maxPage = currentTask.ErrorList.Count / maxRow + 1; } else { maxPage = currentTask.ErrorList.Count / maxRow; } leftPage = this.transform.Find("BG/ScroingArea/Page/forward").GetComponent<Text>(); rightPage = this.transform.Find("BG/ScroingArea/Page/Back").GetComponent<Text>(); leftPage.text = "1"; rightPage.text = maxPage + ""; leftDirect = this.transform.Find("BG/ScroingArea/Page/ForwardButton").GetComponent<Button>(); rightDirect = this.transform.Find("BG/ScroingArea/Page/BackButton").GetComponent<Button>(); rightController = VRManager.Instance.GetController(ControllerType.Right); wrongListShow = new WrongDetail[maxRow]; for (int i = 0; i < maxRow; i++) { wrongListShow[i] = new WrongDetail(this.transform.Find("BG/ScroingArea/WrongInformation/Detail/" + i + "/0").GetComponent<Text>(), this.transform.Find("BG/ScroingArea/WrongInformation/Detail/" + i + "/1").GetComponent<Text>(), this.transform.Find("BG/ScroingArea/WrongInformation/Detail/" + i + "/2").GetComponent<Text>()); } OperationEvaluation(currentTask.CurrentScore); } private void OperationEvaluation(float score) { this.transform.Find("BG/SyntheticalGrade/Score").GetComponent<Text>().text = score.ToString(); switch ((int)score / 10) { case 10: this.transform.Find("BG/SyntheticalEvaluation/Inner").GetComponent<Text>().text = OperationGrade.操作熟练.ToString(); break; case 9: this.transform.Find("BG/SyntheticalEvaluation/Inner").GetComponent<Text>().text = OperationGrade.操作熟练.ToString(); break; case 8: this.transform.Find("BG/SyntheticalEvaluation/Inner").GetComponent<Text>().text = OperationGrade.操作一般.ToString(); break; default: this.transform.Find("BG/SyntheticalEvaluation/Inner").GetComponent<Text>().text = OperationGrade.操作生疏.ToString(); break; } } private enum OperationGrade { 操作生疏 = 0, 操作一般 = 1, 操作熟练 = 2, } public class WrongDetail { private Text errorType; private Text errorDetail; private Text errorScore; public WrongDetail(Text errorType, Text errorDetail, Text errorScore) { this.errorType = errorType; this.errorType.text = ""; this.errorDetail = errorDetail; this.errorDetail.text = ""; this.errorScore = errorScore; this.errorScore.text = ""; } public void UpdateScore(string errorType, string errorDetail, string errorScore) { this.errorType.text = errorType; this.errorDetail.text = errorDetail; this.errorScore.text = errorScore; } } }