CultivationOfBrewing/Assets/Scripts/UI/UIPanel/UI_ExamPanel.cs

96 lines
2.5 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class UI_ExamPanel : BasePanel
{
public string jsonFileName = "题目"; // JSON文件名
Root Root = new Root();
public RectTransform Rigcontent;
public ToggleGroup ToggleGroup;
public UI_Topicitem UI_Topicitem;
protected override void Awake()
{
int index = 0; // 用于跟踪当前是第几个Toggle
Root = JsonManager.LoadData<Root>(jsonFileName);
foreach (var tmxh in Root.choose)
{
var item = Instantiate(UI_Topicitem, Rigcontent);
item.Init(tmxh.topiceNumber);
var ToogleText = item.GetControl<Text>("Label");
Toggle toggle = item.GetControl<Toggle>("Toggle");
// 如果是第一个Toggle设置为选中状态
Debug.Log(toggle.name);
if (index == 0)
{
toggle.isOn = true;
}
index++; // 更新索引
}
// 确保 ToggleGroup 状态正确
ToggleGroup.allowSwitchOff = false;
ToggleGroup.SetAllTogglesOff();
//if (Rigcontent.childCount > 0)
//{
// Rigcontent.GetChild(0).GetComponent<Toggle>().isOn = true;
//}
//StartCoroutine(SetFirstToggleNextFrame());
base.Awake();
}
public override void ShowMe()
{
base.ShowMe();
}
public override void HideMe()
{
base.HideMe();
}
protected override void OnClick(string btnName)
{
Debug.Log(btnName);
switch (btnName)
{
case "retrun_Btn":
Bootstrap.Instance.scenesManager.LoadSceneAsyn(this, "MenuScene", () =>
{
Bootstrap.Instance.uiManager.ShowPanel<UI_SelectModePanel>(this, E_UI_Layer.Top, (panel) =>
{
Bootstrap.Instance.uiManager.ShowPanel<UI_BGPanel>(this, E_UI_Layer.Bot, (panel) =>
{
Debug.Log("UI_ExamPanel显示");
Bootstrap.Instance.uiManager.HidePanel<UI_ExamPanel>();
Bootstrap.Instance.uiManager.HidePanel<UI_MainTitlePanel>();
});
});
});
break;
}
}
//IEnumerator SetFirstToggleNextFrame()
//{
// yield return null; // 等待一帧
// if (Rigcontent.childCount > 0)
// {
// Rigcontent.GetChild(0).GetComponent<Toggle>().isOn = true;
// }
//}
}