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.

376 lines
9.9 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 DG.Tweening;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
namespace Level09
{
public class Level09Manager : MonoBehaviour
{
public GameObject noAnswerTip;
public GameObject passOverTip;
public GameObject nextQuesitionTip;
private List<int> currentMoreChoiceList = new List<int>();
public int[] currentAnswer= { 0};
private int currentQuestionIndex = 1;
public int AllQuestionIndex = 2;
public bool op = false;
[Header("问题")]
public GameObject[] questionGroup;
internal void AddAnSwer(int index)
{
if (currentMoreChoiceList.Contains(index))
{
currentMoreChoiceList.Remove(index);
}
else
{
currentMoreChoiceList.Add(index);
}
}
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);
//ReturnMenu();
}
else
{
noAnswerTip.SetActive(true);
}
}
public void CheckEndQuesition()
{
if (currentQuestionIndex == AllQuestionIndex)
{
passOverTip.gameObject.SetActive(true);
}
else
{
}
}
public void NextQuesition()
{
//跳转下一题
if (currentQuestionIndex == AllQuestionIndex)
{
ReturnMenu();
return;
}
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)
{
noAnswerTip.gameObject.SetActive(true);
int[] answers = currentMoreChoiceList.ToArray();
if (isMoreChoice)
{
GameRoot.SubmitMoreChoiceAnswer(level, currentQuestionIndex, answers);
}
else
{
GameRoot.SubmitChoiceAnswer(level, currentQuestionIndex, 0);
}
}
else
{
int[] answers = currentMoreChoiceList.ToArray();
if (isMoreChoice)
{
GameRoot.SubmitMoreChoiceAnswer(level, currentQuestionIndex, answers);
Debug.Log("提交当前多选小题答案为" + GameRoot.ArrToString(answers));
}
else
{
GameRoot.SubmitChoiceAnswer(level, currentQuestionIndex, answers[0]);
Debug.Log("提交当前单选小题答案为" + GameRoot.ArrToString(answers));
}
CheckQuesionIndex();
//当前小题答案提交后List清零
currentMoreChoiceList.Clear();
}
}
public void SubWeiBaoLevel8()
{
if (currentQuestionIndex != 2) return;
int[] answers = currentMoreChoiceList.ToArray();
if (isMoreChoice)
{
GameRoot.SubmitMoreChoiceAnswer(8, 1, answers);
Debug.Log("提交当前多选小题答案为" + GameRoot.ArrToString(answers));
}
}
public void AddMoreChoiceAnswer()
{
if (currentQuestionIndex == AllQuestionIndex)
{
//提示完成答题,然后弹窗返回大厅
passOverTip.gameObject.SetActive(true);
//ReturnMenu();
}
else
{
//noAnswerTip.SetActive(true);
nextQuesitionTip.SetActive(true);
}
if (currentMoreChoiceList.Count > 0)
{
Debug.Log("添加答案" + currentMoreChoiceList[currentMoreChoiceList.Count - 1]);
}
}
public void LoadScene(string name)
{
SceneManager.LoadScene(name);
}
public void SubOP(int level)
{
GameRoot.SubmitOprerationAnswer(level, currentQuestionIndex, new bool[] { op });
Debug.Log("提交当前操作小题答案为" + GameRoot.ArrToString(new bool[] { op }));
CheckQuesionIndex();
}
public void ReturnMenu()
{
GameRoot.ReturnMenu();
}
public void SetOP(bool b)
{
op = b;
Debug.Log("当前结果为" + b);
}
public void SetLevel8Str(Text txt)
{
if (txt.text == "手动:禁止")
{
txt.text = "手动:允许";
SetOP(true);
}
else if(txt.text == "手动:允许")
{
txt.text = "手动:禁止";
SetOP(false);
}
if (txt.text == "自动:禁止")
{
txt.text = "自动:允许";
}
else if(txt.text == "自动:允许")
{
txt.text = "自动:禁止";
}
}
private bool weibaoLevelOneSD = false;
private bool weibaoLevelOneZD = false;
public void SetWeiBaoLevel1Str(Text txt)
{
if (txt.text == "手动:禁止")
{
txt.text = "手动:允许";
weibaoLevelOneSD = true;
}
else if (txt.text == "手动:允许")
{
txt.text = "手动:禁止";
weibaoLevelOneSD = false;
}
if (txt.text == "自动:禁止")
{
txt.text = "自动:允许";
weibaoLevelOneZD = false;
}
else if (txt.text == "自动:允许")
{
txt.text = "自动:禁止";
weibaoLevelOneZD = true;
}
if (weibaoLevelOneSD && weibaoLevelOneZD)
{
SetOP(true);
}
else
{
SetOP(false);
}
}
public void SetLevel8StrBJuan(Text txt)
{
if (txt.text == "手动:禁止")
{
txt.text = "手动:允许";
SetOP(true);
}
else if (txt.text == "手动:允许")
{
txt.text = "手动:禁止";
SetOP(false);
}
if (txt.text == "自动:禁止")
{
txt.text = "自动:允许";
SetOP(false);
}
else if (txt.text == "自动:允许")
{
txt.text = "自动:禁止";
SetOP(true);
}
}
public void MoveCamera(Vector3 pos)
{
Camera.main.transform.DOMove(pos,1f);
}
public void ReloadScene()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
}
}