经验数据同步,更名逻辑上传

This commit is contained in:
YiHan0621
2025-09-15 18:00:52 +08:00
parent 12cf877c80
commit 0fd35d8c21
10 changed files with 463 additions and 31 deletions

View File

@@ -2,6 +2,7 @@
using System.Collections.Generic;
using UnityEngine;
using System.Threading.Tasks;
using TcgEngine.UI;
using UnityEngine.Networking;
using UnityEngine.Events;
@@ -243,7 +244,11 @@ namespace TcgEngine
udata = ApiTool.JsonToObject<UserData>(res.data);
// Debug.Log($"获取玩家数据:{res.data}");
}
else
{
Debug.LogError("失败!!!!!!!!!!!!");
}
Debug.Log($"{udata.id}");
return udata;
}
@@ -375,6 +380,32 @@ namespace TcgEngine
return response;
}
public async Task<bool> UpdateUsername(string newUsername)
{
if(!IsConnected())
return false;
string url = ServerURL + "/users/username/edit";
EditUsernameRequest req = new EditUsernameRequest();
req.username = newUsername;
string json = ApiTool.ToJson(req);
WebResponse res = await SendPostRequest(url, json);
if (res.success)
{
Debug.Log($"更名前:{username}");
username = newUsername;
MainMenu.Get().RefreshUserData();
PlayerPrefs.SetString("tcg_last_user", newUsername);
Debug.Log($"更名后:{username}");
}
else
{
Debug.LogError("改名失败" + res.error);
}
return res.success;
}
private string GetError(WebResponse res)
{
if (res.success)