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

75 lines
2.3 KiB
C#
Raw Normal View History

2024-11-18 18:52:31 +08:00
using Newtonsoft.Json;
2024-11-13 18:01:18 +08:00
using System.Collections;
using System.Collections.Generic;
2024-11-18 16:53:39 +08:00
using TMPro;
2024-11-13 18:01:18 +08:00
using UnityEngine;
2024-11-18 18:52:31 +08:00
using System.Threading.Tasks;
2024-11-13 18:01:18 +08:00
public class PlayerInfo : MonoBehaviour
{
public static PlayerInfo instance;
2024-11-18 18:52:31 +08:00
public static UserInfomation14 userInfomation14;
2024-11-20 10:24:18 +08:00
public float Money = 0;
2024-11-25 23:27:41 +08:00
public float Ichor= 0;
2024-11-18 16:53:39 +08:00
public float AllBetCoins;//<2F>ܹ<EFBFBD><DCB9><EFBFBD>ע<EFBFBD><D7A2>
public TextMeshProUGUI SelfWoniuText;//<2F><>ţ<EFBFBD><C5A3>ע<EFBFBD><D7A2>ʾ<EFBFBD>ı<EFBFBD>
2024-11-18 17:02:12 +08:00
public bool HaveBet;//<2F>Ƿ<EFBFBD><C7B7>Ѿ<EFBFBD><D1BE><EFBFBD>ע<EFBFBD><D7A2>
2024-11-19 17:55:35 +08:00
public Transform BetText;
2024-11-13 18:01:18 +08:00
// Start is called before the first frame update
void Start()
{
instance = this;
2024-11-13 21:45:48 +08:00
EggNum.instance.eggNumText.text=Money.ToString();
2024-11-18 18:52:31 +08:00
QueryPlayerInfo();
2024-11-13 18:01:18 +08:00
}
2024-11-19 17:55:35 +08:00
2024-11-13 18:01:18 +08:00
public bool SetMoney(float add)
{
if (Money+add>=0)
{
2024-11-13 21:45:48 +08:00
float start = Money;
2024-11-13 18:01:18 +08:00
Money += add;
2024-11-13 21:45:48 +08:00
EggNum.instance.SetEggNumText(start);
2024-11-13 18:01:18 +08:00
return true;
}
Debug.Log(<><C7AE><EFBFBD><EFBFBD>");
return false;
}
// Update is called once per frame
void Update()
{
2024-11-18 18:52:31 +08:00
if (userInfomation14 != null)
{
Money = userInfomation14.data.beansCoin;
2024-11-25 23:27:41 +08:00
Ichor = userInfomation14.data.ichorCoin;
2024-11-18 18:52:31 +08:00
EggNum.instance.eggNumText.text = Money.ToString();
2024-11-25 23:27:41 +08:00
IchorText.instance.ichorText.text = Ichor.ToString();
2024-11-18 18:52:31 +08:00
}
2024-11-19 17:55:35 +08:00
BetText.position = new Vector2(transform.position.x, transform.position.y + 100);
2024-11-18 18:52:31 +08:00
}
// <20><>ѯ<EFBFBD><D1AF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
2024-11-25 23:27:41 +08:00
public async Task QueryPlayerInfo() // 1.4
2024-11-18 18:52:31 +08:00
{
// ׼<><D7BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ȩ<EFBFBD><C8A8><EFBFBD><EFBFBD>
Dictionary<string, string> head14 = new Dictionary<string, string>
{
{ "Authorization", Global.global.serverResponse.data.token }
};
// <20><EFBFBD><ECB2BD>ѯ<EFBFBD><D1AF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
string response14 = await web.SendRequest(web.URL + "/snail/user/queryUserInfo", "POST", "{}", head14);
Debug.Log("1.4<EFBFBD><EFBFBD>ѯ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ" + response14);
userInfomation14 = JsonConvert.DeserializeObject<UserInfomation14>(response14);
Debug.Log("<22><><EFBFBD><EFBFBD>ʣ<EFBFBD><CAA3><EFBFBD>ϵ<EFBFBD><CFB5><EFBFBD>" + userInfomation14.data.beansCoin);
//Money = userInfomation14.beansCoin;
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD>
Global.global.response = JsonConvert.DeserializeObject<ServerResponse>(response14);
// <20><><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5>ֻ<EFBFBD><D6BB><EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD><ECB2BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
await Task.CompletedTask; // <20><><EFBFBD><EFBFBD>ֱ<EFBFBD>ӷ<EFBFBD><D3B7>أ<EFBFBD><D8A3><EFBFBD>ʹ<EFBFBD><CAB9> await
2024-11-13 18:01:18 +08:00
}
}
2024-11-18 18:52:31 +08:00