Yandex Mobile Ads
Loading...
Searching...
No Matches
InterstitialAdLoader.cs
Go to the documentation of this file.
1/*
2 * This file is a part of the Yandex Advertising Network
3 *
4 * Version for Unity (C) 2023 YANDEX
5 *
6 * You may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at https://legal.yandex.com/partner_ch/
8 */
9
10using System;
12using YandexMobileAds.Common;
13using YandexMobileAds.Platforms;
14
15namespace YandexMobileAds
16{
21 {
25 public event EventHandler<InterstitialAdLoadedEventArgs> OnAdLoaded;
26
30 public event EventHandler<AdFailedToLoadEventArgs> OnAdFailedToLoad;
31
32 private readonly AdRequestConfigurationFactory _adRequestConfigurationFactory;
33 private readonly IInterstitialAdLoaderClient _client;
34
39 {
40 this._adRequestConfigurationFactory = new AdRequestConfigurationFactory();
41 this._client = YandexMobileAdsClientFactory.BuildInterstitialAdLoaderClient();
42
43 MainThreadDispatcher.initialize();
44 ConfigureInterstitialEvents();
45 }
46
52 public void LoadAd(AdRequestConfiguration configuration)
53 {
54 _client.LoadAd(_adRequestConfigurationFactory.CreateAdRequestConfiguration(configuration));
55 }
56
60 public void CancelLoading()
61 {
62 this._client.CancelLoading();
63 }
64
65 private void ConfigureInterstitialEvents()
66 {
67 this._client.OnAdLoaded += (sender, args) =>
68 {
69 if (this.OnAdLoaded == null)
70 {
71 return;
72 }
73
74 MainThreadDispatcher.EnqueueAction(() =>
75 {
76 if (this.OnAdLoaded == null)
77 {
78 return;
79 }
80
81 InterstitialAdLoadedEventArgs adLoadedEventArgs = new InterstitialAdLoadedEventArgs()
82 {
83 Interstitial = new Interstitial(args.Value)
84 };
85 this.OnAdLoaded(this, adLoadedEventArgs);
86 });
87 };
88
89 this._client.OnAdFailedToLoad += (sender, args) =>
90 {
91 if (this.OnAdLoaded == null)
92 {
93 return;
94 }
95
96 MainThreadDispatcher.EnqueueAction(() =>
97 {
98 if (this.OnAdLoaded == null)
99 {
100 return;
101 }
102
103 this.OnAdFailedToLoad(this, args);
104 });
105 };
106 }
107 }
108}
A class with data for a targeted ad request.
EventHandler< AdFailedToLoadEventArgs > OnAdFailedToLoad
Notifies that a rewarded ad request failed.
EventHandler< InterstitialAdLoadedEventArgs > OnAdLoaded
Notifies that ad is loaded.
InterstitialAdLoader()
Cunstructs an object of the InterstitialAdLoader class.
void CancelLoading()
Cancel active loading of the rewarded ads.
void LoadAd(AdRequestConfiguration configuration)
Starts loading the ad by AdRequestConfiguration. A successfuly loaded Interstitial will be delivered ...
Full-screen interstitial ad.