61 lines
2.0 KiB
C#
61 lines
2.0 KiB
C#
|
|
using System.Collections;
|
||
|
|
using System.Collections.Generic;
|
||
|
|
using Kill.Managers;
|
||
|
|
using UnityEngine;
|
||
|
|
using UnityEngine.UI;
|
||
|
|
|
||
|
|
public class SafetylearningOption : MonoBehaviour
|
||
|
|
{
|
||
|
|
/// <summary>
|
||
|
|
/// 0未选择 1选中 2正确 3错误
|
||
|
|
/// </summary>
|
||
|
|
public Sprite[] optionBg;
|
||
|
|
/// <summary>
|
||
|
|
/// 0正确 1错误
|
||
|
|
/// </summary>
|
||
|
|
public Sprite[] optionLabelIcon;
|
||
|
|
/// <summary>
|
||
|
|
/// 0正常 1正确 2错误
|
||
|
|
/// </summary>
|
||
|
|
public Color[] optionTextColor;
|
||
|
|
public Text optionLabelText;
|
||
|
|
public Text optionContentText;
|
||
|
|
public bool isChinese=false;
|
||
|
|
public Image icon;
|
||
|
|
public Image bg;
|
||
|
|
public bool isSelected=false;
|
||
|
|
|
||
|
|
public void Init(QuestionOption option,bool isChinese)
|
||
|
|
{
|
||
|
|
this.isChinese=isChinese;
|
||
|
|
icon.gameObject.SetActive(false);
|
||
|
|
optionLabelText.gameObject.SetActive(true);
|
||
|
|
optionContentText.gameObject.SetActive(true);
|
||
|
|
optionContentText.color=optionTextColor[0];
|
||
|
|
bg.sprite=optionBg[0];
|
||
|
|
optionLabelText.text=option.optionLabel;
|
||
|
|
optionContentText.text=isChinese?option.optionContent:option.optionContentEn;
|
||
|
|
StartCoroutine(FitSize());
|
||
|
|
}
|
||
|
|
public void SetSelected(bool isSelected)
|
||
|
|
{
|
||
|
|
this.isSelected=isSelected;
|
||
|
|
bg.sprite=isSelected?optionBg[1]:optionBg[0];
|
||
|
|
}
|
||
|
|
public void SetCorrect(bool isCorrect)
|
||
|
|
{
|
||
|
|
icon.gameObject.SetActive(true);
|
||
|
|
optionLabelText.gameObject.SetActive(false);
|
||
|
|
optionContentText.gameObject.SetActive(true);
|
||
|
|
optionContentText.color=isCorrect?optionTextColor[1]:optionTextColor[2];
|
||
|
|
icon.sprite=isCorrect?optionLabelIcon[0]:optionLabelIcon[1];
|
||
|
|
bg.sprite=isCorrect?optionBg[2]:optionBg[3];
|
||
|
|
GetComponent<Button>().interactable=false;
|
||
|
|
}
|
||
|
|
IEnumerator FitSize()
|
||
|
|
{
|
||
|
|
yield return new WaitForFixedUpdate();
|
||
|
|
GetComponent<RectTransform>().sizeDelta=new Vector2(GetComponent<RectTransform>().sizeDelta.x,optionContentText.GetComponent<RectTransform>().sizeDelta.y+54);
|
||
|
|
}
|
||
|
|
}
|