private void PrepareAndRequestRewardedAd(int id) { var rewarded = new RewardedAd(frameworkValues.TestAds ? RewardedVideoIDTest : frameworkValues.RewardedVideoID); rewarded.OnAdFailedToLoad += (sender, arg) => { MobileAdsEventExecutor.ExecuteInUpdate(() => { this.Log("[ADMOB] RewardedAd failed to load with message: " + arg.Message, LogLevel.FrameworkErrorInfo); CoroutineHelper.InvokeWithDelay(frameworkValues.TimeAfterAdFailedToLoad, () => PrepareAndRequestRewardedAd(id)); }); }; rewarded.OnUserEarnedReward += HandleRewaredAdUserEarnedReward; rewarded.OnAdClosed += (sender, arg) => { MobileAdsEventExecutor.ExecuteInUpdate(() => { PrepareAndRequestRewardedAd(id); }); }; var request = BuildAdRequest(); rewarded.LoadAd(request); rewardedAds[id] = rewarded; }
public void onCustomClick(AndroidJavaObject ad, string assetName) { CustomNativeTemplateAd nativeAd = new CustomNativeTemplateAd( new CustomNativeTemplateClient(ad)); MobileAdsEventExecutor.executeInUpdate(() => this.CustomNativeTemplateCallbacks[nativeAd.GetCustomTemplateId()](nativeAd, assetName)); }
private void HandleInterstitialFailedToLoad(object sender, AdFailedToLoadEventArgs args) { MobileAdsEventExecutor.ExecuteInUpdate(() => { this.Log("[ADMOB] Interstitial failed to load with message: " + args.Message, LogLevel.FrameworkErrorInfo); CoroutineHelper.InvokeWithDelay(frameworkValues.TimeAfterAdFailedToLoad, RequestInterstitial); }); }
public void HandleRewardedAdClosed(object sender, EventArgs args) { Debug.Log("HandleRewardedAdClosed event received"); MobileAdsEventExecutor.ExecuteInUpdate(() => { RewardAd_CallBack.Invoke(ADS_CALLBACK_STATE.FAIL); RequestAndLoadRewardedAd(); }); }
public void HandleRewardedAdFailedToShow(object sender, AdErrorEventArgs args) { Debug.Log( "HandleRewardedAdFailedToShow event received with message: " + args.Message); MobileAdsEventExecutor.ExecuteInUpdate(() => { RewardAd_CallBack.Invoke(ADS_CALLBACK_STATE.FAIL); }); }
public static void Initialize(Action <InitializationStatus> initCompleteAction) { client.Initialize((initStatusClient) => { if (initCompleteAction != null) { initCompleteAction.Invoke(new InitializationStatus(initStatusClient)); } }); MobileAdsEventExecutor.Initialize(); }
private static void NativeCustomTemplateDidReceiveClickCallback( IntPtr nativeCustomAd, string assetName) { CustomNativeTemplateClient client = IntPtrToAdLoaderClient(nativeCustomAd); if (client.clickHandler != null) { CustomNativeTemplateAd nativeAd = new CustomNativeTemplateAd(client); MobileAdsEventExecutor.executeInUpdate(() => client.clickHandler(nativeAd, assetName)); } }
public void HandleOnAdClosed_InterstitialAd(object sender, EventArgs args) { MobileAdsEventExecutor.ExecuteInUpdate(() => { Debug.Log("HandleOnAdClosed_InterstitialAd event received"); InterstitialAd_CallBack.Invoke(ADS_CALLBACK_STATE.SUCCESS); Debug.Log("end call back"); RequestAndLoadInterstitialAd(); Debug.Log("end request"); }); }
private void HandleInitCompleteAction(InitializationStatus initstatus) { // Callbacks from GoogleMobileAds are not guaranteed to be called on // main thread. // In this example we use MobileAdsEventExecutor to schedule these calls on // the next Update() loop. MobileAdsEventExecutor.ExecuteInUpdate(() => { statusText.text = "Initialization complete"; RequestBannerAd(); }); }
private void HandleInitCompleteAction(InitializationStatus initstatus) { // Callbacks from GoogleMobileAds are not guaranteed to be called on // main thread. // In this example we use MobileAdsEventExecutor to schedule these calls on // the next Update() loop. MobileAdsEventExecutor.ExecuteInUpdate(() => { Debug.Log("Initialization complete"); adsInitiated = true; }); }
public void RequestAndLoadRewardedInterstitialAd() { statusText.text = "Requesting Rewarded Interstitial Ad."; // These ad units are configured to always serve test ads. #if UNITY_EDITOR string adUnitId = "unused"; #elif UNITY_ANDROID string adUnitId = "ca-app-pub-3940256099942544/5354046379"; #elif UNITY_IPHONE string adUnitId = "ca-app-pub-3940256099942544/6978759866"; #else string adUnitId = "unexpected_platform"; #endif // Create an interstitial. RewardedInterstitialAd.LoadAd(adUnitId, CreateAdRequest(), (rewardedInterstitialAd, error) => { if (error != null) { MobileAdsEventExecutor.ExecuteInUpdate(() => { statusText.text = "RewardedInterstitialAd load failed, error: " + error; }); return; } this.rewardedInterstitialAd = rewardedInterstitialAd; MobileAdsEventExecutor.ExecuteInUpdate(() => { statusText.text = "RewardedInterstitialAd loaded"; }); // Register for ad events. this.rewardedInterstitialAd.OnAdDidPresentFullScreenContent += (sender, args) => { MobileAdsEventExecutor.ExecuteInUpdate(() => { statusText.text = "Rewarded Interstitial presented."; }); }; this.rewardedInterstitialAd.OnAdDidDismissFullScreenContent += (sender, args) => { MobileAdsEventExecutor.ExecuteInUpdate(() => { statusText.text = "Rewarded Interstitial dismissed."; }); this.rewardedInterstitialAd = null; }; this.rewardedInterstitialAd.OnAdFailedToPresentFullScreenContent += (sender, args) => { MobileAdsEventExecutor.ExecuteInUpdate(() => { statusText.text = "Rewarded Interstitial failed to present."; }); this.rewardedInterstitialAd = null; }; }); }
// Creates an InterstitialAd. public InterstitialAd(string adUnitId) { Type googleMobileAdsClientFactory = Type.GetType( "GoogleMobileAds.GoogleMobileAdsClientFactory,Assembly-CSharp"); MethodInfo method = googleMobileAdsClientFactory.GetMethod( "BuildInterstitialClient", BindingFlags.Static | BindingFlags.Public); this.client = (IInterstitialClient)method.Invoke(null, null); client.CreateInterstitialAd(adUnitId); Utils.CheckInitialization(); this.client.OnAdLoaded += (sender, args) => { if (this.OnAdLoaded != null) { MobileAdsEventExecutor.executeInUpdate(() => this.OnAdLoaded(this, args)); } }; this.client.OnAdFailedToLoad += (sender, args) => { if (this.OnAdFailedToLoad != null) { MobileAdsEventExecutor.executeInUpdate(() => this.OnAdFailedToLoad(this, args)); } }; this.client.OnAdOpening += (sender, args) => { if (this.OnAdOpening != null) { MobileAdsEventExecutor.executeInUpdate(() => this.OnAdOpening(this, args)); } }; this.client.OnAdClosed += (sender, args) => { if (this.OnAdClosed != null) { MobileAdsEventExecutor.executeInUpdate(() => this.OnAdClosed(this, args)); } }; this.client.OnAdLeavingApplication += (sender, args) => { if (this.OnAdLeavingApplication != null) { MobileAdsEventExecutor.executeInUpdate(() => this.OnAdLeavingApplication(this, args)); } }; }
private void HandleInitCompleteAction(InitializationStatus initstatus) { // Callbacks from GoogleMobileAds are not guaranteed to be called on // main thread. // In this example we use MobileAdsEventExecutor to schedule these calls on // the next Update() loop. MobileAdsEventExecutor.ExecuteInUpdate(() => { Init_InterstitialAd(); InitLoadRewardedAd(); //Init_Banner(); //InitLoadNativeAd(); }); }
public void ShowRewardedInterstitialAd() { if (rewardedInterstitialAd != null) { rewardedInterstitialAd.Show((reward) => { MobileAdsEventExecutor.ExecuteInUpdate(() => { statusText.text = "User Rewarded: " + reward.Amount; }); }); } else { statusText.text = "Rewarded ad is not ready yet."; } }
public void HandleUserEarnedReward(object sender, Reward args) { MobileAdsEventExecutor.ExecuteInUpdate(() => { string type = args.Type; double amount = args.Amount; Debug.Log( "HandleRewardedAdRewarded event received for " + amount.ToString() + " " + type); FirebaseManager.instance.LogRewarded(); timeLastShowReward = Config.GetTimeStamp(); RewardAd_CallBack.Invoke(ADS_CALLBACK_STATE.SUCCESS); }); //RequestAndLoadRewardedAd(); }
void OnInit(InitializationStatus initstatus) { // Callbacks from GoogleMobileAds are not guaranteed to be called on // main thread. // In this example we use MobileAdsEventExecutor to schedule these calls on // the next Update() loop. MobileAdsEventExecutor.ExecuteInUpdate(() => { isInit = true; if (this.stateTxt != null) { this.stateTxt.text = "Initialize OK"; } LoadReawrdAD(); }); }
private void Start() { // if server Ad Units is enabled then use server units: if (serverAdUnitsEnabled) { idBanner = (string.IsNullOrEmpty(AdmobServerAdUnits.BannerId)) ? idBanner : AdmobServerAdUnits.BannerId; idInterstitial = (string.IsNullOrEmpty(AdmobServerAdUnits.InterstitialId)) ? idInterstitial : AdmobServerAdUnits.InterstitialId; idReward = (string.IsNullOrEmpty(AdmobServerAdUnits.RewardId)) ? idReward : AdmobServerAdUnits.RewardId; } #if UNITY_EDITOR //this block is just for debugging in the editor string color; if (AdmobServer.adUnitsLoaded) { color = "yellow"; Debug.Log(">><color=yellow>You're using <b>SERVER</b> ad units :</color>"); } else { color = "orange"; Debug.Log(">><color=orange>You're using default ad units :</color>"); } Debug.Log("<color=" + color + "><b>Banner : </b>" + idBanner + "</color>"); Debug.Log("<color=" + color + "><b>Interstitial : </b>" + idInterstitial + "</color>"); Debug.Log("<color=" + color + "><b>Reward : </b>" + idReward + "</color>"); #endif RequestConfiguration requestConfiguration = new RequestConfiguration.Builder() .SetTagForChildDirectedTreatment(TagForChildDirectedTreatment.Unspecified) .build(); MobileAds.SetRequestConfiguration(requestConfiguration); MobileAds.Initialize(initstatus => { MobileAdsEventExecutor.ExecuteInUpdate(() => { if (OnInitComplete != null) { OnInitComplete.Invoke(); } }); }); }
private void ConfigureBannerEvents() { this.client.OnAdLoaded += (sender, args) => { if (this.OnAdLoaded != null) { MobileAdsEventExecutor.executeInUpdate(() => this.OnAdLoaded(this, args)); } }; this.client.OnAdFailedToLoad += (sender, args) => { if (this.OnAdFailedToLoad != null) { MobileAdsEventExecutor.executeInUpdate(() => this.OnAdFailedToLoad(this, args)); } }; this.client.OnAdOpening += (sender, args) => { if (this.OnAdOpening != null) { MobileAdsEventExecutor.executeInUpdate(() => this.OnAdOpening(this, args)); } }; this.client.OnAdClosed += (sender, args) => { if (this.OnAdClosed != null) { MobileAdsEventExecutor.executeInUpdate(() => this.OnAdClosed(this, args)); } }; this.client.OnAdLeavingApplication += (sender, args) => { if (this.OnAdLeavingApplication != null) { MobileAdsEventExecutor.executeInUpdate(() => this.OnAdLeavingApplication(this, args)); } }; }
void OnInit(InitializationStatus initstatus) { // Callbacks from GoogleMobileAds are not guaranteed to be called on // main thread. // In this example we use MobileAdsEventExecutor to schedule these calls on // the next Update() loop. MobileAdsEventExecutor.ExecuteInUpdate(() => { //load banner AdRequest request = new AdRequest.Builder().Build(); _banner = new BannerView(Data.UnitId, AdSize.SmartBanner, Data.Position); _banner.OnAdLoaded += (sender, args) => { _loading = false; _loaded = true; _onLoaded(); }; _banner.OnAdFailedToLoad += (sender, e) => { // on failed, delay 2 secs before re-loading again. _loadTimer = new Timer(2f); }; _banner.LoadAd(request); }); }
private AdLoader(Builder builder) { this.AdUnitId = string.Copy(builder.AdUnitId); this.CustomNativeTemplateClickHandlers = new Dictionary <string, Action <CustomNativeTemplateAd, string> >( builder.CustomNativeTemplateClickHandlers); this.TemplateIds = new HashSet <string>(builder.TemplateIds); this.AdTypes = new HashSet <NativeAdType>(builder.AdTypes); Type googleMobileAdsClientFactory = Type.GetType( "GoogleMobileAds.GoogleMobileAdsClientFactory,Assembly-CSharp"); MethodInfo method = googleMobileAdsClientFactory.GetMethod( "BuildAdLoaderClient", BindingFlags.Static | BindingFlags.Public); this.adLoaderClient = (IAdLoaderClient)method.Invoke(null, new object[] { this }); Utils.CheckInitialization(); this.adLoaderClient.OnCustomNativeTemplateAdLoaded += delegate(object sender, CustomNativeEventArgs args) { if (this.OnCustomNativeTemplateAdLoaded != null) { MobileAdsEventExecutor.executeInUpdate(() => this.OnCustomNativeTemplateAdLoaded(this, args)); } }; this.adLoaderClient.OnAdFailedToLoad += delegate( object sender, AdFailedToLoadEventArgs args) { if (this.OnAdFailedToLoad != null) { MobileAdsEventExecutor.executeInUpdate(() => this.OnAdFailedToLoad(this, args)); } }; }
public static void Initialize(string appId) { Instance.client.Initialize(appId); MobileAdsEventExecutor.Initialize(); }
public static void Initialize(Action <InitializationStatus> initCompleteAction) { client.Initialize(initCompleteAction); MobileAdsEventExecutor.Initialize(); }
private void HandleRewaredAdUserEarnedReward(object sender, Reward args) { MobileAdsEventExecutor.ExecuteInUpdate(RewardPlayer); }