修改天梯UI数据,及任务的UI数据的初步同步
This commit is contained in:
@@ -24,6 +24,10 @@ namespace TcgEngine.Gameplay
|
||||
private GameLogic gameLogic;
|
||||
private System.Random random = new System.Random();
|
||||
|
||||
public Action<List<PlayerTask>> refreshTaskUI;
|
||||
|
||||
private GameClient gameClient;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (Instance == null)
|
||||
@@ -39,18 +43,19 @@ namespace TcgEngine.Gameplay
|
||||
|
||||
private void Start()
|
||||
{
|
||||
LoadTasks();
|
||||
LoadPlayerData();
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
// 订阅游戏事件
|
||||
GameClient client = GameClient.Get();
|
||||
if (client != null)
|
||||
gameClient = FindFirstObjectByType<GameClient>();
|
||||
gameClient = GameClient.Get();
|
||||
if (gameClient != null)
|
||||
{
|
||||
client.onGameStart += OnGameStart;
|
||||
client.onGameEnd += OnGameEnd;
|
||||
LoadTasks();
|
||||
LoadPlayerData();
|
||||
gameClient.onGameStart += OnGameStart;
|
||||
gameClient.onGameEnd += OnGameEnd;
|
||||
}
|
||||
|
||||
// 移除对GameLogic.Instance的错误引用,改为检查gameLogic变量
|
||||
@@ -63,11 +68,12 @@ namespace TcgEngine.Gameplay
|
||||
private void OnDisable()
|
||||
{
|
||||
// 取消订阅游戏事件
|
||||
GameClient client = GameClient.Get();
|
||||
if (client != null)
|
||||
gameClient = FindFirstObjectByType<GameClient>();
|
||||
gameClient = GameClient.Get();
|
||||
if (gameClient != null)
|
||||
{
|
||||
client.onGameStart -= OnGameStart;
|
||||
client.onGameEnd -= OnGameEnd;
|
||||
gameClient.onGameStart -= OnGameStart;
|
||||
gameClient.onGameEnd -= OnGameEnd;
|
||||
}
|
||||
|
||||
// 移除对GameLogic.Instance的错误引用,改为检查gameLogic变量
|
||||
@@ -128,6 +134,11 @@ namespace TcgEngine.Gameplay
|
||||
Debug.Log("Loaded " + taskResponses.Length + " tasks from server");
|
||||
// 在实际项目中,这里应该将服务器数据转换为TaskData对象并存储在内存中
|
||||
// 供后续使用,而不是每次都从Resources加载
|
||||
|
||||
foreach (var item in taskResponses)
|
||||
{
|
||||
Debug.Log($"<color=pink>{item.id}</color>");
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -145,6 +156,24 @@ namespace TcgEngine.Gameplay
|
||||
Debug.Log("Loaded " + localTasks.Length + " tasks from local resources as fallback");
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
private void Update()
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.K))
|
||||
{
|
||||
LoadTasks();
|
||||
LoadPlayerData();
|
||||
SavePlayerData();
|
||||
}
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.U))
|
||||
{
|
||||
UpdateTaskProgress(TaskConditionType.WinGames, "YiYongJun", "YiYongJun");
|
||||
UpdateTaskProgress(TaskConditionType.SummonHeroWithAttributes, "WangGuoJun", "YiYongJun");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
private async void LoadPlayerData()
|
||||
{
|
||||
// 从服务器加载玩家任务数据
|
||||
@@ -159,6 +188,8 @@ namespace TcgEngine.Gameplay
|
||||
string url = ApiClient.ServerURL + "/users/" + ApiClient.Get().UserID + "/tasks";
|
||||
WebResponse res = await ApiClient.Get().SendGetRequest(url);
|
||||
|
||||
Debug.Log($"<color=red>{url}</color>");
|
||||
|
||||
if (res.success)
|
||||
{
|
||||
// 解析玩家任务数据
|
||||
@@ -175,6 +206,7 @@ namespace TcgEngine.Gameplay
|
||||
{
|
||||
PlayerTask playerTask = new PlayerTask(taskResponse);
|
||||
playerTasks.Add(playerTask);
|
||||
Debug.Log(playerTask);
|
||||
}
|
||||
|
||||
Debug.Log("Player tasks loaded from server: " + playerTasks.Count + " tasks");
|
||||
@@ -202,6 +234,7 @@ namespace TcgEngine.Gameplay
|
||||
// 将玩家任务数据保存到服务器
|
||||
if (ApiClient.Get() != null && ApiClient.Get().IsLoggedIn())
|
||||
{
|
||||
Debug.Log("<color=red> GO GO GO </color>");
|
||||
// 准备要发送的数据
|
||||
PlayerTasksResponse saveData = new PlayerTasksResponse();
|
||||
|
||||
@@ -219,9 +252,11 @@ namespace TcgEngine.Gameplay
|
||||
string url = ApiClient.ServerURL + "/users/" + ApiClient.Get().UserID + "/tasks";
|
||||
WebResponse res = await ApiClient.Get().SendPostRequest(url, json);
|
||||
|
||||
Debug.Log($"<color=red>{res}</color>");
|
||||
|
||||
if (res.success)
|
||||
{
|
||||
Debug.Log("Player tasks saved to server");
|
||||
Debug.Log("--Player tasks saved to server");
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -371,7 +406,7 @@ namespace TcgEngine.Gameplay
|
||||
private void UpdateTaskProgress(TaskConditionType conditionType, string parameter1 = null, string parameter2 = null)
|
||||
{
|
||||
bool progressUpdated = false;
|
||||
|
||||
refreshTaskUI?.Invoke(playerTasks);
|
||||
foreach (var task in playerTasks)
|
||||
{
|
||||
if (task.status != TaskStatus.Active)
|
||||
|
||||
Reference in New Issue
Block a user