_TheStrongestSnail/TheStrongestSnail/Assets/Scripts/Battle_Royale/BettingBtn.cs

161 lines
5.3 KiB
C#
Raw Normal View History

2024-11-12 14:06:34 +08:00
using System.Collections;
using System.Collections.Generic;
2024-11-15 23:31:54 +08:00
using System.Threading.Tasks;
2024-11-18 16:53:39 +08:00
using TMPro;
2024-11-15 23:31:54 +08:00
using Unity.VisualScripting.Antlr3.Runtime;
2024-11-12 14:06:34 +08:00
using UnityEngine;
using UnityEngine.UI;
2024-11-15 23:31:54 +08:00
using static BettingBtn;
using static UnityEditor.PlayerSettings;
2024-11-12 14:06:34 +08:00
public class BettingBtn : MonoBehaviour
{
2024-11-13 21:45:48 +08:00
public static BettingBtn instance;
2024-11-12 14:06:34 +08:00
public GameObject BetList;
public Button NumBtn;
public Text BetText;
public float BetValue;//Ͷע<CDB6><D7A2>ֵ
2024-11-13 21:45:48 +08:00
public float AllBetValue;//Ͷע<CDB6><D7A2>ֵ
2024-11-13 18:01:18 +08:00
public Button BetButton;//Ͷע<CDB6>İ<EFBFBD>ť
public GameObject text1;
public GameObject text2;
public GameObject text3;
public GameObject text4;
public GameObject text5;
public GameObject text6;
2024-11-13 21:45:48 +08:00
public List<GameObject> list=new List<GameObject>();
2024-11-18 16:53:39 +08:00
public TextMeshProUGUI SelfWoniuText;
2024-11-12 14:06:34 +08:00
// Start is called before the first frame update
void Start()
{
2024-11-13 21:45:48 +08:00
instance = this;
2024-11-12 14:06:34 +08:00
BetList.SetActive(false);
NumBtn.onClick.AddListener(OnClickNumBtn);
BetValue = 50;//Ĭ<><C4AC>50
SetBet();
}
void OnClickNumBtn()
{
BetList.SetActive(true);
}
2024-11-15 23:31:54 +08:00
[System.Serializable]
public class RequestData
{
public int userId;
public int escapeId;
public float bet;
public int roomNo;
}
public GameObject bg;
public async void OnClickBetBtnAsync()
2024-11-13 18:01:18 +08:00
{
2024-11-18 17:02:12 +08:00
PlayerInfo.instance.HaveBet = true;
2024-11-15 23:31:54 +08:00
RequestData body = new RequestData();
body.escapeId = bg.GetComponentInChildren<AllHouseContro>().escapeId;
body.bet = BetValue;
body.roomNo = bg.GetComponentInChildren<AllHouseContro>().roomNo;
body.userId = Global.global.serverResponse.data.userId;
2024-11-18 16:53:39 +08:00
bg.GetComponentInChildren<AllHouseContro>().house.text.GetComponent<TextBox>().AddText(BetValue);
PlayerInfo.instance.AllBetCoins += BetValue;
StartCoroutine(Tools.AnimateTextMashPro(PlayerInfo.instance.AllBetCoins, PlayerInfo.instance.AllBetCoins + BetValue, 0.5f, SelfWoniuText));//<2F>޸<EFBFBD><DEB8><EFBFBD>ţͷ<C5A3><CDB7><EFBFBD>ı<EFBFBD>
2024-11-15 23:31:54 +08:00
string response = await web.SendRequest(web.URL + "/snail/gameEscape/userBet", "POST", JsonUtility.ToJson(body), Global.global.CreateHeaders());
Debug.Log("<22>û<EFBFBD><C3BB><EFBFBD>ע<EFBFBD><D7A2>Ӧ: " + response);
bg.GetComponentInChildren<AllHouseContro>().battleRoyaleGameDetails();
2024-11-13 18:01:18 +08:00
}
2024-11-15 23:31:54 +08:00
2024-11-13 18:01:18 +08:00
void SetBet()
2024-11-12 14:06:34 +08:00
{
// <20><>ȡ<EFBFBD><C8A1><EFBFBD>е<EFBFBD>Button<6F><6E><EFBFBD><EFBFBD>
Button[] buttons = BetList.GetComponentsInChildren<Button>();
// <20><><EFBFBD><EFBFBD>ÿһ<C3BF><D2BB>Button<6F><6E><EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD><D3B5><EFBFBD><EFBFBD>¼<EFBFBD>
foreach (Button button in buttons)
{
button.onClick.AddListener(() => {
BetText.text = button.transform.GetComponentInChildren<Text>().text;
BetValue = float.Parse(BetText.text);
BetList.SetActive(false);
});
}
}
2024-11-16 02:05:07 +08:00
public void GiveMoney(string room_id)
2024-11-13 21:45:48 +08:00
{
float AllMoney = text1.GetComponent<TextBox>().ReturnText() + text2.GetComponent<TextBox>().ReturnText() + text3.GetComponent<TextBox>().ReturnText()
+ text4.GetComponent<TextBox>().ReturnText() + text5.GetComponent<TextBox>().ReturnText() + text6.GetComponent<TextBox>().ReturnText();
2024-11-16 02:05:07 +08:00
foreach (GameObject item in list)
2024-11-13 21:45:48 +08:00
{
2024-11-16 02:05:07 +08:00
if (item.GetComponent<TextBox>().ParentHouse.GetComponent<HouseBtn>().roomNo == int.Parse(room_id))
{
2024-11-16 05:56:57 +08:00
2024-11-16 16:01:27 +08:00
//item.GetComponent<TextBox>().ParentHouse.GetComponent<HouseBtn>().wn.GetComponent<wuniusj>().yingchang();
2024-11-16 02:05:07 +08:00
item.GetComponent<TextBox>().PlayAni();
2024-11-18 16:53:39 +08:00
ControMoney(item);//<2F><>Ǯ
2024-11-16 02:05:07 +08:00
}
2024-11-13 21:45:48 +08:00
}
}
public void ControMoney(GameObject text)
{
float giveMoney= text.GetComponent<TextBox>().ReturnText();
text.GetComponent<TextBox>().SetText(-giveMoney);
float AllMoney = text1.GetComponent<TextBox>().ReturnText() + text2.GetComponent<TextBox>().ReturnText() + text3.GetComponent<TextBox>().ReturnText()
+ text4.GetComponent<TextBox>().ReturnText() + text5.GetComponent<TextBox>().ReturnText() + text6.GetComponent<TextBox>().ReturnText();
for (int i=0;i<list.Count;i++)
{
if (list[i]==text)
{
continue;
}
list[i].GetComponent<TextBox>().SetText(giveMoney*(list[i].GetComponent<TextBox>().ReturnText()/AllMoney));
}
}
2024-11-18 16:53:39 +08:00
//public void GiveMoneyToPlayer()
//{
// switch (PlayerMovePos.instance.HouseId)
// {
// case 1:
// PlayerInfo.instance.SetMoney(text1.GetComponent<TextBox>().ReturnText()/2);
2024-11-13 21:45:48 +08:00
2024-11-18 16:53:39 +08:00
// break;
// case 2:
// PlayerInfo.instance.SetMoney(text2.GetComponent<TextBox>().ReturnText()/2);
// break;
// case 3:
// PlayerInfo.instance.SetMoney(text3.GetComponent<TextBox>().ReturnText() / 2);
// break;
// case 4:
// PlayerInfo.instance.SetMoney(text4.GetComponent<TextBox>().ReturnText()/2);
// break;
// case 5:
// PlayerInfo.instance.SetMoney(text5.GetComponent<TextBox>().ReturnText() / 2);
// break;
// case 6:
// PlayerInfo.instance.SetMoney(text6.GetComponent<TextBox>().ReturnText() / 2);
// break;
// default:
// Debug.Log("δѡ<CEB4>񷿼<EFBFBD>");
// break;
// }
//}
2024-11-12 14:06:34 +08:00
}