using System.Collections; using System.Collections.Generic; using Cysharp.Threading.Tasks; using UnityEngine; using LitJson; public class ServerListParser : SingletonMonobehaviour { bool hasCommonResult = false; ServerInfoCommon serverInfoCommon; bool hasPlayerResult = false; ServerInfoPlayer serverInfoPlayer; public void PushCommonServerListRawData(string content) { hasCommonResult = false; ParseCommonServerListAsync(content).Forget(); } private async UniTaskVoid ParseCommonServerListAsync(string content) { await UniTask.Yield(); serverInfoCommon = JsonMapper.ToObject(content); hasCommonResult = true; } public void PushPlayerServerListRawData(string content) { hasPlayerResult = false; Debug.Log("ServerListParser:" + content); if (content == "" || content == "{}") return; JsonData RankArr = JsonMapper.ToObject(content); if (RankArr["player"]["group_list"].Count == 0) return; ParsePlayerServerListAsync(content).Forget(); } private async UniTaskVoid ParsePlayerServerListAsync(string content) { await UniTask.Yield(); serverInfoPlayer = JsonMapper.ToObject(content); hasPlayerResult = true; SetIsInWhiteList(); } public void ReportCommonResult() { if (serverInfoCommon != null) { ServerListCenter.Instance.SetServerlistCommon(serverInfoCommon); } } public void ReportPlayerResult() { if (serverInfoPlayer != null) { ServerListCenter.Instance.SetServerListPlayer(serverInfoPlayer); } } public void SetIsInWhiteList() { DebugUtility.Instance.isWhiteListAccount = serverInfoPlayer.white == 1; } private void Update() { if (hasCommonResult) { ReportCommonResult(); hasCommonResult = false; } if (hasPlayerResult) { ReportPlayerResult(); hasPlayerResult = false; } } }