diff --git a/Assets/AddressableAssetsData/Android/addressables_content_state.bin b/Assets/AddressableAssetsData/Android/addressables_content_state.bin index 0dda50c..ceb5343 100644 Binary files a/Assets/AddressableAssetsData/Android/addressables_content_state.bin and b/Assets/AddressableAssetsData/Android/addressables_content_state.bin differ diff --git a/Assets/Resources/VersionCode.txt b/Assets/Resources/VersionCode.txt index b5045cc..b393560 100644 --- a/Assets/Resources/VersionCode.txt +++ b/Assets/Resources/VersionCode.txt @@ -1 +1 @@ -21 \ No newline at end of file +23 \ No newline at end of file diff --git a/Assets/Scripts/AttachToGameObject/ADInfo.cs b/Assets/Scripts/AttachToGameObject/ADInfo.cs index af54e34..a6b093d 100644 --- a/Assets/Scripts/AttachToGameObject/ADInfo.cs +++ b/Assets/Scripts/AttachToGameObject/ADInfo.cs @@ -7,15 +7,22 @@ public class ADInfo : MonoBehaviourSingletonTemplate, { #if UNITY_ANDROID string gameId = "5947579"; + string placement_Interstitial = "Interstitial_Android"; + string placement_Rewarded = "Rewarded_Android"; + string placement_Banner = "Banner_Android"; #elif UNITY_IOS string gameId = "5947578"; + string placement_Interstitial = "Interstitial_iOS"; + string placement_Rewarded = "Rewarded_iOS"; + string placement_Banner = "Banner_iOS"; #endif bool testMode = false; - string placement_Interstitial = "Interstitial_Android"; - string placement_Rewarded = "Rewarded_Android"; - string placement_Banner = "Banner_Android"; + bool interstitialReady = false; + bool rewardedReady = false; + bool bannerLoaded = false; + bool bannerVisible = false; byte GetReward = 0; Action Action_success, Action_fail; @@ -26,6 +33,9 @@ public class ADInfo : MonoBehaviourSingletonTemplate, Advertisement.Initialize(gameId, testMode, this); } + // =========================================================== + // 광고 시청 요청 + // =========================================================== public void Show_AD(bool bshort, Action _success, Action _fail = null) { Stop_Game(); @@ -41,43 +51,119 @@ public class ADInfo : MonoBehaviourSingletonTemplate, return; } - Advertisement.Load(placement_Interstitial, this); - } - else - { - Advertisement.Load(placement_Rewarded, this); - } - } - - public void Set_Banner(bool active) - { - return; - - if (active) - { - if (!SaveMgr.Ins.Get_ShopNoAD()) + if (interstitialReady) { - Advertisement.Banner.Load(placement_Banner, new BannerLoadOptions - { - loadCallback = () => - { - Debug.Log("Banner Load Success"); - Advertisement.Banner.SetPosition(BannerPosition.BOTTOM_CENTER); - Advertisement.Banner.Show(placement_Banner); - }, - errorCallback = (err) => - { - Debug.Log("Banner Load Fail: " + err); - } - }); + Advertisement.Show(placement_Interstitial, this); + interstitialReady = false; + } + else + { + LobbyUI.Ins.m_ToastUI.Set("광고를 준비 중입니다.\n잠시 후 다시 시도해주세요."); + GetReward = 3; } } else { - Advertisement.Banner.Hide(); + if (rewardedReady) + { + Advertisement.Show(placement_Rewarded, this); + rewardedReady = false; + } + else + { + LobbyUI.Ins.m_ToastUI.Set("광고를 준비 중입니다.\n잠시 후 다시 시도해주세요."); + GetReward = 3; + } } } + // =========================================================== + // 배너 광고 제어 + // =========================================================== + // 외부에서 배너를 켜거나 끌 때 호출 + 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; + // 자동으로 보이게 하려면 아래 호출 + // Advertisement.Banner.Show(placement_Banner); + }, + errorCallback = (err) => + { + Debug.LogWarning("Banner Load Fail: " + err); + bannerLoaded = false; + // 필요시 재시도 로직 (예: 일정 시간 후 다시 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) + { + // 로드가 안 되어 있으면 우선 로드하고, 로드시 자동으로 보여주게 처리 + 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() { base.Update(); @@ -88,11 +174,11 @@ public class ADInfo : MonoBehaviourSingletonTemplate, Play_Game(); Action_success?.Invoke(); break; + case 2: case 3: GetReward = 0; Play_Game(); - LobbyUI.Ins.m_ToastUI.Set("준비된 광고가 없습니다.\n나중에 다시 시도해 주세요."); Action_fail?.Invoke(); break; } @@ -114,12 +200,19 @@ public class ADInfo : MonoBehaviourSingletonTemplate, // =========================================================== 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) { - Debug.LogError($"Unity Ads Init Failed: {error} - {message}"); + Debug.LogError($"❌ Unity Ads Init Failed: {error} - {message}"); } // =========================================================== @@ -128,13 +221,17 @@ public class ADInfo : MonoBehaviourSingletonTemplate, public void OnUnityAdsAdLoaded(string 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) { - Debug.LogError($"Failed to load Ad {placementId}: {error} - {message}"); - GetReward = 2; + Debug.LogError($"❌ Failed to load Ad {placementId}: {error} - {message}"); + if (placementId == placement_Interstitial) interstitialReady = false; + else if (placementId == placement_Rewarded) rewardedReady = false; } // =========================================================== @@ -146,12 +243,18 @@ public class ADInfo : MonoBehaviourSingletonTemplate, GetReward = 1; else GetReward = 2; + + // 광고 시청 후 즉시 다음 광고 미리 로드 + Advertisement.Load(placementId, this); } 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; + + // 실패했어도 다음 광고 미리 로드 시도 + Advertisement.Load(placementId, this); } public void OnUnityAdsShowStart(string placementId) { }