WaiXie_QuestionSystem/Assets/Script/UI/Panel/ScrollPanel.cs

79 lines
2.0 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using UnityEngine.UI;
using ZXL.Excel;
namespace Script.UI
{
public class ScrollPanel : PanelBase
{
[SerializeField] private Text txt_ID;
[SerializeField] private Text txt_Subject;
[SerializeField] private Text txt_Content;
[SerializeField] private Button btn_StopGun;
private StringBuilder sb = new StringBuilder();
public override void Init()
{
base.Init();
btn_StopGun.onClick.AddListener(ClickStopGun);
// isFirst = true;
}
public override void Dispose()
{
base.Dispose();
btn_StopGun.onClick.RemoveListener(ClickStopGun);
}
public override void Open()
{
base.Open();
}
// public bool isFirst;
public override void ResetPanelData()
{
base.ResetPanelData();
UpdateText();
txt_ID.text = GlobalManager.Instance.CurrentInfo.id;
txt_Subject.text = GlobalManager.Instance.CurrentInfo.subject;
}
private void UpdateText()
{
List<SingleChoice_QuestionBank_A_DataInfo> infos = new List<SingleChoice_QuestionBank_A_DataInfo>();
for (int i = 0; i < 50; i++)
{
var info = ExcelManager.Instance.GetRandomA();
if (info == null)
{
UIManager.Instance.OpenPanel(PanelType.Error);
return;
}
infos.Add(info);
sb.AppendLine(info.topic);
foreach (var infoOption in info.options)
{
sb.AppendLine(infoOption);
}
sb.AppendLine("");
}
txt_Content.text = sb.ToString();
}
private void ClickStopGun()
{
UIManager.Instance.OpenPanel(PanelType.Answering);
Close();
}
}
}