LaboratoryProtection/Assets/UnityTest/ZXL/Scripts/UI/ChoiceQuestionUI.cs

70 lines
1.9 KiB
C#
Raw Normal View History

using System;
using Mono.Event;
using TMPro;
2023-10-08 17:04:32 +08:00
using UnityEngine;
using UnityEngine.UI;
namespace UnityTest.ZXL
{
public class ChoiceQuestionUI : UI
{
public Button btnFirst;
public Button btnSecond;
2023-10-08 17:04:32 +08:00
public Image imgFirst;
public Image imgSecond;
public Sprite yes_Garden;
public Sprite no_Garden;
public Sprite yes_Text;
public Sprite no_Text;
public override void OnInit()
{
base.OnInit();
btnFirst.onClick.AddListener(ClickFirst);
btnSecond.onClick.AddListener(ClickSecond);
}
2023-10-05 02:31:29 +08:00
public void SetIndex(int index)
{
if (index == 0)
{
2023-10-08 17:04:32 +08:00
btnFirst.enabled = true;
btnSecond.enabled = false;
btnFirst.GetComponent<Animator>().enabled = true;
btnSecond.GetComponent<Animator>().enabled = false;
btnFirst.image.sprite = yes_Garden;
imgFirst.sprite = yes_Text;
btnSecond.image.sprite = no_Garden;
imgSecond.sprite = no_Text;
2023-10-05 02:31:29 +08:00
}
else if (index == 1)
{
2023-10-08 17:04:32 +08:00
btnFirst.enabled = false;
btnSecond.enabled = true;
btnFirst.GetComponent<Animator>().enabled = false;
btnSecond.GetComponent<Animator>().enabled = true;
btnFirst.image.sprite = no_Garden;
imgFirst.sprite = no_Text;
btnSecond.image.sprite = yes_Garden;
imgSecond.sprite = yes_Text;
2023-10-05 02:31:29 +08:00
}
}
private void ClickFirst()
{
EventManager.Instance.FireNow(this, new ChoiceQuestionEventArgs(true));
}
private void ClickSecond()
{
EventManager.Instance.FireNow(this, new ChoiceQuestionEventArgs(false));
}
}
}