From 090c7bf518b4a9455f4db5af6a49d7fdb0e02ac4 Mon Sep 17 00:00:00 2001 From: 99jamin <99jamin56@gmail.com> Date: Fri, 21 Mar 2025 16:24:56 +0900 Subject: [PATCH] =?UTF-8?q?Do-44=20[Feat]=20=EA=B2=8C=EC=9E=84=20=EC=8B=9C?= =?UTF-8?q?=EC=9E=91=20=EC=8B=9C=20=EC=BD=94=EC=9D=B8=20=EC=B0=A8=EA=B0=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/KJM/Admob/AdManager.cs | 8 +-- Assets/KJM/ShopTest/ShopTestKJM.unity | 13 ++++ .../Prefabs/Panels/Main Panel.prefab | 1 + Assets/Script/Common/CoinsPanelController.cs | 8 ++- Assets/Script/Main/MainPanelController.cs | 6 +- Assets/Script/Main/NetworkManager.cs | 66 +++++++++++++++++++ Assets/Script/Main/UserManager.cs | 11 ++++ .../ShopItemController.cs | 5 +- .../Script/UI/PanelController/PanelManager.cs | 20 +++++- 9 files changed, 125 insertions(+), 13 deletions(-) diff --git a/Assets/KJM/Admob/AdManager.cs b/Assets/KJM/Admob/AdManager.cs index 1950296..109c5cb 100644 --- a/Assets/KJM/Admob/AdManager.cs +++ b/Assets/KJM/Admob/AdManager.cs @@ -44,14 +44,14 @@ public class AdManager : MonoBehaviour } // 보상형 전면 광고 실행 - public void ShowRewardedInterstitialAd(CanvasGroup shopPanel) + public void ShowRewardedInterstitialAd() { if (rewardedInterstitialAd != null && rewardedInterstitialAd.CanShowAd()) { rewardedInterstitialAd.Show((Reward reward) => //서버에서 500코인을 고정으로 반환하기 때문에 reward는 사용하지 않음. { // 코인 지급 로직 - GrantReward(shopPanel); + GrantReward(); }); } else @@ -67,12 +67,12 @@ public class AdManager : MonoBehaviour } // 코인 지급 함수 - private void GrantReward(CanvasGroup shopPanel) + private void GrantReward() { NetworkManager.Instance.WatchAdForCoins((coinsAdded) => { // UI 업데이트 - GameManager.Instance.panelManager.UpdateCoinsPanelUI(coinsAdded, shopPanel); + GameManager.Instance.panelManager.UpdateCoinsPanelUI(coinsAdded); }, () => { Debug.Log("광고 시청 후 코인 추가 실패"); diff --git a/Assets/KJM/ShopTest/ShopTestKJM.unity b/Assets/KJM/ShopTest/ShopTestKJM.unity index dda09c9..769da6e 100644 --- a/Assets/KJM/ShopTest/ShopTestKJM.unity +++ b/Assets/KJM/ShopTest/ShopTestKJM.unity @@ -395,6 +395,7 @@ GameObject: - component: {fileID: 1340395581} - component: {fileID: 1340395580} - component: {fileID: 1340395579} + - component: {fileID: 1340395583} m_Layer: 5 m_Name: Canvas m_TagString: Untagged @@ -484,6 +485,18 @@ RectTransform: m_AnchoredPosition: {x: 0, y: 0} m_SizeDelta: {x: 0, y: 0} m_Pivot: {x: 0, y: 0} +--- !u!225 &1340395583 +CanvasGroup: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1340395578} + m_Enabled: 1 + m_Alpha: 1 + m_Interactable: 1 + m_BlocksRaycasts: 1 + m_IgnoreParentGroups: 0 --- !u!1 &1377839198 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Resources/Prefabs/Panels/Main Panel.prefab b/Assets/Resources/Prefabs/Panels/Main Panel.prefab index 5e9ded7..ef894a8 100644 --- a/Assets/Resources/Prefabs/Panels/Main Panel.prefab +++ b/Assets/Resources/Prefabs/Panels/Main Panel.prefab @@ -1713,6 +1713,7 @@ MonoBehaviour: m_OnCullStateChanged: m_PersistentCalls: m_Calls: [] + m_text: kjm m_isRightToLeft: 0 m_fontAsset: {fileID: 11400000, guid: 85a19688db53c77469fc4406b01045da, type: 2} m_sharedMaterial: {fileID: -2477908578676791210, guid: 85a19688db53c77469fc4406b01045da, type: 2} diff --git a/Assets/Script/Common/CoinsPanelController.cs b/Assets/Script/Common/CoinsPanelController.cs index 38c3dcd..eba6cae 100644 --- a/Assets/Script/Common/CoinsPanelController.cs +++ b/Assets/Script/Common/CoinsPanelController.cs @@ -20,6 +20,7 @@ public class CoinsPanelController : MonoBehaviour private AudioSource _audioSource; private int _coinsCount; private RectTransform _coinsRect; + private CanvasGroup _canvasGroup; //부모 캔버스 그룹 // 1. 코인 추가 연출 // 2. 코인 감소 연출 @@ -30,6 +31,7 @@ public class CoinsPanelController : MonoBehaviour _audioSource = GetComponent(); _coinsColor = coinsRemoveImageObject.GetComponent().color; _coinsRect = GetComponent(); + _canvasGroup = GetComponentInParent(); } private void Start() @@ -96,9 +98,9 @@ public class CoinsPanelController : MonoBehaviour /// 추가할 코인 수량 /// 상점 패널 캔버스 그룹 /// 애니메이션 종료 후 동작 EX) 코인 수량 변경 - public void AddCoins(int coinsCount, CanvasGroup shopPanel,Action action) + public void AddCoins(int coinsCount, Action action) { - shopPanel.blocksRaycasts = false; //코인 중복 추가 방지 코드 + _canvasGroup.blocksRaycasts = false; //코인 중복 추가 방지 코드 Sequence sequence = DOTween.Sequence(); // i += a 반복 횟수 조절, 100개 단위로 상승 차감 시 100으로 설정 @@ -120,7 +122,7 @@ public class CoinsPanelController : MonoBehaviour } sequence.OnComplete(() => { - shopPanel.blocksRaycasts = true; //구매 후 클릭 활성화 + _canvasGroup.blocksRaycasts = true; //구매 후 클릭 활성화 }); } diff --git a/Assets/Script/Main/MainPanelController.cs b/Assets/Script/Main/MainPanelController.cs index 9f0c9c3..75bde69 100644 --- a/Assets/Script/Main/MainPanelController.cs +++ b/Assets/Script/Main/MainPanelController.cs @@ -82,7 +82,11 @@ public class MainPanelController : MonoBehaviour //대국 시작 버튼 클릭 public void OnClickGameStart() { - GameManager.Instance.ChangeToGameScene(Enums.GameType.SinglePlay); + //코인 차감 후 게임 씬 로드 + GameManager.Instance.panelManager.RemoveCoinsPanelUI((() => + { + GameManager.Instance.ChangeToGameScene(Enums.GameType.SinglePlay); + })); } //상점 패널 생성 diff --git a/Assets/Script/Main/NetworkManager.cs b/Assets/Script/Main/NetworkManager.cs index 903a866..180e998 100644 --- a/Assets/Script/Main/NetworkManager.cs +++ b/Assets/Script/Main/NetworkManager.cs @@ -446,6 +446,72 @@ public class NetworkManager : Singleton } } + /// + /// 코인 제거 함수 + /// + /// + /// + public void DeductCoins(Action success, Action failure) + { + StartCoroutine(DeductCoinsCoroutine(success, failure)); + } + + private IEnumerator DeductCoinsCoroutine(Action success, Action failure) + { + string DeductCoinsUrl = Constants.ServerURL + "/coins/deduct"; + + using (UnityWebRequest www = new UnityWebRequest(DeductCoinsUrl, UnityWebRequest.kHttpVerbPOST)) + { + www.downloadHandler = new DownloadHandlerBuffer(); + string sid = PlayerPrefs.GetString("sid", ""); + + if (!string.IsNullOrEmpty(sid)) + { + www.SetRequestHeader("Cookie", sid); + } + else + { + Debug.LogError("SID 값이 없습니다. 로그인 정보가 없습니다."); + failure?.Invoke("LOGIN_REQUIRED"); + yield break; + } + + yield return www.SendWebRequest(); + + if (www.result == UnityWebRequest.Result.ConnectionError || + www.result == UnityWebRequest.Result.ProtocolError) + { + Debug.LogError("코인 차감 실패: " + www.error); + + if (www.responseCode == 400) + { + failure?.Invoke("INSUFFICIENT_COINS"); + } + else + { + failure?.Invoke("ERROR"); + } + } + else + { + var result = www.downloadHandler.text; + var deductResult = JsonUtility.FromJson(result); + + if (deductResult.result == "SUCCESS") + { + Debug.Log("코인 차감 완료: " + deductResult.deducted); + UserManager.Instance.SetCoinsInfo(); + success?.Invoke(deductResult.deducted); + } + else + { + Debug.LogError("코인 차감 실패: " + deductResult.result); + failure?.Invoke(deductResult.result); + } + } + } + } + public void GetLeaderboardData(Action> success, Action failure) { StartCoroutine(GetLeaderboardDataCoroutine(success, failure)); diff --git a/Assets/Script/Main/UserManager.cs b/Assets/Script/Main/UserManager.cs index 83fff14..c9f99e9 100644 --- a/Assets/Script/Main/UserManager.cs +++ b/Assets/Script/Main/UserManager.cs @@ -58,6 +58,17 @@ public class PurchaseData } } +/// +/// 코인 차감 응답 데이터 클래스 +/// +public class DeductCoinsResult +{ + public string result; + public string message; + public int deducted; + public int remainingCoins; +} + public class UserManager : Singleton diff --git a/Assets/Script/UI/PanelChildController/ShopItemController.cs b/Assets/Script/UI/PanelChildController/ShopItemController.cs index 7b39614..63437bc 100644 --- a/Assets/Script/UI/PanelChildController/ShopItemController.cs +++ b/Assets/Script/UI/PanelChildController/ShopItemController.cs @@ -22,13 +22,12 @@ public class ShopItemController : MonoBehaviour public void OnClickShopItem() { - var shopPanel = GetComponentInParent(); //코인 구매시 상점 패널의 캔버스 그룹 raycast를 비활성화하여 중복클릭 방지. if (_shopItem.price == 0) { //보상형 전면 광고 로드 _adManager = GetComponent(); - _adManager.ShowRewardedInterstitialAd(shopPanel); + _adManager.ShowRewardedInterstitialAd(); } else { @@ -38,7 +37,7 @@ public class ShopItemController : MonoBehaviour _shopItem.name, // 결제 ID "GooglePay", // 결제 방식 (GooglePay, PayPal 등) (coins) => { - GameManager.Instance.panelManager.UpdateCoinsPanelUI(coins,shopPanel); + GameManager.Instance.panelManager.UpdateCoinsPanelUI(coins); }, () => { Debug.LogError("결제 후 코인 충전 실패"); diff --git a/Assets/Script/UI/PanelController/PanelManager.cs b/Assets/Script/UI/PanelController/PanelManager.cs index c1db29f..c037178 100644 --- a/Assets/Script/UI/PanelController/PanelManager.cs +++ b/Assets/Script/UI/PanelController/PanelManager.cs @@ -189,11 +189,11 @@ public class PanelManager : MonoBehaviour } //코인 패널 코인 갱신 - public void UpdateCoinsPanelUI(int coinsChanged, CanvasGroup shopPanel) + public void UpdateCoinsPanelUI(int coinsChanged) { if (_coinsPanel != null) { - _coinsPanel.AddCoins(coinsChanged, shopPanel, () => + _coinsPanel.AddCoins(coinsChanged, () => { }); @@ -204,5 +204,21 @@ public class PanelManager : MonoBehaviour } } + public void RemoveCoinsPanelUI(Action onComplete) + { + NetworkManager.Instance.DeductCoins((i) => + { + + }, (s) => + { + + }); + + _coinsPanel.RemoveCoins((() => + { + onComplete?.Invoke(); + })); + } + }