1#if !LEGACY_YANDEX_MOBILE_ADS
3using System.Collections.Generic;
4using System.Threading.Tasks;
6using YandexMobileAds.Base;
21 public abstract partial class YandexAdUnit<TAd> : AdUnit<TAd>,
IAsyncAdUnit
38 [field: SerializeField]
39 [field: Tooltip(
"Loads this Yandex ad unit through the SDK async API when Load is called.")]
54 public override bool Load()
69 if (customAdUnit !=
null)
78 return loadingStarted;
85 if (customAdUnit !=
null)
94 return loadingStarted;
102 private async
void LoadDefaultAsync()
108 catch (AdLoadingException)
112 catch (Exception exception)
114 Debug.LogException(exception,
this);
152 return new AdRequest(
154 requestOptions?.CreateTargeting(),
155 requestOptions?.AdTheme ?? AdTheme.None,
156 requestOptions?.CreateParameters());
168 var replaceLogValues =
new Dictionary<string, Func<string>>
171 {
"{time}", () =>
LoadTime?.ToString(System.Globalization.CultureInfo.CurrentCulture) },
172 {
"{loadingTimeMs}", () =>
LoadingTimeMs?.ToString(System.Globalization.CultureInfo.InvariantCulture) ?? string.Empty },
173 {
"{loadTimeMs}", () =>
LoadingTimeMs?.ToString(System.Globalization.CultureInfo.InvariantCulture) ?? string.Empty },
174 {
"{name}", () => name }
176 return new SpaceAdLogger(
this, replaceLogValues,
LogOptions.Channel, !
LogOptions.SuppressAllLogs);
181using System.Collections.Generic;
183using YandexMobileAds.Base;
198 public abstract partial class YandexAdUnit<TAd> : AdUnit<TAd>
203 public AdInfo ResponseInfo {
get;
protected set; }
206 protected override bool SdkInitialized =>
true;
209 public override void Unload()
211 ResetLoadingStartTime();
217 protected override bool LoadInternal()
219 var customAdUnit = LoadCustomType();
220 if (customAdUnit !=
null)
223 AdObject = customAdUnit;
224 var customAdBuilder =
new AdRequest.Builder();
225 PrepareAdBuilder(customAdBuilder);
226 var customAdRequest = customAdBuilder.Build();
228 SetLoadingStartTime();
229 var loadingStarted = LoadInternal(customAdRequest);
231 ResetLoadingStartTime();
233 return loadingStarted;
237 var adBuilder =
new AdRequestConfiguration.Builder(GetId());
238 PrepareAdBuilder(adBuilder);
239 var adRequest = adBuilder.Build();
241 SetLoadingStartTime();
242 var loadingStarted = LoadInternal(adRequest);
244 ResetLoadingStartTime();
246 return loadingStarted;
254 protected abstract bool LoadInternal(AdRequestConfiguration adRequest);
262 protected virtual bool LoadInternal(AdRequest adRequest) =>
true;
270 protected virtual TAd LoadCustomType() =>
default;
278 protected virtual void PrepareAdBuilder(AdRequest.Builder adBuilder) { }
287 protected virtual void PrepareAdBuilder(AdRequestConfiguration.Builder adBuilder) { }
293 protected virtual void PrepareAdObject() { }
296 protected override SpaceAdLogger InitLogger()
298 var replaceLogValues =
new Dictionary<string, Func<string>>
300 {
"{ad}", () => SystemAdTypeName },
301 {
"{time}", () => LoadTime?.ToString(System.Globalization.CultureInfo.CurrentCulture) },
302 {
"{loadingTimeMs}", () => LoadingTimeMs?.ToString(System.Globalization.CultureInfo.InvariantCulture) ?? string.Empty },
303 {
"{loadTimeMs}", () => LoadingTimeMs?.ToString(System.Globalization.CultureInfo.InvariantCulture) ?? string.Empty },
304 {
"{name}", () => name }
306 return new SpaceAdLogger(
this, replaceLogValues, LogOptions.Channel, !LogOptions.SuppressAllLogs);
string GetId()
Determines and returns the appropriate ad ID based on the current platform and ad mode....
TAd AdObject
The ad object associated with this unit. This property allows for direct interaction with the specifi...
string SystemAdTypeName
A convenient string representation of the system ad type, used primarily for logging and debugging pu...
bool TryPrepareLoad()
Performs shared loading preflight used by synchronous and asynchronous provider implementations....
virtual LogOptions LogOptions
static YandexRequestOptions CurrentRequestOptions
Current Yandex request options used by Yandex ad units. The value is refreshed from the active scene ...
Represents a mobile ad manager component specifically designed for integration with Google AdMob serv...
AdInfo ResponseInfo
Holds essential information for advertisements, excluding banners and app open ads.
bool LoadAsyncByDefault
Controls whether the regular Load call uses the Yandex SDK async loading API.
virtual void PrepareAdObject()
Optional overridable method for setting up the AdObject. This can be used for initializing or customi...
long? LoadingTimeMs
Gets the duration of the latest successful ad-loading request in milliseconds. Divide the value by 10...
override bool SdkInitialized
override SpaceAdLogger InitLogger()
bool LoadInternal(AdRequest adRequest)
Loads an ad with a configured provider request. Derived classes implement the format-specific loader ...
async Task< bool > LoadAsync()
Loads the ad asynchronously. The returned task completes when loading succeeds or fails with the load...
override void Unload()
Unloads the ad.
AdInfo GetResponseInfo()
Retrieves detailed response information for the most recent ad request, providing insights into the a...
override bool Load()
Loads the ad.
virtual AdRequest CreateAdRequest()
Creates the request used by all Yandex ad formats. Request targeting and parameters are read from the...
virtual TAd LoadCustomType()
Creates a custom SDK ad object before loading. Banners use this to create their Banner instance befor...
void ResetLoadingStartTime()
Clears the saved start time when an ad-loading request cannot be started.
DateTime? LoadTime
Date and time when the ad was loaded.
Task< bool > LoadInternalAsync(AdRequest adRequest)
Loads an ad asynchronously with a configured provider request. Derived classes override this when the...
void SetLoadingStartTime()
Saves the start time of an ad-loading request.
override bool LoadInternal()
Defines asynchronous loading support for ad units.