using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class MenuWnd : MonoBehaviour { [Header("Btn")] public Button accidentBtn; public Button returnBtn; public Button checkBtn; public Button analyseBtn; public Button analyseSuiDaoBtn; [Header("其他控件")] public GameObject peopleCheckWnd; public GameObject analyseWnd; public GameObject checkWorkerPanle; public Transform peopleCheckGroup; public Transform suidaoCheckGroup; public GameObject suidaoAnalyseWnd; public GameObject suidaoCheckWnd; public GameObject suidaoResultWnd; public GameObject suidaoEndWnd; public Text checkResultTxt; public Text AccidentTip; public Text suidaoCheckTip; public Text errorTip; public Animator blackAni; public Transform accidentCamere; public GameObject car; [Header("可拖动图片相关")] public Transform DargImgParent; public Transform DargCheckParent; private DargCheck[] _dargChecks; private UiListenter[] _uiListenters; [HideInInspector] public RectTransform currentDarg = null; [Header("场景物件")] public GameObject tanTaObj; //事故发生的员工记录 private int accidentWorkerId = -1; public void Init() { // accidentBtn.onClick.AddListener(() => { AISys.Instance.Accident(GameRoot.Instance._passIndex);}); RigisterListenter(); RigisterDargChecker(); checkBtn.onClick.AddListener(CheckAnswer); analyseBtn.onClick.AddListener(() => { analyseWnd.SetActive(true); StartCoroutine(Const.TimedTask(6,()=> { analyseWnd.SetActive(false); checkWorkerPanle.SetActive(true); AISys.Instance.ShowFangKuang(accidentWorkerId, false); })); }); } public void CheckPeople(int index) { peopleCheckWnd.SetActive(true); StartCoroutine(IE_CheckPeople(index)); } public void CheckSuiDao(int index) { //隧道窗口开启 suidaoCheckWnd.SetActive(true); //隧道监测开启 StartCoroutine(IE_CheckSuidao(index)); } /// /// 关卡1监测人员 /// /// 出事故的人员索引 /// IEnumerator IE_CheckPeople(int index) { for (int i = 0; i < peopleCheckGroup.childCount; i++) { yield return new WaitForSeconds(Random.Range(2, 4)); if (i == index) { yield return new WaitForSeconds(6f); peopleCheckGroup.GetChild(i).GetComponent().color = Color.red; accidentWorkerId = i; // AISys.Instance.ShowFangKuang(i,false); continue; } peopleCheckGroup.GetChild(i).GetComponent().color = Color.green; AISys.Instance.ShowFangKuang(i,true); } checkResultTxt.text = (index + 1) + "号员工长时间未响应是否调取相应监控并智能分析结果?"; checkResultTxt.gameObject.SetActive(true); } /// /// 事故1处理 /// public void Accident1Progss() { blackAni.CrossFade("Black", 0f); accidentCamere.localPosition = new Vector3(-7.43f, 12.3f, 18.6f); accidentCamere.localEulerAngles = new Vector3(40f, -6f, 0f); StartCoroutine( Const.TimedTask(1.5f, () => { AccidentTip.gameObject.SetActive(true); returnBtn.gameObject.SetActive(true); car.SetActive(true); EduCoderTool.WebConnecter.Singleton.SendResultToWeb(true); // car.GetComponent().CrossFade("Go", 0); })); } /// /// pass2检查隧道压力 /// /// 异常隧道索引 /// IEnumerator IE_CheckSuidao(int index) { for (int i = 0; i < suidaoCheckGroup.childCount; i++) { float value = Random.Range(0.5f, 1); yield return new WaitForSeconds(Random.Range(2, 4)); if (i == index) { suidaoCheckGroup.GetChild(i).GetComponent().color = Color.red; suidaoCheckGroup.GetChild(i).GetComponent().text = "2.5Mpa"; continue; } suidaoCheckGroup.GetChild(i).GetComponent().color = Color.green; suidaoCheckGroup.GetChild(i).GetComponent().text = value.ToString("0.0")+"Mpa"; } suidaoCheckTip.text = "A-" + (index+1) + "段隧道监测到数据异常是否察看分析结果?"; analyseSuiDaoBtn.gameObject.SetActive(true); analyseSuiDaoBtn.onClick.AddListener(() => { StartCoroutine(Const.TimedTask(5f, () => { suidaoResultWnd.SetActive(true); //suidaoCheckWnd.SetActive(false); suidaoAnalyseWnd.SetActive(false); })); }); } private void RigisterListenter() { if (DargImgParent == null) return; _uiListenters = new UiListenter[DargImgParent.childCount]; for (int i = 0; i < DargImgParent.childCount; i++) { UiListenter listenter; listenter = DargImgParent.GetChild(i).GetComponent(); listenter._onClickDown = (p) => { AccidentClickAction(listenter); }; listenter._onClickUp = (p) => { AccidentClickUpAction(); }; listenter._onDarg = (p) => { AccidentDargAction(); }; _uiListenters[i] = listenter; } } private void RigisterDargChecker() { if (DargCheckParent == null) return; _dargChecks = new DargCheck[DargCheckParent.childCount]; for (int i = 0; i < DargCheckParent.childCount; i++) { DargCheckParent.GetChild(i).GetComponent().uiListenters = _uiListenters; _dargChecks[i] = DargCheckParent.GetChild(i).GetComponent(); } } private void AccidentDargAction() { //currentDarg.position = Input.mousePosition; float x = Input.mousePosition.x; float y = Input.mousePosition.y; //x = Mathf.Clamp(x, 525, 1385); //y = Mathf.Clamp(y, 147, 362); currentDarg.position = new Vector3(x, y, 0); Debug.Log(x+"-"+y); Debug.Log(currentDarg.position); } private void AccidentClickAction(UiListenter listenter) { Debug.Log("点击" + listenter.ID); currentDarg = listenter.GetComponent(); } private void AccidentClickUpAction() { currentDarg = null; for (int i = 0; i < DargCheckParent.childCount; i++) { DargCheckParent.GetChild(i).GetComponent().openCheck = true; } } public void CheckAnswer() { int index = 0; for (int i = 0; i < _dargChecks.Length; i++) { if (_dargChecks[i].CheckAnswer()) { index++; } } Debug.Log(index+"-"+ (_dargChecks.Length )); if (index != _dargChecks.Length) { errorTip.gameObject.SetActive(true); return; } //事故成功后处理事件 errorTip.gameObject.SetActive(false); checkBtn.gameObject.SetActive(false); returnBtn.gameObject.SetActive(true); AccidentTip.text = "成功救护,已将昏迷人员护安全送至救护中心"; AccidentTip.gameObject.SetActive(false); Accident1Progss(); } /// /// pass2 答案检查 /// public void Pass2CheckAnswer() { int index = 0; for (int i = 0; i < _dargChecks.Length; i++) { if (_dargChecks[i].CheckAnswer()) { index++; } } Debug.Log(index + "-" + (_dargChecks.Length)); if (index != _dargChecks.Length) { errorTip.gameObject.SetActive(true); return; } //事故成功后处理事件 errorTip.gameObject.SetActive(false); checkBtn.gameObject.SetActive(false); returnBtn.gameObject.SetActive(true); //AccidentTip.text = "成功救护,已将昏迷人员护安全送至救护中心"; //AccidentTip.gameObject.SetActive(false); //Accident1Progss(); suidaoResultWnd.SetActive(false); suidaoEndWnd.SetActive(true); tanTaObj.SetActive(false); AISys.Instance.ResetWorker(); EduCoderTool.WebConnecter.Singleton.SendResultToWeb(true); } }