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.

161 lines
4.5 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace Level22
{
public class Level22 : MonoBehaviour
{
public GameObject noAnswerTip;
public GameObject passOverTip;
private List<int> currentMoreChoiceList = new List<int>();
public int[] currentAnswer;
private int currentQuestionIndex = 1;
public int AllQuestionIndex = 2;
[Header("问题")]
public GameObject[] questionGroup;
public Transform[] toggleGroup;
private List<GameObject[]> toggleImgList = new List<GameObject[]>();
public bool isMoreChoice;
// Start is called before the first frame update
void Start()
{
//InitToggle(toggles1,imgs1);
//InitToggle(toggles2,imgs2);
InitToggleGroup();
}
public int GetCurrentQuesitionIndex()
{
return currentQuestionIndex;
}
private void InitToggleGroup()
{
for (int i = 0; i < toggleGroup.Length; i++)
{
int childCount = toggleGroup[i].childCount;
GameObject[] imgs=new GameObject[childCount];
for (int j = 0; j < childCount; j++)
{
Toggle toggle = null;
int index = j;
toggle= toggleGroup[i].GetChild(j).GetComponent<Toggle>();
if (toggle != null)
{
//图片记录
imgs[j] = toggle.transform.Find("selectedImg").gameObject;
toggle.onValueChanged.AddListener((bool b) =>
{
if (toggle.isOn)
{
currentMoreChoiceList.Add(index + 1);
imgs[index].SetActive(true);
}
else
{
currentMoreChoiceList.Remove(index + 1);
imgs[index].SetActive(false);
}
});
}
}
toggleImgList.Add(imgs);
}
}
// Update is called once per frame
void Update()
{
}
public void CheckQuesionIndex()
{
if (currentQuestionIndex == AllQuestionIndex)
{
//提示完成答题,然后弹窗返回大厅
passOverTip.gameObject.SetActive(true);
}
else
{
//跳转下一题
currentQuestionIndex += 1;
for (int i = 0; i < questionGroup.Length; i++)
{
questionGroup[i].SetActive(false);
}
questionGroup[currentQuestionIndex - 1].SetActive(true);
for (int i = 0; i < toggleGroup.Length; i++)
{
toggleGroup[i].gameObject.SetActive(false);
}
toggleGroup[currentQuestionIndex-1].gameObject.SetActive(true);
}
}
//记录关卡完成是否
public void CheckPassisOver(int level)
{
GameRoot.SubmitPassState(level, true);
}
public void SubAnswer(int level)
{
if (currentMoreChoiceList.Count==0
|| (currentQuestionIndex == 2 && currentMoreChoiceList.Count < 3))
{
noAnswerTip.gameObject.SetActive(true);
}
else
{
int[] answers = currentMoreChoiceList.ToArray();
if (isMoreChoice)
{
GameRoot.SubmitMoreChoiceAnswer(level, currentQuestionIndex, answers);
}
else
{
GameRoot.SubmitChoiceAnswer(level, currentQuestionIndex, answers[0]);
}
Debug.Log("提交当前小题答案为" + GameRoot.ArrToString(answers));
CheckQuesionIndex();
//当前小题答案提交后List清零
currentMoreChoiceList.Clear();
}
}
public void ReturnMenu()
{
GameRoot.ReturnMenu();
}
}
}