[Feat] 네트워크매니저에 게임결과 업데이트 요청하는 함수 작성
This commit is contained in:
parent
78cb2356d7
commit
8c7d4e963d
@ -228,6 +228,61 @@ public class NetworkManager : Singleton<NetworkManager>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void UpdateScore(int isWin, Action success, Action failure)
|
||||||
|
{
|
||||||
|
StartCoroutine(UpdateScoreCoroutine(isWin, success, failure));
|
||||||
|
}
|
||||||
|
public IEnumerator UpdateScoreCoroutine(int isWin, Action success, Action failure)
|
||||||
|
{
|
||||||
|
string jsonString = "{\"isWin\": "+isWin.ToString() + "}";
|
||||||
|
byte[] bodyRaw = System.Text.Encoding.UTF8.GetBytes(jsonString);
|
||||||
|
|
||||||
|
using (UnityWebRequest www =
|
||||||
|
new UnityWebRequest(Constants.ServerURL + "/users/score-update", UnityWebRequest.kHttpVerbPOST))
|
||||||
|
{
|
||||||
|
www.uploadHandler = new UploadHandlerRaw(bodyRaw);
|
||||||
|
www.downloadHandler = new DownloadHandlerBuffer();
|
||||||
|
www.SetRequestHeader("Content-Type", "application/json");
|
||||||
|
|
||||||
|
string sid = PlayerPrefs.GetString("sid", "");
|
||||||
|
if (!string.IsNullOrEmpty(sid))
|
||||||
|
{
|
||||||
|
www.SetRequestHeader("Cookie", sid);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Debug.LogError("SID 값이 없습니다. 로그인 정보가 없습니다.");
|
||||||
|
GameManager.Instance.panelManager.OpenConfirmPanel("SID 값이 없습니다. 로그인 정보가 없습니다.", () =>
|
||||||
|
{
|
||||||
|
failure?.Invoke();
|
||||||
|
});
|
||||||
|
yield break; // 더 이상 진행하지 않고 종료
|
||||||
|
}
|
||||||
|
|
||||||
|
yield return www.SendWebRequest();
|
||||||
|
|
||||||
|
if (www.result == UnityWebRequest.Result.ConnectionError ||
|
||||||
|
www.result == UnityWebRequest.Result.ProtocolError)
|
||||||
|
{
|
||||||
|
Debug.LogError("Error: " + www.error);
|
||||||
|
failure?.Invoke();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var result = www.downloadHandler.text;
|
||||||
|
var scoreResultInfo = JsonUtility.FromJson<ScoreInfoResult>(result);
|
||||||
|
Debug.Log(scoreResultInfo.message);
|
||||||
|
Debug.Log(scoreResultInfo.rating);
|
||||||
|
Debug.Log(scoreResultInfo.score);
|
||||||
|
Debug.Log(scoreResultInfo.win);
|
||||||
|
Debug.Log(scoreResultInfo.lose);
|
||||||
|
Debug.Log(scoreResultInfo.isAdvancement);
|
||||||
|
|
||||||
|
success?.Invoke();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public IEnumerator GetLeaderboard(Action<Scores> success, Action failure)
|
public IEnumerator GetLeaderboard(Action<Scores> success, Action failure)
|
||||||
{
|
{
|
||||||
using (UnityWebRequest www =
|
using (UnityWebRequest www =
|
||||||
|
@ -20,6 +20,19 @@ public class CoinsInfoResult
|
|||||||
public int coins;
|
public int coins;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 점수 업데이트 응답 클래스
|
||||||
|
/// </summary>
|
||||||
|
public class ScoreInfoResult
|
||||||
|
{
|
||||||
|
public string message;
|
||||||
|
public int rating;
|
||||||
|
public int score;
|
||||||
|
public int win;
|
||||||
|
public int lose;
|
||||||
|
public int isAdvancement;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 코인 구매 응답 클래스
|
/// 코인 구매 응답 클래스
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -21,6 +21,24 @@ public class RatingPanelController : PanelController
|
|||||||
public void Show(Enums.GameResult gameResult)
|
public void Show(Enums.GameResult gameResult)
|
||||||
{
|
{
|
||||||
base.Show(InitRatingPanel(gameResult));
|
base.Show(InitRatingPanel(gameResult));
|
||||||
|
UpdateGameResult(gameResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpdateGameResult(Enums.GameResult gameResult)
|
||||||
|
{
|
||||||
|
switch (gameResult)
|
||||||
|
{
|
||||||
|
case (Enums.GameResult.Win):
|
||||||
|
NetworkManager.Instance.UpdateScore(1 , () =>
|
||||||
|
{
|
||||||
|
//유저 인포 업데이트
|
||||||
|
//결과화면 띄우기
|
||||||
|
},() => { });
|
||||||
|
break;
|
||||||
|
case (Enums.GameResult.Lose):
|
||||||
|
NetworkManager.Instance.UpdateScore(-1, () => { }, () => { });
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnClickConfirmButton()
|
public void OnClickConfirmButton()
|
||||||
@ -102,7 +120,6 @@ public class RatingPanelController : PanelController
|
|||||||
else
|
else
|
||||||
_ratingPointsController.SetRatingDownLimit(_oldScore+1);
|
_ratingPointsController.SetRatingDownLimit(_oldScore+1);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -120,9 +137,6 @@ public class RatingPanelController : PanelController
|
|||||||
{
|
{
|
||||||
getPointsText.text = $"게임에서 {win}했습니다.\n{Constants.RAING_POINTS} 승급 포인트를 {get}";
|
getPointsText.text = $"게임에서 {win}했습니다.\n{Constants.RAING_POINTS} 승급 포인트를 {get}";
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user