262 lines
7.7 KiB
C#
262 lines
7.7 KiB
C#
using System;
|
||
using UnityEngine;
|
||
using UnityEngine.Advertisements;
|
||
|
||
public class ADInfo : MonoBehaviourSingletonTemplate<ADInfo>,
|
||
IUnityAdsInitializationListener, IUnityAdsLoadListener, IUnityAdsShowListener
|
||
{
|
||
#if UNITY_ANDROID
|
||
string gameId = "6006223";
|
||
string placement_Interstitial = "Interstitial_Android";
|
||
string placement_Rewarded = "Rewarded_Android";
|
||
string placement_Banner = "Banner_Android";
|
||
#elif UNITY_IOS
|
||
string gameId = "6006222";
|
||
string placement_Interstitial = "Interstitial_iOS";
|
||
string placement_Rewarded = "Rewarded_iOS";
|
||
string placement_Banner = "Banner_iOS";
|
||
#endif
|
||
|
||
bool testMode = false;
|
||
|
||
bool interstitialReady = false;
|
||
bool rewardedReady = false;
|
||
bool bannerLoaded = false;
|
||
bool bannerVisible = false;
|
||
|
||
byte GetReward = 0;
|
||
Action Action_success, Action_fail;
|
||
float curVolume;
|
||
|
||
void Start()
|
||
{
|
||
Advertisement.Initialize(gameId, testMode, this);
|
||
}
|
||
|
||
// ===========================================================
|
||
// ê´‘ê³ ?œì² ?”ì²
|
||
// ===========================================================
|
||
public void Show_AD(bool bshort, Action _success, Action _fail = null)
|
||
{
|
||
Stop_Game();
|
||
Action_success = _success;
|
||
Action_fail = _fail;
|
||
GetReward = 0;
|
||
|
||
if (bshort)
|
||
{
|
||
if (SaveMgr.Ins.Get_ShopNoAD())
|
||
{
|
||
GetReward = 1;
|
||
return;
|
||
}
|
||
|
||
if (interstitialReady)
|
||
{
|
||
Advertisement.Show(placement_Interstitial, this);
|
||
interstitialReady = false;
|
||
}
|
||
else
|
||
{
|
||
LobbyUI.Ins.m_ToastUI.Set("ê´‘ê³ ë¥?준ë¹?중입?ˆë‹¤.\n? 시 ???¤ì‹œ ?œë<C593>„?´ì£¼?¸ìš”.");
|
||
GetReward = 3;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (rewardedReady)
|
||
{
|
||
Advertisement.Show(placement_Rewarded, this);
|
||
rewardedReady = false;
|
||
}
|
||
else
|
||
{
|
||
LobbyUI.Ins.m_ToastUI.Set("ê´‘ê³ ë¥?준ë¹?중입?ˆë‹¤.\n? 시 ???¤ì‹œ ?œë<C593>„?´ì£¼?¸ìš”.");
|
||
GetReward = 3;
|
||
}
|
||
}
|
||
}
|
||
|
||
// ===========================================================
|
||
// 배너 ê´‘ê³ ?œì–´
|
||
// ===========================================================
|
||
// ?¸ë??<3F>서 배너ë¥?켜거???????¸ì¶œ
|
||
public void Set_Banner(bool active)
|
||
{
|
||
return; // ?¼ë‹¨ 비활?±í™”
|
||
|
||
if (SaveMgr.Ins.Get_ShopNoAD())
|
||
{
|
||
// No-AD ? ì?ë©???ƒ<> ?¨ê?
|
||
if (bannerVisible)
|
||
{
|
||
HideBanner();
|
||
}
|
||
return;
|
||
}
|
||
|
||
if (active)
|
||
{
|
||
ShowBanner();
|
||
}
|
||
else
|
||
{
|
||
HideBanner();
|
||
}
|
||
}
|
||
|
||
void LoadBanner()
|
||
{
|
||
if (bannerLoaded) return;
|
||
|
||
var options = new BannerLoadOptions
|
||
{
|
||
loadCallback = () =>
|
||
{
|
||
Debug.Log("Banner Load Success");
|
||
bannerLoaded = true;
|
||
// ?<3F>ë<EFBFBD>™?¼ë¡œ ë³´ì<C2B4>´ê²??˜ë ¤ë©??„래 ?¸ì¶œ
|
||
// Advertisement.Banner.Show(placement_Banner);
|
||
},
|
||
errorCallback = (err) =>
|
||
{
|
||
Debug.LogWarning("Banner Load Fail: " + err);
|
||
bannerLoaded = false;
|
||
// ?„ìš”???¬ì‹œ??로ì§<C3AC> (?? ?¼ì • ?œê°„ ???¤ì‹œ Load)
|
||
// StartCoroutine(RetryLoadBannerCoroutine());
|
||
}
|
||
};
|
||
|
||
Advertisement.Banner.SetPosition(BannerPosition.BOTTOM_CENTER);
|
||
Advertisement.Banner.Load(placement_Banner, options);
|
||
}
|
||
|
||
void ShowBanner()
|
||
{
|
||
if (SaveMgr.Ins.Get_ShopNoAD()) return;
|
||
|
||
if (!bannerLoaded)
|
||
{
|
||
// 로드가 ???˜ì–´ ?ˆìœ¼ë©??°ì„ 로드?˜ê³ , 로드???<3F>ë<EFBFBD>™?¼ë¡œ 보여주게 처리
|
||
LoadBanner();
|
||
// 간단 처리: 로드 ?„료 콜백?<3F>서 ?¤ì œë¡?보여주ë<C2BC>„ë¡??˜ê±°??즉시 ?ˆë‚´ 메시지
|
||
LobbyUI.Ins.m_ToastUI.Set("배너 ê´‘ê³ ì¤€ë¹?중입?ˆë‹¤.");
|
||
return;
|
||
}
|
||
|
||
var showOptions = new BannerOptions
|
||
{
|
||
clickCallback = () => Debug.Log("Banner clicked"),
|
||
hideCallback = () => Debug.Log("Banner hidden"),
|
||
showCallback = () => Debug.Log("Banner shown")
|
||
};
|
||
|
||
Advertisement.Banner.Show(placement_Banner, showOptions);
|
||
bannerVisible = true;
|
||
}
|
||
|
||
void HideBanner()
|
||
{
|
||
Advertisement.Banner.Hide(false); // trueë©?destroy
|
||
bannerVisible = false;
|
||
}
|
||
|
||
// ===========================================================
|
||
// ?…ë<E280A6>°?´íЏ - ê´‘ê³ ê²°ê³¼ 처리
|
||
// ===========================================================
|
||
protected override void Update()
|
||
{
|
||
base.Update();
|
||
switch (GetReward)
|
||
{
|
||
case 1:
|
||
GetReward = 0;
|
||
Play_Game();
|
||
Action_success?.Invoke();
|
||
break;
|
||
|
||
case 2:
|
||
case 3:
|
||
GetReward = 0;
|
||
Play_Game();
|
||
Action_fail?.Invoke();
|
||
break;
|
||
}
|
||
}
|
||
|
||
void Stop_Game()
|
||
{
|
||
curVolume = AudioListener.volume;
|
||
AudioListener.volume = 0f;
|
||
}
|
||
|
||
void Play_Game()
|
||
{
|
||
AudioListener.volume = curVolume;
|
||
}
|
||
|
||
// ===========================================================
|
||
// IUnityAdsInitializationListener
|
||
// ===========================================================
|
||
public void OnInitializationComplete()
|
||
{
|
||
Debug.Log("??Unity Ads Initialized");
|
||
|
||
// 초기???„료 ??ê´‘ê³ ë¯¸ë¦¬ 로드 (?¸í„°?¤í‹°??+ 리워??
|
||
Advertisement.Load(placement_Interstitial, this);
|
||
Advertisement.Load(placement_Rewarded, this);
|
||
|
||
// 배너??미리 로드?˜ë<CB9C>˜, ?<3F>ë<EFBFBD>™ ?¸ì¶œ?€ ?˜ì? ?Šì<C5A0>Œ
|
||
LoadBanner();
|
||
}
|
||
|
||
public void OnInitializationFailed(UnityAdsInitializationError error, string message)
|
||
{
|
||
Debug.LogError($"??Unity Ads Init Failed: {error} - {message}");
|
||
}
|
||
|
||
// ===========================================================
|
||
// IUnityAdsLoadListener
|
||
// ===========================================================
|
||
public void OnUnityAdsAdLoaded(string placementId)
|
||
{
|
||
Debug.Log("Ad Loaded: " + placementId);
|
||
if (placementId == placement_Interstitial)
|
||
interstitialReady = true;
|
||
else if (placementId == placement_Rewarded)
|
||
rewardedReady = true;
|
||
}
|
||
|
||
public void OnUnityAdsFailedToLoad(string placementId, UnityAdsLoadError error, string message)
|
||
{
|
||
Debug.LogError($"??Failed to load Ad {placementId}: {error} - {message}");
|
||
if (placementId == placement_Interstitial) interstitialReady = false;
|
||
else if (placementId == placement_Rewarded) rewardedReady = false;
|
||
}
|
||
|
||
// ===========================================================
|
||
// IUnityAdsShowListener
|
||
// ===========================================================
|
||
public void OnUnityAdsShowComplete(string placementId, UnityAdsShowCompletionState showCompletionState)
|
||
{
|
||
if (showCompletionState == UnityAdsShowCompletionState.COMPLETED)
|
||
GetReward = 1;
|
||
else
|
||
GetReward = 2;
|
||
|
||
// ê´‘ê³ ?œì² ??즉시 ?¤ì<C2A4>Œ ê´‘ê³ ë¯¸ë¦¬ 로드
|
||
Advertisement.Load(placementId, this);
|
||
}
|
||
|
||
public void OnUnityAdsShowFailure(string placementId, UnityAdsShowError error, string message)
|
||
{
|
||
Debug.LogError($"??Show failed {placementId}: {error} - {message}");
|
||
GetReward = 2;
|
||
|
||
// ?¤íŒ¨?ˆì–´???¤ì<C2A4>Œ ê´‘ê³ ë¯¸ë¦¬ 로드 ?œë<C593>„
|
||
Advertisement.Load(placementId, this);
|
||
}
|
||
|
||
public void OnUnityAdsShowStart(string placementId) { }
|
||
public void OnUnityAdsShowClick(string placementId) { }
|
||
} |