killapp/Assets/Scripts/UI/Pages/Safetylearning/SafetylearningAnswer.cs

60 lines
1.8 KiB
C#
Raw Normal View History

2026-04-24 16:57:44 +08:00
using System;
using System.Collections;
using System.Collections.Generic;
using Kill.Managers;
using Kill.UI.Components;
using UnityEngine;
using UnityEngine.UI;
public class SafetylearningAnswer : MonoBehaviour
{
public Text correctAnswerText;
public GameObject answerPrefab;
public VideoCtrl video;
public void Init(List<QuestionOption> options,string videoUrl)
{
bool isChinese = LanguageManager.Instance.languageType == LanguageManager.LanguageType.Chinese;
answerPrefab.SetActive(false);
string correctAnswer="";
2026-05-18 08:42:33 +08:00
2026-04-24 16:57:44 +08:00
for(int i = 0; i <options.Count; i++) {
string explanation=isChinese?options[i].explanation:options[i].explanationEn;
if(options[i].isCorrect==true)
{
if(correctAnswer!="")
correctAnswer+=" ";
correctAnswer+=options[i].optionLabel;
}
if(!string.IsNullOrEmpty(explanation))
{
var a=Instantiate(answerPrefab,answerPrefab.transform.parent);
a.GetComponent<Text>().text=$"{options[i].optionLabel}: {explanation}";
a.SetActive(true);
a.transform.SetAsLastSibling();
}
}
2026-05-18 08:42:33 +08:00
correctAnswerText.text=LanguageManager.Instance.GetLanguage("100055").Replace("{0}",correctAnswer);
Debug.Log(correctAnswer);
2026-04-24 16:57:44 +08:00
if(videoUrl!="")
{
video.gameObject.SetActive(true);
video.transform.SetAsLastSibling();
video.SetVideo(videoUrl);
2026-05-18 08:42:33 +08:00
video.gameObject.transform.parent.SetAsLastSibling();
2026-04-24 16:57:44 +08:00
}
else
{
video.gameObject.SetActive(false);
}
2026-05-18 08:42:33 +08:00
2026-04-24 16:57:44 +08:00
}
void LateSetCorrectAnswerText(string correctAnswer)
{
correctAnswerText.text.Replace("{0}",correctAnswer);
}
}