using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using XFramework; //学员端科目一推演界面 public class Sub1LearnPanel : BasePanel { const string panelName = "Panel_studentSub1推演"; private GameObject finishPromptWindow; private Text text_Timer; private AnserWindowCtrl answerWindow; Transform image_Map; int time; public Sub1LearnPanel():base(new UIType(panelName)) { } protected override void InitEvent() { finishPromptWindow = ActivePanel.Find("Image_结束提示").gameObject; answerWindow = ActivePanel.Find("Image_答题框").GetComponent(); text_Timer = ActivePanel.Find("Text_Timer").GetComponent(); //EventCenter.Instance.AddEventListener("TuFaTrigger",); } public override void OnStart() { base.OnStart(); finishPromptWindow.gameObject.SetActive(false); answerWindow.gameObject.SetActive(false); Game.StartCoroutine(Timer()); } //int timeScale=5;//时间 按5倍快放计时 private IEnumerator Timer() { yield return new WaitForSeconds(1); time += (int)Time.timeScale; int miao = time % 60; int min = time / 60; int hour = 0; if (min > 59) { hour = min / 60; min = min % 60; } if (text_Timer != null) LocalizationManager.SetFormatted(text_Timer, "推演时间: {0}:{1}:{2}", hour, min, miao); Game.StartCoroutine(Timer()); } public override void OnDestroy(bool isDestroy = false) { base.OnDestroy(isDestroy); Game.StopCoroutine(Timer()); } //初始化推演界面 小地图 沿用编辑时的GameObject public override void Change(object newData) { base.Change(newData); image_Map = newData as Transform; image_Map.transform.SetParent(ActivePanel); RectTransform rectTransform = image_Map.GetComponent(); rectTransform.anchorMin = Vector2.zero; rectTransform.anchorMax = Vector2.zero; rectTransform.sizeDelta = new Vector2(480, 270); rectTransform.anchoredPosition = new Vector2(240, 135); image_Map.GetComponentInChildren().InitSize(); } TuFaAnswerClass tufaMsg;//当前遇到的突发事件对应的答题选项 TuFaEnum tuFa;//当前遇到的突发事件名称 /// /// 遇到突发事件 导调模式发送事件信息到教员端 /// /// /// public override void Change(string msgType, object value) { if (msgType == "TuFaTrigger") { tuFa = (TuFaEnum)value ; tufaMsg = TuFaAnswers.tufaEvents[tuFa]; List options = new List(); foreach (var item in tufaMsg.options) { options.Add(item.Key); } answerWindow.SetAskAndAnswer(tuFa.ToString(), options, AnswerEvent); if (AdjustingManager.Instance.Adjusting)//导调状态下遇到突发事件发送消息到教员端 { NetTuFaHandleMsg msg = new NetTuFaHandleMsg(); msg.msgType = TuFaMsgType.trigger; msg.msg = tuFa.ToString(); TCPManager.Instance.SendNetMsg(msg, NetMsgName.TuFaEvent); } } } // 完成答题时 检查选项是否最佳选项以及当前选项对应的罚时 并恢复车辆移动 导调模式下发送事件信息到教员端 void AnswerEvent(string selectOperations) { bool isRightOption = selectOperations == tufaMsg.rightOption; int takeTime = tufaMsg.options[selectOperations]; time -= takeTime * 60;//takeTime为负数 if (isRightOption)//正确处理方式不记录罚时 { StudentOperateRecorder.Instance.InjectOperateMsg($"行军过程中遇到{tuFa.ToString()},选择处理方式为{selectOperations}"); } else StudentOperateRecorder.Instance.InjectOperateMsg($"行军过程中遇到{tuFa.ToString()},选择处理方式为{selectOperations},罚时{takeTime}分钟"); if (AdjustingManager.Instance.Adjusting)//导调状态下遇到突发事件发送消息到教员端 { NetTuFaHandleMsg msg = new NetTuFaHandleMsg(); if (isRightOption) { msg.msgType = TuFaMsgType.handleRight; msg.msg = $"{ selectOperations}"; } else { msg.msgType = TuFaMsgType.handleWrong; msg.msg = $"{ selectOperations},罚时{takeTime}分钟"; } TCPManager.Instance.SendNetMsg(msg, NetMsgName.TuFaEvent); } if (StudentStateManager.Instance.LearnState == LearnState.learning&&!isRightOption)//训练模式回答错误时 提示正确答案 并延迟3秒后消失 { answerWindow.ShowRightResult(tufaMsg.rightOption); Game.StartCoroutine(WaitSeconds());//延迟3秒 } else { HideWindowAndMove();//直接调用 不延迟 } } //等待时间 IEnumerator WaitSeconds() { yield return new WaitForSeconds(3f); HideWindowAndMove(); } void HideWindowAndMove() { GameObjectManager.Instance.StartAIMove();//回答完成后 车队继续移动 answerWindow.Hide(); } }