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.
192 lines
5.2 KiB
192 lines
5.2 KiB
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using HJDFrameWork;
|
|
|
|
|
|
namespace Level05
|
|
{
|
|
public class AnswerSys : MonoBehaviour
|
|
{
|
|
public static AnswerSys Instance = null;
|
|
|
|
[Header("答案集合")]
|
|
public int[] keys = { 3, 2 };
|
|
[Header("当前选择答案")]
|
|
public int currentKey;
|
|
[Header("当前题目轮数")]
|
|
public int QuestionIndex = 1;
|
|
[Header("答案记录")]
|
|
public int[] selctedKeys;
|
|
[Header("问题组")]
|
|
public Transform questionParent;
|
|
private GameObject[] questionGroup;
|
|
[Header("答案组")]
|
|
public Transform keyParent;
|
|
private GameObject[] keyGroup;
|
|
[Header("物件")]
|
|
public GameObject noAnswerTip;
|
|
public GameObject overTip;
|
|
|
|
|
|
|
|
public bool[] operationAnswers;
|
|
|
|
public void Init()
|
|
{
|
|
Instance = this;
|
|
selctedKeys = new int[keys.Length + 1];
|
|
GroupCheck();
|
|
|
|
}
|
|
|
|
void GroupCheck()
|
|
{
|
|
questionGroup = new GameObject[questionParent.childCount];
|
|
keyGroup = new GameObject[keyParent.childCount];
|
|
for (int i = 0; i < questionParent.childCount; i++)
|
|
{
|
|
questionGroup[i] = questionParent.GetChild(i).gameObject;
|
|
}
|
|
for (int i = 0; i < keyParent.childCount; i++)
|
|
{
|
|
keyGroup[i] = keyParent.GetChild(i).gameObject;
|
|
}
|
|
|
|
GroupActiveUpdate(QuestionIndex, questionGroup);
|
|
GroupActiveUpdate(QuestionIndex, keyGroup);
|
|
}
|
|
|
|
void GroupActiveUpdate(int index, GameObject[] group)
|
|
{
|
|
for (int i = 0; i < group.Length; i++)
|
|
{
|
|
group[i].SetActive(false);
|
|
}
|
|
|
|
if (group[index - 1] != null)
|
|
{
|
|
group[index - 1].SetActive(true);
|
|
|
|
}
|
|
}
|
|
|
|
public void SetCurrentKey(int key)
|
|
{
|
|
currentKey = key;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 提交答案
|
|
/// </summary>
|
|
public void SubmitAnswer()
|
|
{
|
|
//先检测是否选项为空
|
|
if (CheckAnswerIsNull()) return;
|
|
//检测是否是操作题
|
|
if (QuestionIndex == 2) {
|
|
UpdateQuestion();
|
|
return;
|
|
}
|
|
|
|
selctedKeys[QuestionIndex] = currentKey;
|
|
GameRoot.SubmitChoiceAnswer(5, QuestionIndex, selctedKeys[QuestionIndex]);
|
|
Debug.Log("记录第" + QuestionIndex + "关答案为" + currentKey);
|
|
//重置当前选择
|
|
currentKey = 0;
|
|
|
|
UpdateQuestion();
|
|
|
|
}
|
|
|
|
public bool CheckAnswerIsNull()
|
|
{
|
|
if (currentKey == 0)
|
|
{
|
|
//空答案提示
|
|
// ItemManager.Instance.GetItem("emptyAnswerTip").gameObject.SetActive(true);
|
|
noAnswerTip.gameObject.SetActive(true);
|
|
|
|
return true;
|
|
|
|
}
|
|
return false;
|
|
|
|
}
|
|
/// <summary>
|
|
/// 更新新问题的显示
|
|
/// </summary>
|
|
public void UpdateQuestion()
|
|
{
|
|
|
|
|
|
|
|
//执行环节完成处理
|
|
ProcessPassAction(QuestionIndex);
|
|
//本关结束
|
|
if (QuestionIndex >= questionGroup.Length)
|
|
{
|
|
Debug.Log("本关结束");
|
|
//完成提示
|
|
//ItemManager.Instance.GetItem("OverTip").gameObject.SetActive(true);
|
|
overTip.gameObject.SetActive(true);
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
QuestionIndex += 1;
|
|
QuestionIndex = Mathf.Clamp(QuestionIndex, 0, questionGroup.Length);
|
|
Debug.Log(QuestionIndex);
|
|
|
|
//更新环节的标识
|
|
ViewManager.Instance.GetViewWnd<QuestionWnd>().UpdateQuestionIndex(QuestionIndex);
|
|
//显示新的环节
|
|
GroupActiveUpdate(QuestionIndex, questionGroup);
|
|
GroupActiveUpdate(QuestionIndex, keyGroup);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
public void UpdateQuesitonIndex()
|
|
{
|
|
QuestionIndex += 1;
|
|
}
|
|
|
|
public void ProcessPassAction(int passIndex)
|
|
{
|
|
switch (passIndex)
|
|
{
|
|
case 1:
|
|
ViewManager.Instance.GetViewWnd<QuestionWnd>().ResetXFDoor();
|
|
ItemManager.Instance.GetItem("GuanZi").gameObject.SetActive(true);
|
|
break;
|
|
}
|
|
}
|
|
|
|
public void SubmitOperation(string str)
|
|
{
|
|
string[] arr = str.Split('-');
|
|
int inedx = int.Parse(arr[0]);
|
|
bool b;
|
|
if (arr[1] == "T")
|
|
{
|
|
b = true;
|
|
operationAnswers[inedx] = b;
|
|
}
|
|
else
|
|
{
|
|
b = false;
|
|
operationAnswers[inedx] = b;
|
|
}
|
|
|
|
GameRoot.SubmitOprerationAnswer(5, QuestionIndex, operationAnswers);
|
|
Debug.Log("记录第"+QuestionIndex+"操作题答案为"+GameRoot.ArrToString(operationAnswers));
|
|
}
|
|
|
|
}
|
|
}
|
|
|