modify scripts
This commit is contained in:
@ -22,10 +22,11 @@ namespace WordsToolkit.Scripts.Services.Ads.AdUnits
|
||||
public Action<string> OnShown { get; set; }
|
||||
public Action<string> OnInitialized { get; set; }
|
||||
|
||||
public AdUnit(string placementId, AdReference adReference)
|
||||
public AdUnit(string placementId, AdReference adReference, AdsHandlerBase adsHandler)
|
||||
{
|
||||
PlacementId = placementId;
|
||||
AdReference = adReference;
|
||||
AdsHandler = adsHandler;
|
||||
}
|
||||
|
||||
public AdsHandlerBase AdsHandler { get; set; }
|
||||
|
||||
@ -10,8 +10,14 @@
|
||||
// // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// // THE SOFTWARE.
|
||||
|
||||
#if IRONSOURCE
|
||||
using Unity.Services.LevelPlay;
|
||||
#endif
|
||||
using UnityEngine;
|
||||
using WordsToolkit.Scripts.Services.Ads.AdUnits;
|
||||
#if UMP_AVAILABLE
|
||||
using GoogleMobileAds.Ump.Api;
|
||||
#endif
|
||||
|
||||
namespace WordsToolkit.Scripts.Services.Ads.Networks
|
||||
{
|
||||
@ -19,14 +25,42 @@ namespace WordsToolkit.Scripts.Services.Ads.Networks
|
||||
public class IronsourceAdsHandler : AdsHandlerBase
|
||||
{
|
||||
private IAdsListener _listener;
|
||||
#if IRONSOURCE
|
||||
private LevelPlayInterstitialAd _interstitialAd;
|
||||
private LevelPlayRewardedAd _rewardedAd;
|
||||
#endif
|
||||
|
||||
private void Init(string _id)
|
||||
{
|
||||
#if IRONSOURCE
|
||||
IronSource.Agent.setManualLoadRewardedVideo(true);
|
||||
IronSource.Agent.validateIntegration();
|
||||
IronSource.Agent.init(_id);
|
||||
LevelPlay.ValidateIntegration();
|
||||
|
||||
// Set consent for LevelPlay
|
||||
SetConsentStatus();
|
||||
|
||||
// Register initialization events
|
||||
LevelPlay.OnInitSuccess += SdkInitializationCompletedEvent;
|
||||
LevelPlay.OnInitFailed += SdkInitializationFailedEvent;
|
||||
|
||||
LevelPlay.Init(_id);
|
||||
#endif
|
||||
}
|
||||
|
||||
private void SetConsentStatus()
|
||||
{
|
||||
#if IRONSOURCE && UMP_AVAILABLE
|
||||
bool hasConsent = ConsentInformation.CanRequestAds();
|
||||
Debug.Log($"LevelPlay consent status: {hasConsent}");
|
||||
|
||||
// Set consent for GDPR
|
||||
LevelPlay.SetConsent(hasConsent);
|
||||
|
||||
// For CCPA compliance (optional)
|
||||
LevelPlay.SetMetaData("do_not_sell", hasConsent ? "false" : "true");
|
||||
#elif IRONSOURCE
|
||||
// Default to no consent if UMP not available
|
||||
LevelPlay.SetConsent(false);
|
||||
Debug.Log("UMP not available - setting LevelPlay consent to false");
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -34,78 +68,121 @@ namespace WordsToolkit.Scripts.Services.Ads.Networks
|
||||
{
|
||||
_listener = listener;
|
||||
Debug.Log(_listener);
|
||||
#if IRONSOURCE
|
||||
//Add Rewarded Video Events
|
||||
IronSourceInterstitialEvents.onAdReadyEvent += OnInterstitialAdReady;
|
||||
IronSourceInterstitialEvents.onAdLoadFailedEvent += InterstitialAdLoadFailedEvent;
|
||||
|
||||
IronSourceRewardedVideoEvents.onAdReadyEvent += OnRewardedVideoAdReady;
|
||||
IronSourceRewardedVideoEvents.onAdLoadFailedEvent += RewardedVideoAdShowFailedEvent;
|
||||
IronSourceRewardedVideoEvents.onAdRewardedEvent += Rewardeded;
|
||||
|
||||
IronSourceEvents.onSdkInitializationCompletedEvent += SdkInitializationCompletedEvent;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if IRONSOURCE
|
||||
private void Rewardeded(IronSourcePlacement obj, IronSourceAdInfo ironSourceAdInfo)
|
||||
private void SdkInitializationCompletedEvent(LevelPlayConfiguration config)
|
||||
{
|
||||
Debug.Log("Ironsource Rewardeded");
|
||||
_listener?.OnAdsShowComplete();
|
||||
}
|
||||
|
||||
private void SdkInitializationCompletedEvent()
|
||||
{
|
||||
Debug.Log("Ironsource SdkInitializationCompletedEvent");
|
||||
Debug.Log("LevelPlay SdkInitializationCompletedEvent");
|
||||
_listener?.OnAdsInitialized();
|
||||
}
|
||||
|
||||
private void InterstitialAdLoadFailedEvent(IronSourceError obj)
|
||||
private void SdkInitializationFailedEvent(LevelPlayInitError error)
|
||||
{
|
||||
Debug.Log("Ironsource InterstitialAdLoadFailedEvent " + obj.getCode() + " " + obj.getDescription());
|
||||
Debug.Log($"LevelPlay SdkInitializationFailedEvent: {error}");
|
||||
_listener?.OnInitFailed();
|
||||
}
|
||||
|
||||
// Interstitial event handlers
|
||||
private void InterstitialAdLoadedEvent(LevelPlayAdInfo adInfo)
|
||||
{
|
||||
Debug.Log("LevelPlay OnInterstitialAdReady");
|
||||
_listener?.OnAdsLoaded(adInfo.AdUnitId);
|
||||
}
|
||||
|
||||
private void InterstitialAdLoadFailedEvent(LevelPlayAdError error)
|
||||
{
|
||||
Debug.Log($"LevelPlay InterstitialAdLoadFailedEvent: {error}");
|
||||
_listener?.OnAdsLoadFailed();
|
||||
}
|
||||
|
||||
private void RewardedVideoAdShowFailedEvent(IronSourceError obj)
|
||||
private void InterstitialAdDisplayFailedEvent(LevelPlayAdInfo levelPlayAdInfo, LevelPlayAdError levelPlayAdError)
|
||||
{
|
||||
Debug.Log("1" + obj.getCode());
|
||||
Debug.Log("2" + obj.getDescription());
|
||||
Debug.Log("Ironsource RewardedVideoAdShowFailedEvent " + obj.getCode() + " " + obj.getDescription());
|
||||
Debug.Log(_listener);
|
||||
Debug.Log($"LevelPlay InterstitialAdDisplayFailedEvent: {levelPlayAdError}");
|
||||
_listener?.OnAdsShowFailed();
|
||||
LevelPlay.SetPauseGame(false);
|
||||
}
|
||||
|
||||
private void OnRewardedVideoAdReady(IronSourceAdInfo obj)
|
||||
#if LEVELPLAY8
|
||||
private void InterstitialAdDisplayFailedEvent(LevelPlayAdDisplayInfoError obj)
|
||||
{
|
||||
Debug.Log("Ironsource OnRewardedVideoAdReady");
|
||||
_listener?.OnAdsLoaded(obj.instanceId);
|
||||
}
|
||||
|
||||
private void OnInterstitialAdReady(IronSourceAdInfo obj)
|
||||
{
|
||||
Debug.Log("Ironsource OnInterstitialAdReady");
|
||||
_listener?.OnAdsLoaded(obj.instanceId);
|
||||
Debug.Log($"LevelPlay InterstitialAdDisplayFailedEvent: {obj}");
|
||||
_listener?.OnAdsShowFailed();
|
||||
LevelPlay.SetPauseGame(false);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
// Rewarded video event handlers
|
||||
private void RewardedAdLoadedEvent(LevelPlayAdInfo adInfo)
|
||||
{
|
||||
Debug.Log("LevelPlay OnRewardedVideoAdReady");
|
||||
_listener?.OnAdsLoaded(adInfo.AdUnitId);
|
||||
}
|
||||
|
||||
private void RewardedAdLoadFailedEvent(LevelPlayAdError error)
|
||||
{
|
||||
Debug.Log($"LevelPlay RewardedVideoAdLoadFailedEvent: {error}");
|
||||
_listener?.OnAdsLoadFailed();
|
||||
}
|
||||
|
||||
private void RewardedAdDisplayFailedEvent(LevelPlayAdInfo levelPlayAdInfo, LevelPlayAdError levelPlayAdError)
|
||||
{
|
||||
Debug.Log($"LevelPlay RewardedVideoAdShowFailedEvent: {levelPlayAdError}");
|
||||
_listener?.OnAdsShowFailed();
|
||||
LevelPlay.SetPauseGame(false);
|
||||
}
|
||||
|
||||
#if LEVELPLAY8
|
||||
private void RewardedAdDisplayFailedEvent(LevelPlayAdDisplayInfoError obj)
|
||||
{
|
||||
Debug.Log($"LevelPlay RewardedAdDisplayFailedEvent: {obj}");
|
||||
_listener?.OnAdsShowFailed();
|
||||
LevelPlay.SetPauseGame(false);
|
||||
}
|
||||
#endif
|
||||
|
||||
private void RewardedAdRewardedEvent(LevelPlayAdInfo adInfo, LevelPlayReward reward)
|
||||
{
|
||||
Debug.Log("LevelPlay Rewarded");
|
||||
_listener?.OnAdsShowComplete();
|
||||
LevelPlay.SetPauseGame(false);
|
||||
}
|
||||
private void InterstitialDisplayedEvent(LevelPlayAdInfo obj)
|
||||
{
|
||||
Debug.Log("LevelPlay InterstitialDisplayedEvent");
|
||||
_listener?.OnAdsShowStart();
|
||||
LevelPlay.SetPauseGame(false);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
public override void Init(string _id, bool adSettingTestMode, IAdsListener listener)
|
||||
{
|
||||
Debug.Log("Ironsource Init");
|
||||
Debug.Log("LevelPlay Init");
|
||||
Init(_id);
|
||||
Debug.Log("Ironsource SetListener");
|
||||
Debug.Log("LevelPlay SetListener");
|
||||
SetListener(listener);
|
||||
}
|
||||
|
||||
public override void Show(AdUnit adUnit)
|
||||
{
|
||||
#if IRONSOURCE
|
||||
if (adUnit.AdReference.adType == EAdType.Interstitial)
|
||||
if (adUnit.AdReference.adType == EAdType.Interstitial && _interstitialAd != null)
|
||||
{
|
||||
IronSource.Agent.showInterstitial();
|
||||
if (_interstitialAd.IsAdReady())
|
||||
{
|
||||
_interstitialAd.ShowAd();
|
||||
LevelPlay.SetPauseGame(true);
|
||||
}
|
||||
}
|
||||
else if (adUnit.AdReference.adType == EAdType.Rewarded)
|
||||
else if (adUnit.AdReference.adType == EAdType.Rewarded && _rewardedAd != null)
|
||||
{
|
||||
IronSource.Agent.showRewardedVideo();
|
||||
if (_rewardedAd.IsAdReady())
|
||||
{
|
||||
_rewardedAd.ShowAd();
|
||||
LevelPlay.SetPauseGame(true);
|
||||
}
|
||||
}
|
||||
|
||||
_listener?.Show(adUnit);
|
||||
@ -117,26 +194,43 @@ namespace WordsToolkit.Scripts.Services.Ads.Networks
|
||||
#if IRONSOURCE
|
||||
if (adUnit.AdReference.adType == EAdType.Interstitial)
|
||||
{
|
||||
IronSource.Agent.loadInterstitial();
|
||||
_interstitialAd = new LevelPlayInterstitialAd(adUnit.PlacementId);
|
||||
|
||||
_interstitialAd.OnAdLoaded += InterstitialAdLoadedEvent;
|
||||
_interstitialAd.OnAdDisplayed += InterstitialDisplayedEvent;
|
||||
_interstitialAd.OnAdLoadFailed += InterstitialAdLoadFailedEvent;
|
||||
_interstitialAd.OnAdDisplayFailed += InterstitialAdDisplayFailedEvent;
|
||||
|
||||
_interstitialAd.LoadAd();
|
||||
}
|
||||
else if (adUnit.AdReference.adType == EAdType.Rewarded)
|
||||
{
|
||||
IronSource.Agent.loadRewardedVideo();
|
||||
_rewardedAd = new LevelPlayRewardedAd(adUnit.PlacementId);
|
||||
|
||||
_rewardedAd.OnAdLoaded += RewardedAdLoadedEvent;
|
||||
_rewardedAd.OnAdLoadFailed += RewardedAdLoadFailedEvent;
|
||||
_rewardedAd.OnAdDisplayFailed += RewardedAdDisplayFailedEvent;
|
||||
_rewardedAd.OnAdRewarded += RewardedAdRewardedEvent;
|
||||
|
||||
_rewardedAd.LoadAd();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public override bool IsAvailable(AdUnit adUnit)
|
||||
{
|
||||
#if IRONSOURCE
|
||||
if (adUnit.AdReference.adType == EAdType.Interstitial)
|
||||
{
|
||||
return IronSource.Agent.isInterstitialReady();
|
||||
return _interstitialAd != null && _interstitialAd.IsAdReady();
|
||||
}
|
||||
|
||||
if (adUnit.AdReference.adType == EAdType.Rewarded)
|
||||
{
|
||||
return IronSource.Agent.isRewardedVideoAvailable();
|
||||
return _rewardedAd != null && _rewardedAd.IsAdReady();
|
||||
}
|
||||
#endif
|
||||
return false;
|
||||
|
||||
@ -10,6 +10,9 @@
|
||||
// // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// // THE SOFTWARE.
|
||||
|
||||
#if IRONSOURCE
|
||||
using Unity.Services.LevelPlay;
|
||||
#endif
|
||||
using UnityEngine;
|
||||
using WordsToolkit.Scripts.Services.Ads.AdUnits;
|
||||
|
||||
@ -19,65 +22,100 @@ namespace WordsToolkit.Scripts.Services.Ads.Networks
|
||||
public class IronsourceBannerHandler : AdsHandlerBase
|
||||
{
|
||||
private IAdsListener _listener;
|
||||
#if IRONSOURCE
|
||||
private LevelPlayBannerAd _bannerAd;
|
||||
private LevelPlayBannerAd.Config.Builder configBuilder;
|
||||
#endif
|
||||
|
||||
private void Init(string _id)
|
||||
{
|
||||
#if IRONSOURCE
|
||||
IronSource.Agent.validateIntegration();
|
||||
IronSource.Agent.init(_id);
|
||||
LevelPlay.ValidateIntegration();
|
||||
LevelPlay.Init(_id);
|
||||
#endif
|
||||
}
|
||||
|
||||
private void SetListener(IAdsListener listener)
|
||||
{
|
||||
_listener = listener;
|
||||
#if IRONSOURCE
|
||||
IronSourceBannerEvents.onAdLoadedEvent += BannerAdLoadedEvent;
|
||||
IronSourceBannerEvents.onAdLoadFailedEvent += BannerAdLoadFailedEvent;
|
||||
IronSourceBannerEvents.onAdClickedEvent += BannerAdClickedEvent;
|
||||
IronSourceBannerEvents.onAdScreenPresentedEvent += BannerAdScreenPresentedEvent;
|
||||
IronSourceBannerEvents.onAdScreenDismissedEvent += BannerAdScreenDismissedEvent;
|
||||
IronSourceBannerEvents.onAdLeftApplicationEvent += BannerAdLeftApplicationEvent;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if IRONSOURCE
|
||||
private void BannerAdLoadedEvent(IronSourceAdInfo adInfo)
|
||||
private void BannerAdLoadedEvent(LevelPlayAdInfo adInfo)
|
||||
{
|
||||
Debug.Log("IronSource Banner ad loaded");
|
||||
_listener?.OnAdsLoaded(adInfo.instanceId);
|
||||
Debug.Log("LevelPlay Banner ad loaded");
|
||||
_listener?.OnAdsLoaded(adInfo.AdUnitId);
|
||||
}
|
||||
|
||||
private void BannerAdLoadFailedEvent(IronSourceError error)
|
||||
private void BannerAdLoadFailedEvent(LevelPlayAdError error)
|
||||
{
|
||||
Debug.Log($"IronSource Banner ad load failed. Error: {error.getCode()} - {error.getDescription()}");
|
||||
Debug.Log($"LevelPlay Banner ad load failed. Error: {error}");
|
||||
_listener?.OnAdsLoadFailed();
|
||||
}
|
||||
|
||||
private void BannerAdClickedEvent(IronSourceAdInfo adInfo)
|
||||
private void BannerAdClickedEvent(LevelPlayAdInfo adInfo)
|
||||
{
|
||||
Debug.Log("IronSource Banner ad clicked");
|
||||
Debug.Log("LevelPlay Banner ad clicked");
|
||||
}
|
||||
|
||||
private void BannerAdScreenPresentedEvent(IronSourceAdInfo adInfo)
|
||||
private void BannerAdDisplayedEvent(LevelPlayAdInfo adInfo)
|
||||
{
|
||||
Debug.Log("IronSource Banner ad screen presented");
|
||||
Debug.Log("LevelPlay Banner ad displayed");
|
||||
}
|
||||
|
||||
private void BannerAdScreenDismissedEvent(IronSourceAdInfo adInfo)
|
||||
private void BannerAdDisplayFailedEvent(LevelPlayAdInfo levelPlayAdInfo, LevelPlayAdError levelPlayAdError)
|
||||
{
|
||||
Debug.Log("IronSource Banner ad screen dismissed");
|
||||
Debug.Log($"LevelPlay Banner ad display failed. Error: {levelPlayAdError}");
|
||||
}
|
||||
|
||||
private void BannerAdLeftApplicationEvent(IronSourceAdInfo adInfo)
|
||||
#if LEVELPLAY8
|
||||
private void BannerAdDisplayFailedEvent(LevelPlayAdDisplayInfoError error)
|
||||
{
|
||||
Debug.Log("IronSource Banner ad caused app to leave");
|
||||
Debug.Log($"LevelPlay Banner ad display failed. Error: {error}");
|
||||
}
|
||||
#endif
|
||||
|
||||
private void BannerAdLeftApplicationEvent(LevelPlayAdInfo adInfo)
|
||||
{
|
||||
Debug.Log("LevelPlay Banner ad caused app to leave");
|
||||
}
|
||||
|
||||
private LevelPlayBannerAd GetBannerAd(AdUnit adUnit)
|
||||
{
|
||||
configBuilder ??= new LevelPlayBannerAd.Config.Builder();
|
||||
#if LEVELPLAY9
|
||||
configBuilder.SetSize(LevelPlayAdSize.BANNER);
|
||||
#elif LEVELPLAY8
|
||||
configBuilder.SetSize(com.unity3d.mediation.LevelPlayAdSize.BANNER);
|
||||
#endif
|
||||
#if LEVELPLAY9
|
||||
configBuilder.SetPosition(LevelPlayBannerPosition.BottomCenter);
|
||||
#elif LEVELPLAY8
|
||||
configBuilder.SetPosition(com.unity3d.mediation.LevelPlayBannerPosition.BottomCenter);
|
||||
#endif
|
||||
configBuilder.SetDisplayOnLoad(true);
|
||||
#if UNITY_ANDROID
|
||||
configBuilder.SetRespectSafeArea(true); // Only relevant for Android
|
||||
#endif
|
||||
configBuilder.SetPlacementName("bannerPlacement");
|
||||
configBuilder.SetBidFloor(1.0); // Minimum bid price in USD
|
||||
var bannerConfig = configBuilder.Build();
|
||||
var bannerAd = new LevelPlayBannerAd(adUnit.PlacementId, bannerConfig);
|
||||
|
||||
bannerAd.OnAdLoaded += BannerAdLoadedEvent;
|
||||
bannerAd.OnAdLoadFailed += BannerAdLoadFailedEvent;
|
||||
bannerAd.OnAdClicked += BannerAdClickedEvent;
|
||||
bannerAd.OnAdDisplayed += BannerAdDisplayedEvent;
|
||||
bannerAd.OnAdDisplayFailed += BannerAdDisplayFailedEvent;
|
||||
bannerAd.OnAdLeftApplication += BannerAdLeftApplicationEvent;
|
||||
|
||||
return bannerAd;
|
||||
}
|
||||
#endif
|
||||
|
||||
public override void Init(string _id, bool adSettingTestMode, IAdsListener listener)
|
||||
{
|
||||
Debug.Log("IronSource Banner Init");
|
||||
Debug.Log("LevelPlay Banner Init");
|
||||
Init(_id);
|
||||
SetListener(listener);
|
||||
}
|
||||
@ -85,22 +123,23 @@ namespace WordsToolkit.Scripts.Services.Ads.Networks
|
||||
public override void Show(AdUnit adUnit)
|
||||
{
|
||||
#if IRONSOURCE
|
||||
if (adUnit.AdReference.adType == EAdType.Banner)
|
||||
if (_bannerAd == null)
|
||||
{
|
||||
IronSource.Agent.displayBanner();
|
||||
_bannerAd = GetBannerAd(adUnit);
|
||||
}
|
||||
if (adUnit.AdReference.adType == EAdType.Banner && _bannerAd != null)
|
||||
{
|
||||
_bannerAd.ShowAd();
|
||||
_listener?.Show(adUnit);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
public override void Load(AdUnit adUnit)
|
||||
{
|
||||
#if IRONSOURCE
|
||||
if (adUnit.AdReference.adType == EAdType.Banner)
|
||||
{
|
||||
IronSourceBannerSize bannerSize = IronSourceBannerSize.BANNER;
|
||||
IronSource.Agent.loadBanner(bannerSize, IronSourceBannerPosition.BOTTOM);
|
||||
}
|
||||
_bannerAd.LoadAd();
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -114,9 +153,9 @@ namespace WordsToolkit.Scripts.Services.Ads.Networks
|
||||
public override void Hide(AdUnit adUnit)
|
||||
{
|
||||
#if IRONSOURCE
|
||||
if (adUnit.AdReference.adType == EAdType.Banner)
|
||||
if (adUnit.AdReference.adType == EAdType.Banner && _bannerAd != null)
|
||||
{
|
||||
IronSource.Agent.hideBanner();
|
||||
_bannerAd.HideAd();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 655355652c9a644febf26cd1a5869bf4
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,33 @@
|
||||
{
|
||||
"name": "CandySmith.LevelPlay",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:00dd4a7ac8c24c898083910c81898ecc",
|
||||
"GUID:760a4c7888534400e882b82c5b3fba06"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [
|
||||
{
|
||||
"name": "com.unity.services.levelplay",
|
||||
"expression": "[0.0,9.0)",
|
||||
"define": "LEVELPLAY8"
|
||||
},
|
||||
{
|
||||
"name": "com.unity.services.levelplay",
|
||||
"expression": "9.0.0",
|
||||
"define": "LEVELPLAY9"
|
||||
},
|
||||
{
|
||||
"name": "com.unity.services.levelplay",
|
||||
"expression": "",
|
||||
"define": "IRONSOURCE"
|
||||
}
|
||||
],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 537e7a60660d24526a2d6a89f5f68492
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -12,7 +12,9 @@
|
||||
|
||||
using UnityEngine;
|
||||
using WordsToolkit.Scripts.Services.Ads.AdUnits;
|
||||
|
||||
#if UMP_AVAILABLE
|
||||
using GoogleMobileAds.Ump.Api;
|
||||
#endif
|
||||
namespace WordsToolkit.Scripts.Services.Ads.Networks
|
||||
{
|
||||
#if UNITY_ADS
|
||||
@ -28,10 +30,33 @@ namespace WordsToolkit.Scripts.Services.Ads.Networks
|
||||
|
||||
public override void Init(string _id, bool adSettingTestMode, IAdsListener listener)
|
||||
{
|
||||
SetConsentStatus();
|
||||
Advertisement.Initialize(_id, adSettingTestMode, this);
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
private void SetConsentStatus()
|
||||
{
|
||||
#if UNITY_ADS && UMP_AVAILABLE
|
||||
bool hasConsent = ConsentInformation.CanRequestAds();
|
||||
Debug.Log($"Unity Ads consent status: {hasConsent}");
|
||||
|
||||
var consentMetaData = new MetaData("gdpr");
|
||||
consentMetaData.Set("consent", hasConsent);
|
||||
Advertisement.SetMetaData(consentMetaData);
|
||||
|
||||
var privacyMetaData = new MetaData("privacy");
|
||||
privacyMetaData.Set("mode", "mixed");
|
||||
Advertisement.SetMetaData(privacyMetaData);
|
||||
#elif UNITY_ADS
|
||||
// Default to no consent if UMP not available
|
||||
var consentMetaData = new MetaData("gdpr");
|
||||
consentMetaData.Set("consent", false);
|
||||
Advertisement.SetMetaData(consentMetaData);
|
||||
Debug.Log("UMP not available - setting Unity Ads consent to false");
|
||||
#endif
|
||||
}
|
||||
|
||||
public override void Show(AdUnit adUnit)
|
||||
{
|
||||
Advertisement.Show(adUnit.PlacementId, this);
|
||||
|
||||
Reference in New Issue
Block a user