using System; using System.Collections; using System.Collections.Generic; using System.Text; using UnityEngine; using UnityEngine.SceneManagement; using UnityEngine.UI; using static System.Net.Mime.MediaTypeNames; public class GameManager : MonoBehaviour { public static GameManager Instance = null; public int CurrentQuesitionIndex = 1; public List answers = new List(); public List AnswerList = new List(); [Header("按钮")] public Button StartBtn; public Button NextQuesitonBtn; [Header("窗口")] public GameObject OverWnd; public GameObject FailWnd; public Conversation[] conversations; public ConversationInput[] conversationInputs; public GameObject obj1, obj2; public bool boolTwo; public bool succeed; // 如果前面符合通过 则为True private void Awake() { Instance = this; } private void Start() { EventCenter.ResetEventTable(); InitConversation(); StartBtn.onClick.AddListener(() => { EventCenter.Broadcast(EventType.ShowQuestion, CurrentQuesitionIndex); }); NextQuesitonBtn.onClick.AddListener(UpdateQuestionIndex); } public void InitConversation() { for (int i = 0; i < conversations.Length; i++) { conversations[i].Init(); Debug.Log("加载对话" + i); } } IEnumerator LoadLeaver(int sceneindex, Action action) { AsyncOperation operation = SceneManager.LoadSceneAsync(sceneindex); while (operation.isDone) { if (action != null) action.Invoke(); yield return null; } } private void Update() { //if (Input.GetKeyDown(KeyCode.B)) //{ // //直接跳到最后一步输入框的步骤 // CurrentQuesitionIndex = 17; // answers = new List(); // answers.Add("1"); // answers.Add("2"); //} //if (Input.GetKeyDown(KeyCode.Q) && Input.GetKey(KeyCode.LeftControl)) //{ // StartCoroutine(LoadLeaver(1, () => // { // })); // //Application.LoadLevel(Application.loadedLevel); //} //if(Input.GetKeyDown(KeyCode.A) && Input.GetKey(KeyCode.LeftControl)) //{ // CurrentQuesitionIndex = 6; // answers = new List(); //} } /// /// 更新索引 以及答案和 显示问题 /// public void UpdateQuestionIndex() { EventCenter.Broadcast(EventType.HideInput); EventCenter.Broadcast(EventType.HideQuestion); // EventCenter.Broadcast(EventType.AddAnswer); //调用加分 EventCenter.Broadcast(EventType.ClearInput); if (CurrentQuesitionIndex == 5 || CurrentQuesitionIndex == 9) { conversationInputs[CurrentQuesitionIndex].GetComponent().AddAnswer(); //if (CurrentQuesitionIndex==19) //{ // if (answers[2].Length <4) // { // answers.Remove(answers[2]); // return; // } //} conversationInputs[CurrentQuesitionIndex].gameObject.SetActive(false); // ConversationInput.Instance.AddAnswer(); } if (CurrentQuesitionIndex == 16) { if (CheckAnswer()) { print("yes"); OverWnd.SetActive(true); EduCoderTool.WebConnecter.Singleton.SendResultToWeb(true); } else { print("no"); FailWnd.SetActive(true); } print("19"); } if (CurrentQuesitionIndex < 17) { CurrentQuesitionIndex++; StartTimeTask(1f, () => { EventCenter.Broadcast(EventType.ShowQuestion, CurrentQuesitionIndex); }); } //else //{ // //核算正确与否 // if (CheckAnswer()) // { // // OverWnd.SetActive(true); // // EduCoderTool.WebConnecter.Singleton.SendResultToWeb(true); // succeed = true; // } // else // { // // FailWnd.SetActive(true); // } //} } private bool CheckAnswer() { int OKNum = 0; for (int i = 0; i < answers.Count; i++) { int index = i + 1; int OKindex = 0; string[] strArr = AnswerList[i].Split('-'); for (int j = 0; j < strArr.Length; j++) { if (answers[i].Contains(strArr[j])) { OKindex++; } } if (OKindex >= 1) { OKNum++; } } Debug.Log(OKNum); //提示正确或错误窗口 if (OKNum >= 1) { return true; } else { return false; } } public void AddAnswer(string str) { answers.Add(str); } public void StartTimeTask(float time, Action action) { StartCoroutine(TimeTask(time, action)); } IEnumerator TimeTask(float time, Action action) { yield return new WaitForSeconds(time); action(); } public void ResetScene() { //SceneManager.LoadScene("office_Two"); // SceneManager.LoadScene("startOne"); StartCoroutine(LoadLeaver(0, () => { })); } }