DO-66 [Fix] 랭킹 자동 로그인 시 데이터 로드
This commit is contained in:
parent
d906bc234f
commit
6587d00b8c
@ -228,7 +228,12 @@ public class NetworkManager : Singleton<NetworkManager>
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerator GetLeaderboard(Action<Scores> success, Action failure)
|
||||
public void GetLeaderboard(Action<List<ScoreInfo>> success, Action failure)
|
||||
{
|
||||
StartCoroutine(GetLeaderboardCoroutine(success, failure));
|
||||
}
|
||||
|
||||
public IEnumerator GetLeaderboardCoroutine(Action<List<ScoreInfo>> success, Action failure)
|
||||
{
|
||||
using (UnityWebRequest www =
|
||||
new UnityWebRequest(Constants.ServerURL + "/leaderboard", UnityWebRequest.kHttpVerbGET))
|
||||
@ -256,10 +261,15 @@ public class NetworkManager : Singleton<NetworkManager>
|
||||
}
|
||||
else
|
||||
{
|
||||
var result = www.downloadHandler.text;
|
||||
var scores = JsonUtility.FromJson<Scores>(result);
|
||||
// 성공적으로 데이터를 받아온 경우
|
||||
string jsonResponse = www.downloadHandler.text; // 응답으로 받은 JSON 데이터
|
||||
|
||||
success?.Invoke(scores);
|
||||
// JSON을 ScoreInfo 리스트로 파싱
|
||||
ScoreListWrapper wrapper = JsonUtility.FromJson<ScoreListWrapper>(jsonResponse);
|
||||
List<ScoreInfo> leaderboardItems = wrapper.leaderboardDatas;
|
||||
|
||||
// Show 메서드를 통해 데이터를 표시
|
||||
success?.Invoke(leaderboardItems);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -511,36 +521,4 @@ public class NetworkManager : Singleton<NetworkManager>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void GetLeaderboardData(Action<List<ScoreInfo>> success, Action failure)
|
||||
{
|
||||
StartCoroutine(GetLeaderboardDataCoroutine(success, failure));
|
||||
}
|
||||
|
||||
private IEnumerator GetLeaderboardDataCoroutine(Action<List<ScoreInfo>> 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<ScoreListWrapper>(jsonResponse);
|
||||
List<ScoreInfo> leaderboardItems = wrapper.leaderboardDatas;
|
||||
|
||||
// Show 메서드를 통해 데이터를 표시
|
||||
success?.Invoke(leaderboardItems);
|
||||
}
|
||||
}
|
||||
}
|
@ -27,7 +27,7 @@ public class LeaderBoardController : MonoBehaviour
|
||||
if (isLeaderboardLoaded) return; // 이미 리더보드가 로드되었으면 중복 호출 방지
|
||||
|
||||
leaderboardPanel.SetActive(true);
|
||||
NetworkManager.Instance.GetLeaderboardData((leaderboardItems) =>
|
||||
NetworkManager.Instance.GetLeaderboard((leaderboardItems) =>
|
||||
{
|
||||
Show(leaderboardItems);
|
||||
}, () => { });
|
||||
|
Loading…
x
Reference in New Issue
Block a user