Do-44 [Feat] 게임 시작 시 코인 차감
This commit is contained in:
parent
e319085e5c
commit
090c7bf518
@ -44,14 +44,14 @@ public class AdManager : MonoBehaviour
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 보상형 전면 광고 실행
|
// 보상형 전면 광고 실행
|
||||||
public void ShowRewardedInterstitialAd(CanvasGroup shopPanel)
|
public void ShowRewardedInterstitialAd()
|
||||||
{
|
{
|
||||||
if (rewardedInterstitialAd != null && rewardedInterstitialAd.CanShowAd())
|
if (rewardedInterstitialAd != null && rewardedInterstitialAd.CanShowAd())
|
||||||
{
|
{
|
||||||
rewardedInterstitialAd.Show((Reward reward) => //서버에서 500코인을 고정으로 반환하기 때문에 reward는 사용하지 않음.
|
rewardedInterstitialAd.Show((Reward reward) => //서버에서 500코인을 고정으로 반환하기 때문에 reward는 사용하지 않음.
|
||||||
{
|
{
|
||||||
// 코인 지급 로직
|
// 코인 지급 로직
|
||||||
GrantReward(shopPanel);
|
GrantReward();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -67,12 +67,12 @@ public class AdManager : MonoBehaviour
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 코인 지급 함수
|
// 코인 지급 함수
|
||||||
private void GrantReward(CanvasGroup shopPanel)
|
private void GrantReward()
|
||||||
{
|
{
|
||||||
NetworkManager.Instance.WatchAdForCoins((coinsAdded) =>
|
NetworkManager.Instance.WatchAdForCoins((coinsAdded) =>
|
||||||
{
|
{
|
||||||
// UI 업데이트
|
// UI 업데이트
|
||||||
GameManager.Instance.panelManager.UpdateCoinsPanelUI(coinsAdded, shopPanel);
|
GameManager.Instance.panelManager.UpdateCoinsPanelUI(coinsAdded);
|
||||||
}, () =>
|
}, () =>
|
||||||
{
|
{
|
||||||
Debug.Log("광고 시청 후 코인 추가 실패");
|
Debug.Log("광고 시청 후 코인 추가 실패");
|
||||||
|
@ -395,6 +395,7 @@ GameObject:
|
|||||||
- component: {fileID: 1340395581}
|
- component: {fileID: 1340395581}
|
||||||
- component: {fileID: 1340395580}
|
- component: {fileID: 1340395580}
|
||||||
- component: {fileID: 1340395579}
|
- component: {fileID: 1340395579}
|
||||||
|
- component: {fileID: 1340395583}
|
||||||
m_Layer: 5
|
m_Layer: 5
|
||||||
m_Name: Canvas
|
m_Name: Canvas
|
||||||
m_TagString: Untagged
|
m_TagString: Untagged
|
||||||
@ -484,6 +485,18 @@ RectTransform:
|
|||||||
m_AnchoredPosition: {x: 0, y: 0}
|
m_AnchoredPosition: {x: 0, y: 0}
|
||||||
m_SizeDelta: {x: 0, y: 0}
|
m_SizeDelta: {x: 0, y: 0}
|
||||||
m_Pivot: {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
|
--- !u!1 &1377839198
|
||||||
GameObject:
|
GameObject:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
@ -1713,6 +1713,7 @@ MonoBehaviour:
|
|||||||
m_OnCullStateChanged:
|
m_OnCullStateChanged:
|
||||||
m_PersistentCalls:
|
m_PersistentCalls:
|
||||||
m_Calls: []
|
m_Calls: []
|
||||||
|
m_text: kjm
|
||||||
m_isRightToLeft: 0
|
m_isRightToLeft: 0
|
||||||
m_fontAsset: {fileID: 11400000, guid: 85a19688db53c77469fc4406b01045da, type: 2}
|
m_fontAsset: {fileID: 11400000, guid: 85a19688db53c77469fc4406b01045da, type: 2}
|
||||||
m_sharedMaterial: {fileID: -2477908578676791210, guid: 85a19688db53c77469fc4406b01045da, type: 2}
|
m_sharedMaterial: {fileID: -2477908578676791210, guid: 85a19688db53c77469fc4406b01045da, type: 2}
|
||||||
|
@ -20,6 +20,7 @@ public class CoinsPanelController : MonoBehaviour
|
|||||||
private AudioSource _audioSource;
|
private AudioSource _audioSource;
|
||||||
private int _coinsCount;
|
private int _coinsCount;
|
||||||
private RectTransform _coinsRect;
|
private RectTransform _coinsRect;
|
||||||
|
private CanvasGroup _canvasGroup; //부모 캔버스 그룹
|
||||||
|
|
||||||
// 1. 코인 추가 연출
|
// 1. 코인 추가 연출
|
||||||
// 2. 코인 감소 연출
|
// 2. 코인 감소 연출
|
||||||
@ -30,6 +31,7 @@ public class CoinsPanelController : MonoBehaviour
|
|||||||
_audioSource = GetComponent<AudioSource>();
|
_audioSource = GetComponent<AudioSource>();
|
||||||
_coinsColor = coinsRemoveImageObject.GetComponent<Image>().color;
|
_coinsColor = coinsRemoveImageObject.GetComponent<Image>().color;
|
||||||
_coinsRect = GetComponent<RectTransform>();
|
_coinsRect = GetComponent<RectTransform>();
|
||||||
|
_canvasGroup = GetComponentInParent<CanvasGroup>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Start()
|
private void Start()
|
||||||
@ -96,9 +98,9 @@ public class CoinsPanelController : MonoBehaviour
|
|||||||
/// <param name="coinsCount"> 추가할 코인 수량</param>
|
/// <param name="coinsCount"> 추가할 코인 수량</param>
|
||||||
/// <param name="shopPanel">상점 패널 캔버스 그룹</param>
|
/// <param name="shopPanel">상점 패널 캔버스 그룹</param>
|
||||||
/// <param name="action">애니메이션 종료 후 동작 EX) 코인 수량 변경</param>
|
/// <param name="action">애니메이션 종료 후 동작 EX) 코인 수량 변경</param>
|
||||||
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();
|
Sequence sequence = DOTween.Sequence();
|
||||||
// i += a 반복 횟수 조절, 100개 단위로 상승 차감 시 100으로 설정
|
// i += a 반복 횟수 조절, 100개 단위로 상승 차감 시 100으로 설정
|
||||||
@ -120,7 +122,7 @@ public class CoinsPanelController : MonoBehaviour
|
|||||||
}
|
}
|
||||||
sequence.OnComplete(() =>
|
sequence.OnComplete(() =>
|
||||||
{
|
{
|
||||||
shopPanel.blocksRaycasts = true; //구매 후 클릭 활성화
|
_canvasGroup.blocksRaycasts = true; //구매 후 클릭 활성화
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,8 +81,12 @@ public class MainPanelController : MonoBehaviour
|
|||||||
|
|
||||||
//대국 시작 버튼 클릭
|
//대국 시작 버튼 클릭
|
||||||
public void OnClickGameStart()
|
public void OnClickGameStart()
|
||||||
|
{
|
||||||
|
//코인 차감 후 게임 씬 로드
|
||||||
|
GameManager.Instance.panelManager.RemoveCoinsPanelUI((() =>
|
||||||
{
|
{
|
||||||
GameManager.Instance.ChangeToGameScene(Enums.GameType.SinglePlay);
|
GameManager.Instance.ChangeToGameScene(Enums.GameType.SinglePlay);
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
//상점 패널 생성
|
//상점 패널 생성
|
||||||
|
@ -446,6 +446,72 @@ public class NetworkManager : Singleton<NetworkManager>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 코인 제거 함수
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="success"></param>
|
||||||
|
/// <param name="failure"></param>
|
||||||
|
public void DeductCoins(Action<int> success, Action<string> failure)
|
||||||
|
{
|
||||||
|
StartCoroutine(DeductCoinsCoroutine(success, failure));
|
||||||
|
}
|
||||||
|
|
||||||
|
private IEnumerator DeductCoinsCoroutine(Action<int> success, Action<string> 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<DeductCoinsResult>(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<List<ScoreInfo>> success, Action failure)
|
public void GetLeaderboardData(Action<List<ScoreInfo>> success, Action failure)
|
||||||
{
|
{
|
||||||
StartCoroutine(GetLeaderboardDataCoroutine(success, failure));
|
StartCoroutine(GetLeaderboardDataCoroutine(success, failure));
|
||||||
|
@ -58,6 +58,17 @@ public class PurchaseData
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 코인 차감 응답 데이터 클래스
|
||||||
|
/// </summary>
|
||||||
|
public class DeductCoinsResult
|
||||||
|
{
|
||||||
|
public string result;
|
||||||
|
public string message;
|
||||||
|
public int deducted;
|
||||||
|
public int remainingCoins;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class UserManager : Singleton<UserManager>
|
public class UserManager : Singleton<UserManager>
|
||||||
|
@ -22,13 +22,12 @@ public class ShopItemController : MonoBehaviour
|
|||||||
|
|
||||||
public void OnClickShopItem()
|
public void OnClickShopItem()
|
||||||
{
|
{
|
||||||
var shopPanel = GetComponentInParent<CanvasGroup>(); //코인 구매시 상점 패널의 캔버스 그룹 raycast를 비활성화하여 중복클릭 방지.
|
|
||||||
|
|
||||||
if (_shopItem.price == 0)
|
if (_shopItem.price == 0)
|
||||||
{
|
{
|
||||||
//보상형 전면 광고 로드
|
//보상형 전면 광고 로드
|
||||||
_adManager = GetComponent<AdManager>();
|
_adManager = GetComponent<AdManager>();
|
||||||
_adManager.ShowRewardedInterstitialAd(shopPanel);
|
_adManager.ShowRewardedInterstitialAd();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -38,7 +37,7 @@ public class ShopItemController : MonoBehaviour
|
|||||||
_shopItem.name, // 결제 ID
|
_shopItem.name, // 결제 ID
|
||||||
"GooglePay", // 결제 방식 (GooglePay, PayPal 등)
|
"GooglePay", // 결제 방식 (GooglePay, PayPal 등)
|
||||||
(coins) => {
|
(coins) => {
|
||||||
GameManager.Instance.panelManager.UpdateCoinsPanelUI(coins,shopPanel);
|
GameManager.Instance.panelManager.UpdateCoinsPanelUI(coins);
|
||||||
},
|
},
|
||||||
() => {
|
() => {
|
||||||
Debug.LogError("결제 후 코인 충전 실패");
|
Debug.LogError("결제 후 코인 충전 실패");
|
||||||
|
@ -189,11 +189,11 @@ public class PanelManager : MonoBehaviour
|
|||||||
}
|
}
|
||||||
|
|
||||||
//코인 패널 코인 갱신
|
//코인 패널 코인 갱신
|
||||||
public void UpdateCoinsPanelUI(int coinsChanged, CanvasGroup shopPanel)
|
public void UpdateCoinsPanelUI(int coinsChanged)
|
||||||
{
|
{
|
||||||
if (_coinsPanel != null)
|
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();
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user