From 71c77ae0c8847d0f8478f31c681ff6f995530ffe Mon Sep 17 00:00:00 2001 From: 99jamin <99jamin56@gmail.com> Date: Wed, 19 Mar 2025 13:12:25 +0900 Subject: [PATCH] =?UTF-8?q?Do-37=20[Style]=20=EC=95=A0=EB=93=9C=EB=A7=A4?= =?UTF-8?q?=EB=8B=88=EC=A0=80=20=EC=A3=BC=EC=84=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/KJM/Admob/AdManager.cs | 2 +- Assets/Script/Main/NetworkManager.cs | 58 +++++++++++++++++++ .../ShopItemController.cs | 4 ++ 3 files changed, 63 insertions(+), 1 deletion(-) diff --git a/Assets/KJM/Admob/AdManager.cs b/Assets/KJM/Admob/AdManager.cs index ec955f1..c95ea7a 100644 --- a/Assets/KJM/Admob/AdManager.cs +++ b/Assets/KJM/Admob/AdManager.cs @@ -43,7 +43,7 @@ public class AdManager : MonoBehaviour { if (rewardedInterstitialAd != null && rewardedInterstitialAd.CanShowAd()) { - rewardedInterstitialAd.Show((Reward reward) => + rewardedInterstitialAd.Show((Reward reward) => //서버에서 500코인을 고정으로 반환하기 때문에 reward는 사용하지 않음. { // 코인 지급 로직 GrantReward(); diff --git a/Assets/Script/Main/NetworkManager.cs b/Assets/Script/Main/NetworkManager.cs index 159b098..aaa6da8 100644 --- a/Assets/Script/Main/NetworkManager.cs +++ b/Assets/Script/Main/NetworkManager.cs @@ -375,4 +375,62 @@ public class NetworkManager : Singleton } } } + + //코인 구매 함수 + public void PurchaseCoins(Action success, Action failure) + { + StartCoroutine(PurchaseCoinsCoroutine(success, failure)); + } + + private IEnumerator PurchaseCoinsCoroutine(Action success, Action failure) + { + string jsonString = "{\"adCompleted\": true}"; //테스트를 위해 ture로 설정 + byte[] bodyRaw = System.Text.Encoding.UTF8.GetBytes(jsonString); + + using (UnityWebRequest www = + new UnityWebRequest(Constants.ServerURL + "/coins/recharge/ad", 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 값이 없습니다. 로그인 정보가 없습니다."); + failure?.Invoke(); + yield break; + } + + yield return www.SendWebRequest(); + + if (www.result == UnityWebRequest.Result.ConnectionError || + www.result == UnityWebRequest.Result.ProtocolError) + { + Debug.Log("광고 시청 후 코인 충전 실패: " + www.error); + failure?.Invoke(); + } + else + { + var result = www.downloadHandler.text; + var rechargeResult = JsonUtility.FromJson(result); + + if (rechargeResult.result == "SUCCESS") + { + Debug.Log("광고 시청으로 코인 충전 완료: " + rechargeResult.recharged); + UserManager.Instance.SetCoinsInfo(); + success?.Invoke(rechargeResult.recharged); + } + else + { + Debug.Log("광고 시청 후 충전 실패: " + rechargeResult.result); + failure?.Invoke(); + } + } + } + } } \ No newline at end of file diff --git a/Assets/Script/UI/PanelChildController/ShopItemController.cs b/Assets/Script/UI/PanelChildController/ShopItemController.cs index 2245032..bb4cef0 100644 --- a/Assets/Script/UI/PanelChildController/ShopItemController.cs +++ b/Assets/Script/UI/PanelChildController/ShopItemController.cs @@ -27,5 +27,9 @@ public class ShopItemController : MonoBehaviour //보상형 전면 광고 로드 FindObjectOfType().ShowRewardedInterstitialAd(); //Todo FindOf 함수 수정 } + else + { + //todo 가격별로 구매하기 + } } }