구글 애드몹 미디에이션 -> 유니티 광고

This commit is contained in:
Ino 2025-11-07 09:01:16 +09:00
parent 92041f76df
commit 6cfaecf0f7
9 changed files with 108 additions and 210 deletions

View File

@ -11,6 +11,7 @@ dependencies {
implementation 'com.google.android.ump:user-messaging-platform:3.1.0' // Assets/GoogleMobileAds/Editor/GoogleUmpDependencies.xml:7 implementation 'com.google.android.ump:user-messaging-platform:3.1.0' // Assets/GoogleMobileAds/Editor/GoogleUmpDependencies.xml:7
implementation 'com.onestorecorp.sdk:sdk-iap:21.02.01' // Assets/OneStoreCorpPlugins/Purchase/Editor/PurchaseDependencies.xml:6 implementation 'com.onestorecorp.sdk:sdk-iap:21.02.01' // Assets/OneStoreCorpPlugins/Purchase/Editor/PurchaseDependencies.xml:6
implementation 'com.onestorecorp.sdk:sdk-licensing:2.2.1' // Assets/OneStoreCorpPlugins/AppLicenseChecker/Editor/AppLicenseCheckerDependencies.xml:6 implementation 'com.onestorecorp.sdk:sdk-licensing:2.2.1' // Assets/OneStoreCorpPlugins/AppLicenseChecker/Editor/AppLicenseCheckerDependencies.xml:6
// implementation 'com.unity3d.ads:unity-ads:[4.16.3,4.17[' // Packages/com.unity.ads/Editor/Source/Dependencies.xml:7
implementation 'com.unity3d.ads:unity-ads:4.12.3' // Assets/GoogleMobileAds/Mediation/UnityAds/Editor/UnityMediationDependencies.xml:33 implementation 'com.unity3d.ads:unity-ads:4.12.3' // Assets/GoogleMobileAds/Mediation/UnityAds/Editor/UnityMediationDependencies.xml:33
// Android Resolver Dependencies End // Android Resolver Dependencies End
**DEPS**} **DEPS**}

View File

