From 6587d00b8c64527352ca26402ffdf35ebda1f3b7 Mon Sep 17 00:00:00 2001 From: Jay <96156114+jaydev00a@users.noreply.github.com> Date: Thu, 27 Mar 2025 10:23:54 +0900 Subject: [PATCH] =?UTF-8?q?DO-66=20[Fix]=20=EB=9E=AD=ED=82=B9=20=EC=9E=90?= =?UTF-8?q?=EB=8F=99=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=20=EC=8B=9C=20=EB=8D=B0?= =?UTF-8?q?=EC=9D=B4=ED=84=B0=20=EB=A1=9C=EB=93=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Script/Main/NetworkManager.cs | 54 ++++++------------- .../PanelController/LeaderBoardController.cs | 2 +- 2 files changed, 17 insertions(+), 39 deletions(-) diff --git a/Assets/Script/Main/NetworkManager.cs b/Assets/Script/Main/NetworkManager.cs index aca1bf4..b49ffd9 100644 --- a/Assets/Script/Main/NetworkManager.cs +++ b/Assets/Script/Main/NetworkManager.cs @@ -227,8 +227,13 @@ public class NetworkManager : Singleton } } } - - public IEnumerator GetLeaderboard(Action success, Action failure) + + public void GetLeaderboard(Action> success, Action failure) + { + StartCoroutine(GetLeaderboardCoroutine(success, failure)); + } + + public IEnumerator GetLeaderboardCoroutine(Action> success, Action failure) { using (UnityWebRequest www = new UnityWebRequest(Constants.ServerURL + "/leaderboard", UnityWebRequest.kHttpVerbGET)) @@ -256,10 +261,15 @@ public class NetworkManager : Singleton } else { - var result = www.downloadHandler.text; - var scores = JsonUtility.FromJson(result); - - success?.Invoke(scores); + // 성공적으로 데이터를 받아온 경우 + string jsonResponse = www.downloadHandler.text; // 응답으로 받은 JSON 데이터 + + // JSON을 ScoreInfo 리스트로 파싱 + ScoreListWrapper wrapper = JsonUtility.FromJson(jsonResponse); + List leaderboardItems = wrapper.leaderboardDatas; + + // Show 메서드를 통해 데이터를 표시 + success?.Invoke(leaderboardItems); } } } @@ -511,36 +521,4 @@ public class NetworkManager : Singleton } } } - - public void GetLeaderboardData(Action> success, Action failure) - { - StartCoroutine(GetLeaderboardDataCoroutine(success, failure)); - } - - private IEnumerator GetLeaderboardDataCoroutine(Action> success, Action failure) - { - string url = Constants.ServerURL + "/leaderboard/"; // 서버의 리더보드 데이터 URL - - UnityWebRequest www = UnityWebRequest.Get(url); // GET 요청으로 데이터 받기 - yield return www.SendWebRequest(); // 요청 전송 대기 - - // 요청이 실패했을 때 - if (www.result == UnityWebRequest.Result.ConnectionError || www.result == UnityWebRequest.Result.ProtocolError) - { - Debug.LogError("Error: " + www.error); - failure?.Invoke(); - } - else - { - // 성공적으로 데이터를 받아온 경우 - string jsonResponse = www.downloadHandler.text; // 응답으로 받은 JSON 데이터 - - // JSON을 ScoreInfo 리스트로 파싱 - ScoreListWrapper wrapper = JsonUtility.FromJson(jsonResponse); - List leaderboardItems = wrapper.leaderboardDatas; - - // Show 메서드를 통해 데이터를 표시 - success?.Invoke(leaderboardItems); - } - } } \ No newline at end of file diff --git a/Assets/Script/UI/PanelController/LeaderBoardController.cs b/Assets/Script/UI/PanelController/LeaderBoardController.cs index 6143beb..dd2de8f 100644 --- a/Assets/Script/UI/PanelController/LeaderBoardController.cs +++ b/Assets/Script/UI/PanelController/LeaderBoardController.cs @@ -27,7 +27,7 @@ public class LeaderBoardController : MonoBehaviour if (isLeaderboardLoaded) return; // 이미 리더보드가 로드되었으면 중복 호출 방지 leaderboardPanel.SetActive(true); - NetworkManager.Instance.GetLeaderboardData((leaderboardItems) => + NetworkManager.Instance.GetLeaderboard((leaderboardItems) => { Show(leaderboardItems); }, () => { });