using System; using System.Collections; using System.Collections.Generic; using System.Data; using System.Diagnostics.Contracts; using Unity.VisualScripting; using UnityEngine; using UnityEngine.SceneManagement; using UnityEngine.UI; using UnityEngine.XR; using static UnityEditor.PlayerSettings; public class Submit : MonoBehaviour { /// /// 提交按钮 /// public Button submitbutton; /// /// 交卷按钮 /// public Button onvolumebutton; /// /// 练习的分页面 /// public GameObject practicepanl; /// /// 查看答案按钮 /// public Button answerbutton; /// /// 考试分数 /// public Text marktext; /// /// 返回按钮 /// public Button backbutton; /// /// 考核面板 /// public GameObject examinepanl; /// /// 技能冷却时间 /// public float examinetimer = 10f; /// /// 技能冷却时间 /// public float skilltimer = 0f; /// /// 技能冷却图片 /// public Image coolingimage; /// /// 技能冷却开关 /// private bool isCooldown = false; /// /// 系统提示 /// public Text warntext; /// /// 体统提示时间 /// public float timer = 10f; /// /// 倒计时 /// public Text timetext; /// /// 提示是否交卷页面 /// public GameObject submissionpromptpanl; /// /// 确定按钮 /// public Button submitbutton2; /// /// 取消按钮 /// public Button cancelbutton2; /// /// 三个菜单按钮 /// public Toggle electricitychargeaccounting, powersupplycontract, contract; /// /// 初始化用户名 /// public Text nametext; /// /// 初始化时间 /// public Text loginname; /// /// 覆约合同预设体 /// public GameObject retreatyobj; /// /// 电费计算预设体 /// public GameObject electricchargeobj; /// /// 覆约电费供电页面练习预制体生成位置 /// public RectTransform retreatypanl; public RectTransform powersupplypanl; public RectTransform electricchargepanl; /// /// 接收覆约合同的预设体 /// public GameObject retreatpreform; public GameObject electricchargeprrform; /// /// 初始化每个考试toggle显示按钮 /// public Vector3 pos; /// /// 提交练习那个页面区分 /// public Judgmentstate judgmentstate; /// /// 电费核算答案查询页面 /// public GameObject viewimage; /// /// 电费核算取消按钮 /// public Button forkoffbutton; private void Awake() { Initialize();//初始化 switch (ScoreManager.Instance.Examinationpaper) { case Examinationpaper.practice: Practicesubject();//练习页面 break; case Examinationpaper.Reviewexamination: Reviewpaper();//覆约页面 break; case Examinationpaper.Powersupplytest: Powersupplytestpaper();//供电页面 break; case Examinationpaper.Electricityfeetest: Electricityexaminationpaper();//电费页面 break; default: break; } } /// /// 初始化场景 /// private void Initialize() { pos = contract.transform.position; loginname.text = PlayerPrefs.GetString("time"); nametext.text = PlayerPrefs.GetString("Name"); Debug.LogError(ScoreManager.Instance.Examinationpaper); retreatyobj = Resources.Load("UIpanel/practice1"); electricchargeobj = Resources.Load("UIpanel/practicepanl3"); } void Start() { submitbutton.onClick.AddListener(() => { switch (ScoreManager.Instance.Judgmentstate) { case Judgmentstate.page1: Practicesubmission1(); break; case Judgmentstate.page2: Practicesubmission2(); break; case Judgmentstate.page3: Practicesubmission3(); break; default: break; } }); backbutton.onClick.AddListener(() => { switch (ScoreManager.Instance.Judgmentstate) { case Judgmentstate.page1: Repractice1(); break; case Judgmentstate.page2: Repractice2(); break; case Judgmentstate.page3: Repractice3(); break; default: break; } }); onvolumebutton.onClick.AddListener(() => { submissionpromptpanl.SetActive(true); }); cancelbutton2.onClick.AddListener(() => { submissionpromptpanl.SetActive(false); }); submitbutton2.onClick.AddListener(() => { switch (ScoreManager.Instance.Examinationpaper) { case Examinationpaper.practice: break; case Examinationpaper.Reviewexamination: Handinanexaminationpaper1(); break; case Examinationpaper.Powersupplytest: Handinanexaminationpaper2(); break; case Examinationpaper.Electricityfeetest: Handinanexaminationpaper3(); break; default: break; } }); Answer();//查看答案 } private void Answer() { answerbutton.onClick.AddListener(() => { viewimage.SetActive(true); }); forkoffbutton.onClick.AddListener(() => { viewimage.SetActive(false); }); } private void Handinanexaminationpaper3() { Debug.Log("电费核算交卷"); electricchargeprrform = GameObject.Find("practicepanl3(Clone)"); Destroy(electricchargeprrform); submissionpromptpanl.SetActive(false); onvolumebutton.gameObject.SetActive(false); isCooldown = true; examinepanl.SetActive(true); } private void Handinanexaminationpaper2() { } private void Handinanexaminationpaper1() { retreatpreform = GameObject.Find("practice1(Clone)"); retreatpreform.SetActive(false); submissionpromptpanl.SetActive(false); onvolumebutton.gameObject.SetActive(false); isCooldown = true; examinepanl.SetActive(true); } private void Repractice3() { Destroy(retreatpreform); Instantiate(retreatyobj, retreatypanl); practicepanl.SetActive(false); ScoreManager.Instance.SubtractScore(100); } private void Repractice2() { Debug.Log("供电合同返回"); practicepanl.SetActive(false); } private void Repractice1() { Debug.Log("电费核算返回"); practicepanl.SetActive(false); Instantiate(electricchargeobj,electricchargepanl); ScoreManager.Instance.SubtractElectriccharge(100); } private void Practicesubmission3() { retreatpreform = GameObject.Find("practice1(Clone)"); Destroy(retreatpreform); //retreatpreform.SetActive(false); answerbutton.gameObject.SetActive(false); marktext.text = ScoreManager.Instance.Score.ToString(); practicepanl.SetActive(true); } private void Practicesubmission2() { Debug.Log("提交供电合同"); answerbutton.gameObject.SetActive(false); } private void Practicesubmission1() { Debug.Log("提交电费核算"); electricchargeprrform = GameObject.Find("practicepanl3(Clone)"); Destroy(electricchargeprrform); Electricitychargeaccounting.Instance.Calculatescore(); Electricitychargeaccounting.Instance.Calculatescore2(); answerbutton.gameObject.SetActive(true); marktext.text = ScoreManager.Instance.Electriccharge.ToString(); practicepanl.SetActive(true); } /// /// 覆约合同考试页面初始化 /// public void Reviewpaper() { contract.isOn = true; contract.gameObject.SetActive(true); electricitychargeaccounting.gameObject.SetActive(false); powersupplycontract.gameObject.SetActive(false); onvolumebutton.gameObject.SetActive(true); retreatypanl.gameObject.SetActive(true); powersupplypanl.gameObject.SetActive(false); electricchargepanl.gameObject.SetActive(false); Instantiate(retreatyobj, retreatypanl); } /// /// 所有练习科目页面初始化 /// public void Practicesubject() { contract.isOn = true; submitbutton.gameObject.SetActive(true); retreatypanl.gameObject.SetActive(true); powersupplypanl.gameObject.SetActive(false); electricchargepanl.gameObject.SetActive(false); Instantiate(electricchargeobj,electricchargepanl); Instantiate(retreatyobj, retreatypanl); } /// /// 供电考试页面初始化 /// public void Powersupplytestpaper() { powersupplycontract.transform.position = pos; powersupplycontract.isOn = true; contract.gameObject.SetActive(false); electricitychargeaccounting.gameObject.SetActive(false); powersupplycontract.gameObject.SetActive(true); retreatypanl.gameObject.SetActive(false); onvolumebutton.gameObject.SetActive(true); powersupplypanl.gameObject.SetActive(true); electricchargepanl.gameObject.SetActive(false); } /// /// 电费核算考试页面初始化 /// public void Electricityexaminationpaper() { electricitychargeaccounting.transform.position = pos; electricitychargeaccounting.isOn = true; contract.gameObject.SetActive(false); electricitychargeaccounting.gameObject.SetActive(true); powersupplycontract.gameObject.SetActive(false); retreatypanl.gameObject.SetActive(false); powersupplypanl.gameObject.SetActive(false); onvolumebutton.gameObject.SetActive(true); electricchargepanl.gameObject.SetActive(true); Instantiate(electricchargeobj,electricchargepanl); } void Update() { //十秒后自动退出程序 if (isCooldown) { coolingimage.fillAmount = 1 - (skilltimer / examinetimer); skilltimer += Time.deltaTime; timer -= Time.deltaTime; warntext.text = timer.ToString("0") + "秒后自动退出系统"; timetext.text = timer.ToString("0"); if (coolingimage.fillAmount == 0) { // 退出应用程序 #if UNITY_EDITOR UnityEditor.EditorApplication.isPlaying = false; #else Application.Quit(); #endif } } } }