123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using ChivaXR.Op;
- using QFramework;
- using UnityEngine.UI;
- using VRTK;
- public class ExamResultPanel : MonoBehaviour
- {
- public RenfenceHand hand = RenfenceHand.LeftHand;
- private GameObject scoreItemPrefab;
- private Transform scoreContent;
- public Text scoreText;
- /// <summary>
- /// 用时
- /// </summary>
- public Text m_TakeTime;
- public Button m_ExitExamBtn;
-
- public ScrollRect scrollRect;
- public void Awake()
- {
- scoreItemPrefab = transform.Find("ResultScroll/Viewport/ScoreItem").gameObject;
- scoreContent = transform.Find("ResultScroll/Viewport/Content");
- scoreText = transform.Find("TitleScoreTitle/TitleScore").GetComponent<Text>();
- m_TakeTime = transform.Find("TitleScoreTitle/Time").GetComponent<Text>();
- m_ExitExamBtn = transform.Find("ExitExamBtn").GetComponent<Button>();
- m_ExitExamBtn.onClick.AddListener(OnExitExamBtnClick);
-
- scrollRect = transform.Find("ResultScroll").GetComponent<ScrollRect>();
- }
- public void Start()
- {
- Transform hander = VRTK_DeviceFinder.HeadsetTransform();
- transform.parent.position = hander.transform.position + new Vector3(hander.transform.forward.x, 0, hander.transform.forward.z).normalized * 1.5f;
- transform.parent.eulerAngles = new Vector3(0, hander.transform.eulerAngles.y, 0);
- }
- /// <summary>
- /// 打开成绩列表
- /// </summary>
- public void ShowScoreList(List<ExamProcessElement> elements, float totalScore,float _totalTime)
- {
- foreach (var item in elements)
- {
- GameObject tmpScoreItemObj = Instantiate<GameObject>(scoreItemPrefab, scoreContent);
- ScoreItem tmpScoreItem = tmpScoreItemObj.GetComponent<ScoreItem>();
- if (tmpScoreItem != null)
- {
- tmpScoreItemObj.SetActive(true);
- tmpScoreItem.InitData(item);
- }
- }
- scoreText.text = totalScore.ToString();
- m_TakeTime.text = _totalTime + "分钟";
- scrollRect.verticalNormalizedPosition = 1;
- }
- float value = 1;
- void Update()
- {
- GameObject handObj;
- if (hand == RenfenceHand.LeftHand) handObj = VRTK_DeviceFinder.GetControllerLeftHand();
- else handObj = VRTK_DeviceFinder.GetControllerRightHand();
- VRTK_DeviceFinder.GetControllerRightHand();
- VRTK_ControllerReference handReference = VRTK_ControllerReference.GetControllerReference(handObj);
- if (VRTK_SDK_Bridge.GetControllerButtonState(SDK_BaseController.ButtonTypes.Touchpad, SDK_BaseController.ButtonPressTypes.Touch, handReference))
- {
- Vector2 axis = VRTK_SDK_Bridge.GetControllerAxis(SDK_BaseController.ButtonTypes.Touchpad, handReference);
- if (axis.y > 0.7f)
- {
- if (value >= 1) return;
- value += Time.deltaTime * 0.05f;
- scrollRect.verticalNormalizedPosition = value;
- }
- else if (axis.y < -0.7f)
- {
- if (value <= 0) return;
- value -= Time.deltaTime * 0.05f;
- scrollRect.verticalNormalizedPosition = value;
- }
- }
- }
- public void OnExitExamBtnClick()
- {
- // 隐藏当前面板,显示退出提示面板
- gameObject.SetActive(false);
- }
- }
|