93 lines
2.3 KiB
C#
93 lines
2.3 KiB
C#
using System;
|
|
using Cysharp.Threading.Tasks;
|
|
using DragonSoul.Shared;
|
|
using Mono.Event;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace UnityTest.ZXL
|
|
{
|
|
public class ChoiceQuestionUI : UI
|
|
{
|
|
public Button btnFirst;
|
|
public Button btnSecond;
|
|
|
|
public Image imgFirstAni;
|
|
public Image imgSecondAni;
|
|
|
|
public Image imgFirst;
|
|
public Image imgSecond;
|
|
|
|
public Sprite yes_Garden;
|
|
public Sprite no_Garden;
|
|
|
|
public Sprite yes_Text;
|
|
public Sprite no_Text;
|
|
|
|
private ETTask task;
|
|
|
|
public override void OnInit()
|
|
{
|
|
base.OnInit();
|
|
btnFirst.onClick.AddListener(ClickFirst);
|
|
btnSecond.onClick.AddListener(ClickSecond);
|
|
}
|
|
|
|
public void SetIndex(int index)
|
|
{
|
|
if (index == 0)
|
|
{
|
|
btnFirst.enabled = true;
|
|
btnSecond.enabled = false;
|
|
|
|
imgFirstAni.sprite = yes_Garden;
|
|
imgFirst.sprite = yes_Text;
|
|
imgSecondAni.sprite = no_Garden;
|
|
imgSecond.sprite = no_Text;
|
|
|
|
ImageRotateAsync(imgFirstAni).Coroutine();
|
|
}
|
|
else if (index == 1)
|
|
{
|
|
btnFirst.enabled = false;
|
|
btnSecond.enabled = true;
|
|
|
|
imgFirstAni.sprite = no_Garden;
|
|
imgFirst.sprite = no_Text;
|
|
imgSecondAni.sprite = yes_Garden;
|
|
imgSecond.sprite = yes_Text;
|
|
|
|
ImageRotateAsync(imgSecondAni).Coroutine();
|
|
}
|
|
}
|
|
|
|
async ETTask ImageRotateAsync(Image image)
|
|
{
|
|
task = ETTask.Create();
|
|
|
|
while (true)
|
|
{
|
|
if (task.IsCompleted)
|
|
break;
|
|
|
|
await UniTask.Yield();
|
|
image.transform.localEulerAngles += new Vector3(0, 0, -1);
|
|
}
|
|
|
|
image.transform.localEulerAngles = Vector3.zero;
|
|
}
|
|
|
|
private void ClickFirst()
|
|
{
|
|
task.SetResult();
|
|
EventManager.Instance.FireNow(this, new ChoiceQuestionEventArgs(true));
|
|
}
|
|
|
|
private void ClickSecond()
|
|
{
|
|
task.SetResult();
|
|
EventManager.Instance.FireNow(this, new ChoiceQuestionEventArgs(false));
|
|
}
|
|
}
|
|
} |