_TheStrongestSnail/TheStrongestSnail/Assets/Scripts/RacingPanel/RacingSuccessPanel.cs
2024-12-04 17:12:02 +08:00

125 lines
4.0 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class RacingSuccessPanel : BasePanel
{
public Button ReturnBtn;
public static RacingSuccessPanel instance;
public TextMeshProUGUI textSnailEggs;//蜗牛蛋文本
public List<Image> images=new List<Image>();//显示蜗牛图片
public List<Sprite> sprites = new List<Sprite>();//图片精灵
public List<RuntimeAnimatorController> animators = new List<RuntimeAnimatorController>();//图片动画
public override void Start()
{
instance = this;
base.Start();
ReturnBtn.onClick.AddListener(OnClickReBtn);
}
public void OnClickReBtn()
{
HidePanel();
}
public void ShowImage()//设置结算展示图片
{
if (AllManeger.instance.WinNos.Count==4)
{
int index = 0;
for (int i = 1; i < images.Count; i++)
{
SetImage(AllManeger.instance.WinNos[index], images[i]);
if (index < AllManeger.instance.WinNos.Count - 1)
{
index++;
}
}
images[0].gameObject.SetActive(false);
images[1].gameObject.SetActive(true);
images[2].gameObject.SetActive(true);
images[3].gameObject.SetActive(true);
images[4].gameObject.SetActive(true);
}
else if (AllManeger.instance.WinNos.Count == 2)
{
int index = 0;
for (int i=1;i<images.Count;i++)
{
SetImage(AllManeger.instance.WinNos[index], images[i]);
if (index < AllManeger.instance.WinNos.Count - 1)
{
index++;
}
}
images[0].gameObject.SetActive(false);
images[1].gameObject.SetActive(true);
images[2].gameObject.SetActive(true);
images[3].gameObject.SetActive(false);
images[4].gameObject.SetActive(false);
}
else if (AllManeger.instance.WinNos.Count == 1)
{
SetImage(AllManeger.instance.WinNos[0], images[0]);
images[0].gameObject.SetActive(true);
images[1].gameObject.SetActive(false);
images[2].gameObject.SetActive(false);
images[3].gameObject.SetActive(false);
images[4].gameObject.SetActive(false);
}
}
public void SetImage(int horseId,Image image)
{
switch (horseId)
{
case 1:
image.sprite = sprites[0];
image.gameObject.GetComponent<Animator>().runtimeAnimatorController = animators[0];
break;
case 2:
image.sprite = sprites[1];
image.gameObject.GetComponent<Animator>().runtimeAnimatorController = animators[1];
break;
case 3:
image.sprite = sprites[2];
image.gameObject.GetComponent<Animator>().runtimeAnimatorController = animators[2];
break;
case 4:
image.sprite = sprites[3];
image.gameObject.GetComponent<Animator>().runtimeAnimatorController = animators[3];
break;
case 5:
image.sprite = sprites[4];
image.gameObject.GetComponent<Animator>().runtimeAnimatorController = animators[4];
break;
case 6:
image.sprite = sprites[5];
image.gameObject.GetComponent<Animator>().runtimeAnimatorController = animators[5];
break;
case 7:
image.sprite = sprites[6];
image.gameObject.GetComponent<Animator>().runtimeAnimatorController = animators[6];
break;
case 8:
image.sprite = sprites[7];
image.gameObject.GetComponent<Animator>().runtimeAnimatorController = animators[7];
break;
}
}
}