@ -22,7 +22,7 @@ dependencyResolutionManagement {
url "https://repo.onestore.net/repository/onestore-sdk-public" // Assets/OneStoreCorpPlugins/AppLicenseChecker/Editor/AppLicenseCheckerDependencies.xml:5, Assets/OneStoreCorpPlugins/Purchase/Editor/PurchaseDependencies.xml:5 url "https://repo.onestore.net/repository/onestore-sdk-public" // Assets/OneStoreCorpPlugins/AppLicenseChecker/Editor/AppLicenseCheckerDependencies.xml:5, Assets/OneStoreCorpPlugins/Purchase/Editor/PurchaseDependencies.xml:5
} }
maven { maven {
url "https://maven.google.com/" // Assets/GoogleMobileAds/Editor/GoogleMobileAdsDependencies.xml:7, Assets/GoogleMobileAds/Editor/GoogleMobileAdsDependencies.xml:12, Assets/GoogleMobileAds/Editor/GoogleUmpDependencies.xml:7 url "https://maven.google.com/" // Assets/GoogleMobileAds/Editor/GoogleMobileAdsDependencies.xml:7, Assets/GoogleMobileAds/Editor/GoogleMobileAdsDependencies.xml:12, Assets/GoogleMobileAds/Editor/GoogleUmpDependencies.xml:7, Packages/com.unity.ads/Editor/Source/Dependencies.xml:7
} }
maven { maven {
url "https://repo.maven.apache.org/maven2/" // Assets/GoogleMobileAds/Mediation/UnityAds/Editor/UnityMediationDependencies.xml:25, Assets/GoogleMobileAds/Mediation/UnityAds/Editor/UnityMediationDependencies.xml:33 url "https://repo.maven.apache.org/maven2/" // Assets/GoogleMobileAds/Mediation/UnityAds/Editor/UnityMediationDependencies.xml:25, Assets/GoogleMobileAds/Mediation/UnityAds/Editor/UnityMediationDependencies.xml:33

View File

@ -1 +1 @@
8 9

View File

@ -1,205 +1,80 @@
using GoogleMobileAds.Api;
using System; using System;
using UnityEngine; using UnityEngine;
using UnityEngine.Advertisements;
public class ADInfo : MonoBehaviourSingletonTemplate<ADInfo> public class ADInfo : MonoBehaviourSingletonTemplate<ADInfo>,
IUnityAdsInitializationListener, IUnityAdsLoadListener, IUnityAdsShowListener
{ {
//[RuntimeInitializeOnLoadMethod] #if UNITY_ANDROID
//static void OnRuntimeMethodLoad() { new GameObject("ADInfo").AddComponent<ADInfo>(); } string gameId = "5947579";
#elif UNITY_IOS
string gameId = "5947578";
#endif
//public static ADInfo Ins; bool testMode = false;
private RewardedInterstitialAd short_rewardedInterstitialAd; string placement_Interstitial = "Interstitial_Android";
string rewardedInterstitialAd_ID = "ca-app-pub-6390804219581974/3468554834"; string placement_Rewarded = "Rewarded_Android";
//string rewardedInterstitialAd_ID = "ca-app-pub-3940256099942544/1033173712"; // 테스트 string placement_Banner = "Banner_Android";
private InterstitialAd m_interstitialAd;
string InterstitialAd_ID = "ca-app-pub-2550554896492831/9309815439";
//string InterstitialAd_ID = "ca-app-pub-3940256099942544/1033173712"; // 테스트
private RewardedAd long_rewardedAd;
string longAD = "ca-app-pub-2550554896492831/2536577422";
//string longAD = "ca-app-pub-3940256099942544/5224354917"; // 테스트
BannerView _bannerView;
string bannerAD = "ca-app-pub-2550554896492831/2225586237";
//string bannerAD = "ca-app-pub-3940256099942544/6300978111"; // 테스트
byte GetReward = 0; byte GetReward = 0;
Action Action_success, Action_fail; Action Action_success, Action_fail;
bool isLoading_InterstitialAd, isLoading_RewardedAd; float curVolume;
//private void Awake() void Start()
//{
// Ins = this;
// DontDestroyOnLoad(gameObject);
//}
public void Start()
{ {
MobileAds.Initialize(initStatus => Advertisement.Initialize(gameId, testMode, this);
{
//Load_RewardedInterstitialAd(rewardedInterstitialAd_ID, Set_RewardedInterstitialAd);
Load_InterstitialAd(InterstitialAd_ID, Set_InterstitialAd);
Load_LongAD(longAD, Set_LongAD);
AdSize adaptiveSize = AdSize.GetPortraitAnchoredAdaptiveBannerAdSizeWithWidth(AdSize.FullWidth);
_bannerView = new BannerView(bannerAD, adaptiveSize, AdPosition.Bottom);
});
}
void Set_RewardedInterstitialAd(RewardedInterstitialAd ad)
{
if (short_rewardedInterstitialAd != null)
{
short_rewardedInterstitialAd.Destroy();
short_rewardedInterstitialAd = null;
}
short_rewardedInterstitialAd = ad;
}
void Set_InterstitialAd(InterstitialAd ad)
{
if (m_interstitialAd != null)
{
m_interstitialAd.Destroy();
m_interstitialAd = null;
}
m_interstitialAd = ad;
m_interstitialAd.OnAdFullScreenContentClosed += () =>
{
GetReward = 1;
Load_InterstitialAd(InterstitialAd_ID, Set_InterstitialAd);
};
m_interstitialAd.OnAdFullScreenContentFailed += (AdError adError) =>
{
Load_InterstitialAd(InterstitialAd_ID, Set_InterstitialAd);
};
}
void Set_LongAD(RewardedAd ad)
{
if (long_rewardedAd != null)
{
long_rewardedAd.Destroy();
long_rewardedAd = null;
}
long_rewardedAd = ad;
}
void Load_RewardedInterstitialAd(string s_ad, Action<RewardedInterstitialAd> adaction)
{
// create our request used to load the ad.
var adRequest = new AdRequest();
// send the request to load the ad.
RewardedInterstitialAd.Load(s_ad, adRequest,
(RewardedInterstitialAd ad, LoadAdError error) =>
{
// if error is not null, the load request failed.
if (error != null || ad == null)
{
Debug.LogError("Rewarded ad failed to load an ad " +
"with error : " + error);
return;
}
adaction(ad);
});
}
void Load_InterstitialAd(string s_ad, Action<InterstitialAd> adaction)
{
if (isLoading_InterstitialAd) return;
isLoading_InterstitialAd = true;
// create our request used to load the ad.
var adRequest = new AdRequest();
// send the request to load the ad.
InterstitialAd.Load(s_ad, adRequest,
(InterstitialAd ad, LoadAdError error) =>
{
isLoading_InterstitialAd = false;
// if error is not null, the load request failed.
if (error != null || ad == null)
{
Debug.LogError("Rewarded ad failed to load an ad " +
"with error : " + error);
return;
}
adaction(ad);
});
}
void Load_LongAD(string s_ad, Action<RewardedAd> adaction)
{
if (isLoading_RewardedAd) return;
isLoading_RewardedAd = true;
// create our request used to load the ad.
var adRequest = new AdRequest();
// send the request to load the ad.
RewardedAd.Load(s_ad, adRequest,
(RewardedAd ad, LoadAdError error) =>
{
isLoading_RewardedAd = false;
// if error is not null, the load request failed.
if (error != null || ad == null)
{
Debug.LogError("Rewarded ad failed to load an ad " +
"with error : " + error);
return;
}
adaction(ad);
});
} }
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();
Action_success = _success; Action_success = _success;
Action_fail = _fail; Action_fail = _fail;
GetReward = 0; GetReward = 0;
if (bshort) if (bshort)
{ {
if (SaveMgr.Ins.Get_ShopNoAD()) // 리워드형 광고가 아니면 제거 if (SaveMgr.Ins.Get_ShopNoAD())
{ {
GetReward = 1; GetReward = 1;
return; return;
} }
if (m_interstitialAd != null && m_interstitialAd.CanShowAd()) 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())
{ {
m_interstitialAd.Show(); Advertisement.Banner.Load(placement_Banner, new BannerLoadOptions
} {
else loadCallback = () =>
{ {
GetReward = 2; Debug.Log("Banner Load Success");
Load_InterstitialAd(InterstitialAd_ID, Set_InterstitialAd); Advertisement.Banner.SetPosition(BannerPosition.BOTTOM_CENTER);
Advertisement.Banner.Show(placement_Banner);
},
errorCallback = (err) =>
{
Debug.Log("Banner Load Fail: " + err);
}
});
} }
} }
else else
{ {
if (long_rewardedAd != null && long_rewardedAd.CanShowAd()) Advertisement.Banner.Hide();
{
long_rewardedAd.Show((Reward reward) =>
{
GetReward = 1;
Load_LongAD(longAD, Set_LongAD);
});
}
else
{
GetReward = 2;
Load_LongAD(longAD, Set_LongAD);
}
} }
} }
@ -211,14 +86,9 @@ public class ADInfo : MonoBehaviourSingletonTemplate<ADInfo>
case 1: case 1:
GetReward = 0; GetReward = 0;
Play_Game(); Play_Game();
Action_success?.Invoke(); // 후 처리 및 저장 Action_success?.Invoke();
break; break;
case 2: case 2:
GetReward = 0;
Play_Game();
LobbyUI.Ins.m_ToastUI.Set("준비된 광고가 없습니다.\n나중에 다시 시도해 주세요.");
Action_fail?.Invoke();
break;
case 3: case 3:
GetReward = 0; GetReward = 0;
Play_Game(); Play_Game();
@ -228,34 +98,62 @@ public class ADInfo : MonoBehaviourSingletonTemplate<ADInfo>
} }
} }
float curVolume;
void Stop_Game() void Stop_Game()
{ {
//Time.timeScale = 0f;
curVolume = AudioListener.volume; curVolume = AudioListener.volume;
AudioListener.volume = 0f; AudioListener.volume = 0f;
} }
void Play_Game() void Play_Game()
{ {
//Time.timeScale = 1f;
AudioListener.volume = curVolume; AudioListener.volume = curVolume;
} }
public void Set_Banner(bool active) // ===========================================================
// IUnityAdsInitializationListener
// ===========================================================
public void OnInitializationComplete()
{ {
if (_bannerView == null) return; Debug.Log("Unity Ads Initialization Complete");
if (active)
{
//// 배너 광고 요청 및 표시
//var adRequest = new AdRequest();
//_bannerView.LoadAd(adRequest);
if (!SaveMgr.Ins.Get_ShopNoAD())
_bannerView.Show();
}
else
{
_bannerView.Hide();
}
} }
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);
Advertisement.Show(placementId, this);
}
public void OnUnityAdsFailedToLoad(string placementId, UnityAdsLoadError error, string message)
{
Debug.LogError($"Failed to load Ad {placementId}: {error} - {message}");
GetReward = 2;
}
// ===========================================================
// IUnityAdsShowListener
// ===========================================================
public void OnUnityAdsShowComplete(string placementId, UnityAdsShowCompletionState showCompletionState)
{
if (placementId == placement_Rewarded && showCompletionState == UnityAdsShowCompletionState.COMPLETED)
GetReward = 1;
else
GetReward = 2;
}
public void OnUnityAdsShowFailure(string placementId, UnityAdsShowError error, string message)
{
Debug.LogError($"Show failed {placementId}: {error} - {message}");
GetReward = 2;
}
public void OnUnityAdsShowStart(string placementId) { }
public void OnUnityAdsShowClick(string placementId) { }
} }

