75 lines
2.3 KiB
C#
75 lines
2.3 KiB
C#
using Newtonsoft.Json;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using System.Threading.Tasks;
|
|
public class PlayerInfo : MonoBehaviour
|
|
{
|
|
public static PlayerInfo instance;
|
|
public static UserInfomation14 userInfomation14;
|
|
public float Money = 0;
|
|
public string Ichor;
|
|
public float AllBetCoins;//总共下注蛋
|
|
public TextMeshProUGUI SelfWoniuText;//蜗牛下注显示文本
|
|
public bool HaveBet;//是否已经下注过
|
|
public Transform BetText;
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
instance = this;
|
|
EggNum.instance.eggNumText.text=Money.ToString();
|
|
QueryPlayerInfo();
|
|
}
|
|
|
|
public bool SetMoney(float add)
|
|
{
|
|
if (Money+add>=0)
|
|
{
|
|
float start = Money;
|
|
Money += add;
|
|
EggNum.instance.SetEggNumText(start);
|
|
return true;
|
|
}
|
|
Debug.Log("钱不够");
|
|
return false;
|
|
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
if (userInfomation14 != null)
|
|
{
|
|
Money = userInfomation14.data.beansCoin;
|
|
Ichor = userInfomation14.data.ichorCoin;
|
|
EggNum.instance.eggNumText.text = Money.ToString();
|
|
IchorText.instance.ichorText.text = Ichor.ToString();
|
|
}
|
|
BetText.position = new Vector2(transform.position.x, transform.position.y + 100);
|
|
}
|
|
// 查询玩家信息
|
|
public async Task QueryPlayerInfo() // 1.4
|
|
{
|
|
// 准备请求的头部信息,包含授权令牌
|
|
Dictionary<string, string> head14 = new Dictionary<string, string>
|
|
{
|
|
{ "Authorization", Global.global.serverResponse.data.token }
|
|
};
|
|
|
|
// 异步查询玩家信息
|
|
string response14 = await web.SendRequest(web.URL + "/snail/user/queryUserInfo", "POST", "{}", head14);
|
|
Debug.Log("1.4查询玩家信息" + response14);
|
|
userInfomation14 = JsonConvert.DeserializeObject<UserInfomation14>(response14);
|
|
Debug.Log("玩家剩余蜗蛋:" + userInfomation14.data.beansCoin);
|
|
//Money = userInfomation14.beansCoin;
|
|
|
|
// 解析服务器返回的数据
|
|
Global.global.response = JsonConvert.DeserializeObject<ServerResponse>(response14);
|
|
|
|
// 不需要返回值,只需表示异步操作完成
|
|
await Task.CompletedTask; // 或者直接返回,不使用 await
|
|
}
|
|
}
|
|
|