81 lines
2.2 KiB
C#
81 lines
2.2 KiB
C#
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using Unity.VisualScripting;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
public class BetBtn : MonoBehaviour
|
||
{
|
||
public static BetBtn instance;
|
||
public int BetHorseId;//投注马匹id
|
||
public GameObject BetList;
|
||
public Button NumBtn;
|
||
public Text BetText;
|
||
public float BetValue;//投注的值
|
||
public float AllBetValue;//投注总值
|
||
|
||
public Button BetButton;//投注的按钮
|
||
public SnailKnightBet523 snailKnightBet523 = new SnailKnightBet523();
|
||
// Start is called before the first frame update
|
||
void Start()
|
||
{
|
||
instance = this;
|
||
BetList.SetActive(false);
|
||
NumBtn.onClick.AddListener(OnClickNumBtn);
|
||
BetButton.onClick.AddListener(BetOnClick);
|
||
BetValue = 50;//默认50
|
||
SetBet();
|
||
}
|
||
|
||
// Update is called once per frame
|
||
void Update()
|
||
{
|
||
|
||
}
|
||
async void BetOnClick()//点击投注
|
||
{
|
||
bool flag= await snailKnightBet523.SnailKnightBet(AllManeger.instance.id, BetValue, BetHorseId);
|
||
if (flag)
|
||
{
|
||
foreach (HorseInfo horse in AllManeger.instance.horseInfos)
|
||
{
|
||
if (BetHorseId == horse.HorseNo)
|
||
{
|
||
StartCoroutine(Tools.AnimateText(horse.BetCoins, horse.BetCoins + BetValue, 0.5f, horse.betText));
|
||
horse.BetCoins += BetValue;
|
||
}
|
||
}
|
||
AllManeger.instance.GetSelfInfo();
|
||
AllManeger.instance.Fuck522();
|
||
}
|
||
|
||
}
|
||
|
||
void OnClickNumBtn()
|
||
{
|
||
if (BetList.activeInHierarchy)
|
||
{
|
||
BetList.SetActive(false);
|
||
}
|
||
else
|
||
{
|
||
BetList.SetActive(true);
|
||
}
|
||
|
||
}
|
||
void SetBet()
|
||
{
|
||
// 获取所有的Button组件
|
||
Button[] buttons = BetList.GetComponentsInChildren<Button>();
|
||
|
||
// 遍历每一个Button,添加点击事件
|
||
foreach (Button button in buttons)
|
||
{
|
||
button.onClick.AddListener(() => {
|
||
BetText.text = button.transform.GetComponentInChildren<Text>().text;
|
||
BetValue = float.Parse(BetText.text);
|
||
BetList.SetActive(false);
|
||
});
|
||
}
|
||
}
|
||
}
|