View File

@ -1,13 +0,0 @@
게등위 버전
게등위 이후 라이브 버전
- 게등위 테스트 제거
- 뽑기 연출 개선
-- 라이트 추가
-- 뽑기 상자 여러 개가 랜덤하게 나왔으면...
- 럭키 뽑기 게임 개선
-- 컵 안에 구슬 보이기
-- 컵을 기울였다 다시 세웠다 할 수 있게
-- 리필
- 파이어 베이스

View File

@ -1,6 +1,7 @@
{ {
"dependencies": { "dependencies": {
"com.unity.addressables": "2.7.3", "com.unity.addressables": "2.7.3",
"com.unity.ads": "4.16.3",
"com.unity.collab-proxy": "2.9.3", "com.unity.collab-proxy": "2.9.3",
"com.unity.feature.2d": "2.0.1", "com.unity.feature.2d": "2.0.1",
"com.unity.ide.rider": "3.0.38", "com.unity.ide.rider": "3.0.38",

View File

@ -108,6 +108,16 @@
}, },
"url": "https://packages.unity.com" "url": "https://packages.unity.com"
}, },
"com.unity.ads": {
"version": "4.16.3",
"depth": 0,
"source": "registry",
"dependencies": {
"com.unity.ugui": "1.0.0",
"com.unity.modules.androidjni": "1.0.0"
},
"url": "https://packages.unity.com"
},
"com.unity.bindings.openimageio": { "com.unity.bindings.openimageio": {
"version": "1.0.0", "version": "1.0.0",
"depth": 1, "depth": 1,

View File

@ -6,6 +6,7 @@
<package>com.google.android.ump:user-messaging-platform:3.1.0</package> <package>com.google.android.ump:user-messaging-platform:3.1.0</package>
<package>com.onestorecorp.sdk:sdk-iap:21.02.01</package> <package>com.onestorecorp.sdk:sdk-iap:21.02.01</package>
<package>com.onestorecorp.sdk:sdk-licensing:2.2.1</package> <package>com.onestorecorp.sdk:sdk-licensing:2.2.1</package>
<package>com.unity3d.ads:unity-ads:[4.16.3,4.17[</package>
<package>com.unity3d.ads:unity-ads:4.12.3</package> <package>com.unity3d.ads:unity-ads:4.12.3</package>
</packages> </packages>
<files /> <files />

View File

@ -173,7 +173,7 @@ PlayerSettings:
iPhone: 0 iPhone: 0
tvOS: 0 tvOS: 0
overrideDefaultApplicationIdentifier: 1 overrideDefaultApplicationIdentifier: 1
AndroidBundleVersionCode: 8 AndroidBundleVersionCode: 9
AndroidMinSdkVersion: 24 AndroidMinSdkVersion: 24
AndroidTargetSdkVersion: 35 AndroidTargetSdkVersion: 35
AndroidPreferredInstallLocation: 1 AndroidPreferredInstallLocation: 1