You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
271 lines
5.6 KiB
271 lines
5.6 KiB
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
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<string> answers = new List<string>();
|
|
|
|
public List<string> AnswerList = new List<string>();
|
|
[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<int>(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) && Input.GetKey(KeyCode.LeftControl))
|
|
{
|
|
//直接跳到最后一步输入框的步骤
|
|
CurrentQuesitionIndex = 19;
|
|
answers = new List<string>();
|
|
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<string>();
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 更新索引 以及答案和 显示问题
|
|
/// </summary>
|
|
public void UpdateQuestionIndex()
|
|
{
|
|
|
|
EventCenter.Broadcast(EventType.HideInput);
|
|
EventCenter.Broadcast(EventType.HideQuestion);
|
|
// EventCenter.Broadcast(EventType.AddAnswer); //调用加分
|
|
EventCenter.Broadcast(EventType.ClearInput);
|
|
|
|
|
|
|
|
|
|
|
|
if (CurrentQuesitionIndex == 6 || CurrentQuesitionIndex == 7 || CurrentQuesitionIndex == 19)
|
|
{
|
|
conversationInputs[CurrentQuesitionIndex - 1].GetComponent<ConversationInput>().AddAnswer();
|
|
|
|
|
|
//if (CurrentQuesitionIndex==19)
|
|
//{
|
|
|
|
// if (answers[2].Length <4)
|
|
// {
|
|
// answers.Remove(answers[2]);
|
|
// return;
|
|
// }
|
|
|
|
|
|
|
|
//}
|
|
|
|
conversationInputs[CurrentQuesitionIndex - 1].gameObject.SetActive(false);
|
|
|
|
// ConversationInput.Instance.AddAnswer();
|
|
|
|
if (CurrentQuesitionIndex == 19)
|
|
{
|
|
if (CheckAnswer())
|
|
{
|
|
succeed = true;
|
|
}
|
|
|
|
EducoderText.Instance.Open();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (CurrentQuesitionIndex < 19)
|
|
{
|
|
CurrentQuesitionIndex++;
|
|
|
|
StartTimeTask(1f, () => { EventCenter.Broadcast<int>(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 >= 2)
|
|
{
|
|
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(1, () =>
|
|
{
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
}
|