2using System.Diagnostics;
4using Unity.Services.LevelPlay;
17 public abstract partial class LevelPlayAdUnit<TAd>
22 public DateTime?
LoadTime {
get;
protected set; }
24 private long? loadingStartTimestamp;
54 private void SetLoadingTime()
57 ? (long)((Stopwatch.GetTimestamp() - startTimestamp) * 1000d / Stopwatch.Frequency)
59 loadingStartTimestamp =
null;
72 protected virtual void OnAdLoaded(LevelPlayAdInfo levelPlayAdInfo)
88 Logger.LogError(
LogOptions.AdLoadFailedText, error.ErrorMessage, error.ErrorCode, error.AdUnitId);
89 base.OnAdLoadFailed(error);
96 protected virtual void OnAdClicked(LevelPlayAdInfo levelPlayAdInfo)
106 protected virtual void OnAdShown(LevelPlayAdInfo levelPlayAdInfo)
116 protected virtual void OnAdClosed(LevelPlayAdInfo levelPlayAdInfo)
127 protected virtual void OnAdContentFailed(LevelPlayAdInfo levelPlayAdInfo, LevelPlayAdError error)
129 Logger.LogError(
LogOptions.AdContentFailedLogText, error.ErrorMessage, error.ErrorCode, error.AdUnitId);
130 base.OnAdContentFailed(error);
142 base.OnUserEarnedReward(reward);
151 var synchronizationContext = unitySynchronizationContext;
152 if (synchronizationContext ==
null)
155 if (ReferenceEquals(synchronizationContext, SynchronizationContext.Current))
157 ProcessImpressionData(impressionData);
161 synchronizationContext.Post(_ =>
164 ProcessImpressionData(impressionData);
172 private void ProcessImpressionData(LevelPlayImpressionData impressionData)
174 base.OnAdPaid(impressionData);
175 base.OnAdImpressionRecorded();
Concrete adapter that wraps an SDK-specific reward object and exposes it through the SDK-agnostic AdR...
virtual LogOptions LogOptions
virtual void OnAdLoadFailed(LevelPlayAdError error)
Handles the ad load failure event, logging the failure reason, the code, the ad unit ID,...
virtual void OnAdClosed(LevelPlayAdInfo levelPlayAdInfo)
Handles the ad closed event, logging that the ad was closed by the user.
virtual void OnAdImpressionDataReady(LevelPlayImpressionData impressionData)
Handles impression-level revenue data on the Unity main thread.
void SetLoadingStartTime()
Saves the start time of an ad-loading request.
LevelPlayAdInfo ResponseInfo
Contains detailed information about a LevelPlay advertisement, including its dimensions,...
virtual void OnAdShown(LevelPlayAdInfo levelPlayAdInfo)
Handles the event when an ad is shown to the user, logging the occurrence.
DateTime? LoadTime
Date and time when the ad was loaded.
virtual void OnUserEarnedReward(LevelPlayAdInfo levelPlayAdInfo, AdReward reward)
Handles the user earned reward event, logging the type and amount of the reward earned through intera...
virtual void OnAdInfoChanged(LevelPlayAdInfo levelPlayAdInfo)
Handles changes to the ad information by updating the ResponseInfo property.
void ResetLoadingStartTime()
Clears the saved start time when an ad-loading request cannot be started.
virtual void OnAdContentFailed(LevelPlayAdInfo levelPlayAdInfo, LevelPlayAdError error)
Handles the ad content failed event, logging the error encountered while displaying the ad content.
virtual void OnAdClicked(LevelPlayAdInfo levelPlayAdInfo)
Handles the ad click event, logging that the ad was clicked by the user.
virtual void OnAdLoaded(LevelPlayAdInfo levelPlayAdInfo)
Handles the ad loaded event, setting the load time and logging the event.
long? LoadingTimeMs
Gets the duration of the latest successful ad-loading request in milliseconds. Divide the value by 10...