171 lines
8.1 KiB
C#
171 lines
8.1 KiB
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using ZXKFramework;
|
|
namespace YiLiao.SiBuChuZhen
|
|
{
|
|
public class KaoHePanel : UIBase
|
|
{
|
|
RectTransform content;
|
|
RectTransform questionAnalysisContent;
|
|
GameObject questionAnalysis;
|
|
GameObject step;
|
|
GameObject question;
|
|
GameObject question_Text;
|
|
GameObject option_Txt;
|
|
GameObject option_Img;
|
|
GameObject option_ImgTxt;
|
|
GameObject answer;
|
|
GameObject yourAnswer;
|
|
public override string GroupName => "KaoHePanel";
|
|
public override string Name => "KaoHePanel";
|
|
public override void Init(IUIManager uictrl)
|
|
{
|
|
base.Init(uictrl);
|
|
question = transform.FindFirst<Transform>("QuestionAnalysis").gameObject;
|
|
content = transform.FindFirst<RectTransform>("Content");
|
|
questionAnalysis = transform.FindFirst<Transform>("QuestionAnalysis").gameObject;
|
|
questionAnalysisContent = transform.FindFirst<RectTransform>("QuestionAnalysisContent");
|
|
|
|
step = transform.FindFirst<Transform>("Step").gameObject;
|
|
question_Text = transform.FindFirst<Transform>("question_Text").gameObject;
|
|
option_Txt = transform.FindFirst<Transform>("option_Txt").gameObject;
|
|
option_Img = transform.FindFirst<Transform>("option_Img").gameObject;
|
|
option_ImgTxt = transform.FindFirst<Transform>("option_ImgTxt").gameObject;
|
|
answer = transform.FindFirst<Transform>("answer").gameObject;
|
|
yourAnswer = transform.FindFirst<Transform>("yourAnswer").gameObject;
|
|
|
|
transform.FindFirst<Text>("Title").text = GetModel<GameModel>().GetLanguage(14);
|
|
transform.FindFirst<Text>("Text1").text = GetModel<GameModel>().GetLanguage(15);
|
|
transform.FindFirst<Text>("Text2").text = GetModel<GameModel>().GetLanguage(16);
|
|
transform.FindFirst<Text>("Text2-2").text = "ÀàÐÍ";
|
|
transform.FindFirst<Text>("Text3").text = GetModel<GameModel>().GetLanguage(17);
|
|
transform.FindFirst<Text>("Text4").text = GetModel<GameModel>().GetLanguage(18);
|
|
transform.FindFirst<Text>("Text5").text = GetModel<GameModel>().GetLanguage(19);
|
|
transform.FindFirst<Text>("Text6").text = GetModel<GameModel>().GetLanguage(19);
|
|
transform.FindFirst<Text>("Text7").text = GetModel<GameModel>().GetLanguage(20);
|
|
transform.FindFirst<Text>("Text8").text = GetModel<GameModel>().GetLanguage(21);
|
|
}
|
|
public override void Show()
|
|
{
|
|
base.Show();
|
|
question.SetActive(false);
|
|
GeneSteps(GameManager.Instance.kaoheManager.result.steps);
|
|
}
|
|
public void GeneSteps(List<Step> steps)
|
|
{
|
|
for (int i = 0; i < steps.Count; i++)
|
|
{
|
|
int seq = i + 1;
|
|
Step s = steps[i];
|
|
GameObject obj = Instantiate(step, content);
|
|
obj.SetActive(true);
|
|
Text id = obj.transform.FindFirst<Text>("ID");
|
|
Text name = obj.transform.FindFirst<Text>("Name");
|
|
Text type = obj.transform.FindFirst<Text>("Type");
|
|
Text maxScore = obj.transform.FindFirst<Text>("MaxScore");
|
|
Text score = obj.transform.FindFirst<Text>("Score");
|
|
id.text = seq.ToString();
|
|
name.text = s.name;
|
|
type.text = s.type;
|
|
maxScore.text = s.maxScore.ToString();
|
|
score.text = s.score.ToString();
|
|
List<Question> questions = s.questions;
|
|
if (questions.Count > 0)
|
|
{
|
|
Debug.Log("name=" + s.name + "questionCount=" + questions.Count);
|
|
obj.FindFirst<Button>("Btn").gameObject.SetActive(true);
|
|
obj.FindFirst<Button>("Btn").onClick.AddListener(() =>
|
|
{
|
|
questionAnalysis.SetActive(true);
|
|
ShowQuestionAnalysis(questions);
|
|
});
|
|
}
|
|
if (seq % 2 == 0)
|
|
{
|
|
obj.transform.FindFirst<Image>("bg").gameObject.SetActive(true);
|
|
}
|
|
else
|
|
{
|
|
obj.transform.FindFirst<Image>("bg").gameObject.SetActive(false);
|
|
}
|
|
}
|
|
}
|
|
void ShowQuestionAnalysis(List<Question> list)
|
|
{
|
|
int count = transform.FindFirst("QuestionAnalysisContent").transform.childCount;
|
|
Game.Instance.objectPool.Unspawn("question_Text");
|
|
Game.Instance.objectPool.Unspawn("option_Txt");
|
|
Game.Instance.objectPool.Unspawn("option_Img");
|
|
Game.Instance.objectPool.Unspawn("option_ImgTxt");
|
|
Game.Instance.objectPool.Unspawn("answer");
|
|
Game.Instance.objectPool.Unspawn("yourAnswer");
|
|
foreach (var q in list)
|
|
{
|
|
Game.Instance.objectPool.Spawn(question_Text, questionAnalysisContent, m =>
|
|
{
|
|
m.GetComponent<Text>().text = q.qText;
|
|
count = m.transform.parent.childCount;
|
|
m.transform.SetSiblingIndex(count - 1);
|
|
});
|
|
foreach (var o in q.qOptions)
|
|
{
|
|
if (string.IsNullOrEmpty(o.imgPath))
|
|
{
|
|
Game.Instance.objectPool.Spawn(option_Txt, questionAnalysisContent, m =>
|
|
{
|
|
m.transform.FindFirst<Text>("Num").text = o.num;
|
|
m.transform.FindFirst<Text>("Txt").text = o.txt;
|
|
count = m.transform.parent.childCount;
|
|
m.transform.SetSiblingIndex(count - 1);
|
|
});
|
|
}
|
|
else if (string.IsNullOrEmpty(o.txt))
|
|
{
|
|
Game.Instance.objectPool.Spawn(option_Img, questionAnalysisContent, m =>
|
|
{
|
|
m.transform.FindFirst<Text>("Num").text = o.num;
|
|
Game.Instance.res.Load<Texture2D>(MVC.GetModel<Main.GameModel>().mainData.folder + "/Textures/" + o.imgPath, t =>
|
|
{
|
|
m.transform.FindFirst<Image>("Image").sprite = UnityTools.ToSprite(t);
|
|
});
|
|
count = m.transform.parent.childCount;
|
|
m.transform.SetSiblingIndex(count - 1);
|
|
});
|
|
}
|
|
else
|
|
{
|
|
Game.Instance.objectPool.Spawn(option_ImgTxt, questionAnalysisContent, m =>
|
|
{
|
|
m.transform.FindFirst<Text>("Num").text = o.num;
|
|
Game.Instance.res.Load<Texture2D>(MVC.GetModel<Main.GameModel>().mainData.folder + "/Textures/" + o.imgPath, t =>
|
|
{
|
|
m.transform.FindFirst<Image>("Image").sprite = UnityTools.ToSprite(t);
|
|
});
|
|
m.transform.FindFirst<Text>("Txt").text = o.txt;
|
|
count = m.transform.parent.childCount;
|
|
m.transform.SetSiblingIndex(count - 1);
|
|
});
|
|
}
|
|
}
|
|
Game.Instance.objectPool.Spawn(answer, questionAnalysisContent, m =>
|
|
{
|
|
m.GetComponent<Text>().text = "ÕýÈ·´ð°¸£º" + q.qAnswer;
|
|
count = m.transform.parent.childCount;
|
|
m.transform.SetSiblingIndex(count - 1);
|
|
});
|
|
Game.Instance.objectPool.Spawn(yourAnswer, questionAnalysisContent, m =>
|
|
{
|
|
m.GetComponent<Text>().text = "ÄãµÄ´ð°¸£º" + q.qYourAnswer + "\n\n";
|
|
count = m.transform.parent.childCount;
|
|
m.transform.SetSiblingIndex(count - 1);
|
|
});
|
|
}
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
Game.Instance.objectPool.Clear();
|
|
}
|
|
}
|
|
} |