1.0.3 버그 수정

This commit is contained in:
Ino 2025-11-12 15:18:56 +09:00
parent 8b4df58198
commit 3960cbc84a
3 changed files with 143 additions and 40 deletions

View File

@ -1 +1 @@
21 23

View File

@ -7,15 +7,22 @@ public class ADInfo : MonoBehaviourSingletonTemplate<ADInfo>,
{ {
#if UNITY_ANDROID #if UNITY_ANDROID
string gameId = "5947579"; string gameId = "5947579";
string placement_Interstitial = "Interstitial_Android";
string placement_Rewarded = "Rewarded_Android";
string placement_Banner = "Banner_Android";
#elif UNITY_IOS #elif UNITY_IOS
string gameId = "5947578"; string gameId = "5947578";
string placement_Interstitial = "Interstitial_iOS";
string placement_Rewarded = "Rewarded_iOS";
string placement_Banner = "Banner_iOS";
#endif #endif
bool testMode = false; bool testMode = false;
string placement_Interstitial = "Interstitial_Android"; bool interstitialReady = false;
string placement_Rewarded = "Rewarded_Android"; bool rewardedReady = false;
string placement_Banner = "Banner_Android"; bool bannerLoaded = false;
bool bannerVisible = false;
byte GetReward = 0; byte GetReward = 0;
Action Action_success, Action_fail; Action Action_success, Action_fail;
@ -26,6 +33,9 @@ public class ADInfo : MonoBehaviourSingletonTemplate<ADInfo>,
Advertisement.Initialize(gameId, testMode, this); Advertisement.Initialize(gameId, testMode, this);
} }
// ===========================================================
// 광고 시청 요청
// ===========================================================
public void Show_AD(bool bshort, Action _success, Action _fail = null) public void Show_AD(bool bshort, Action _success, Action _fail = null)
{ {
Stop_Game(); Stop_Game();
@ -41,43 +51,119 @@ public class ADInfo : MonoBehaviourSingletonTemplate<ADInfo>,
return; return;
} }
Advertisement.Load(placement_Interstitial, this); if (interstitialReady)
{
Advertisement.Show(placement_Interstitial, this);
interstitialReady = false;
} }
else else
{ {
Advertisement.Load(placement_Rewarded, this); LobbyUI.Ins.m_ToastUI.Set("광고를 준비 중입니다.\n잠시 후 다시 시도해주세요.");
GetReward = 3;
}
}
else
{
if (rewardedReady)
{
Advertisement.Show(placement_Rewarded, this);
rewardedReady = false;
}
else
{
LobbyUI.Ins.m_ToastUI.Set("광고를 준비 중입니다.\n잠시 후 다시 시도해주세요.");
GetReward = 3;
}
} }
} }
// ===========================================================
// 배너 광고 제어
// ===========================================================
// 외부에서 배너를 켜거나 끌 때 호출
public void Set_Banner(bool active) public void Set_Banner(bool active)
{ {
return; // 일단 비활성화
if (SaveMgr.Ins.Get_ShopNoAD())
{
// No-AD 유저면 항상 숨김
if (bannerVisible)
{
HideBanner();
}
return; return;
}
if (active) if (active)
{ {
if (!SaveMgr.Ins.Get_ShopNoAD()) ShowBanner();
}
else
{ {
Advertisement.Banner.Load(placement_Banner, new BannerLoadOptions HideBanner();
}
}
void LoadBanner()
{
if (bannerLoaded) return;
var options = new BannerLoadOptions
{ {
loadCallback = () => loadCallback = () =>
{ {
Debug.Log("Banner Load Success"); Debug.Log("Banner Load Success");
Advertisement.Banner.SetPosition(BannerPosition.BOTTOM_CENTER); bannerLoaded = true;
Advertisement.Banner.Show(placement_Banner); // 자동으로 보이게 하려면 아래 호출
// Advertisement.Banner.Show(placement_Banner);
}, },
errorCallback = (err) => errorCallback = (err) =>
{ {
Debug.Log("Banner Load Fail: " + err); Debug.LogWarning("Banner Load Fail: " + err);
} bannerLoaded = false;
}); // 필요시 재시도 로직 (예: 일정 시간 후 다시 Load)
} // StartCoroutine(RetryLoadBannerCoroutine());
}
else
{
Advertisement.Banner.Hide();
} }
};
Advertisement.Banner.SetPosition(BannerPosition.BOTTOM_CENTER);
Advertisement.Banner.Load(placement_Banner, options);
} }
void ShowBanner()
{
if (SaveMgr.Ins.Get_ShopNoAD()) return;
if (!bannerLoaded)
{
// 로드가 안 되어 있으면 우선 로드하고, 로드시 자동으로 보여주게 처리
LoadBanner();
// 간단 처리: 로드 완료 콜백에서 실제로 보여주도록 하거나 즉시 안내 메시지
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;
}
// ===========================================================
// 업데이트 - 광고 결과 처리
// ===========================================================
protected override void Update() protected override void Update()
{ {
base.Update(); base.Update();
@ -88,11 +174,11 @@ public class ADInfo : MonoBehaviourSingletonTemplate<ADInfo>,
Play_Game(); Play_Game();
Action_success?.Invoke(); Action_success?.Invoke();
break; break;
case 2: case 2:
case 3: case 3:
GetReward = 0; GetReward = 0;
Play_Game(); Play_Game();
LobbyUI.Ins.m_ToastUI.Set("준비된 광고가 없습니다.\n나중에 다시 시도해 주세요.");
Action_fail?.Invoke(); Action_fail?.Invoke();
break; break;
} }
@ -114,12 +200,19 @@ public class ADInfo : MonoBehaviourSingletonTemplate<ADInfo>,
// =========================================================== // ===========================================================
public void OnInitializationComplete() public void OnInitializationComplete()
{ {
Debug.Log("Unity Ads Initialization Complete"); Debug.Log("✅ Unity Ads Initialized");
// 초기화 완료 후 광고 미리 로드 (인터스티셜 + 리워드)
Advertisement.Load(placement_Interstitial, this);
Advertisement.Load(placement_Rewarded, this);
// 배너도 미리 로드하되, 자동 노출은 하지 않음
LoadBanner();
} }
public void OnInitializationFailed(UnityAdsInitializationError error, string message) public void OnInitializationFailed(UnityAdsInitializationError error, string message)
{ {
Debug.LogError($"Unity Ads Init Failed: {error} - {message}"); Debug.LogError($"Unity Ads Init Failed: {error} - {message}");
} }
// =========================================================== // ===========================================================
@ -128,13 +221,17 @@ public class ADInfo : MonoBehaviourSingletonTemplate<ADInfo>,
public void OnUnityAdsAdLoaded(string placementId) public void OnUnityAdsAdLoaded(string placementId)
{ {
Debug.Log("Ad Loaded: " + placementId); Debug.Log("Ad Loaded: " + placementId);
Advertisement.Show(placementId, this); if (placementId == placement_Interstitial)
interstitialReady = true;
else if (placementId == placement_Rewarded)
rewardedReady = true;
} }
public void OnUnityAdsFailedToLoad(string placementId, UnityAdsLoadError error, string message) public void OnUnityAdsFailedToLoad(string placementId, UnityAdsLoadError error, string message)
{ {
Debug.LogError($"Failed to load Ad {placementId}: {error} - {message}"); Debug.LogError($"❌ Failed to load Ad {placementId}: {error} - {message}");
GetReward = 2; if (placementId == placement_Interstitial) interstitialReady = false;
else if (placementId == placement_Rewarded) rewardedReady = false;
} }
// =========================================================== // ===========================================================
@ -146,12 +243,18 @@ public class ADInfo : MonoBehaviourSingletonTemplate<ADInfo>,
GetReward = 1; GetReward = 1;
else else
GetReward = 2; GetReward = 2;
// 광고 시청 후 즉시 다음 광고 미리 로드
Advertisement.Load(placementId, this);
} }
public void OnUnityAdsShowFailure(string placementId, UnityAdsShowError error, string message) public void OnUnityAdsShowFailure(string placementId, UnityAdsShowError error, string message)
{ {
Debug.LogError($"Show failed {placementId}: {error} - {message}"); Debug.LogError($"Show failed {placementId}: {error} - {message}");
GetReward = 2; GetReward = 2;
// 실패했어도 다음 광고 미리 로드 시도
Advertisement.Load(placementId, this);
} }
public void OnUnityAdsShowStart(string placementId) { } public void OnUnityAdsShowStart(string placementId) { }