2using System.Collections;
3using System.Collections.Generic;
25 [Tooltip(
"Ad unit ID for Android.")]
26 private string androidId;
28 [Tooltip(
"Ad unit ID for iOS.")]
32 [Tooltip(
"Behavior options for displaying and showing ads.")]
36 [Tooltip(
"Options for enabling Unity SendMessage methods.")]
62 protected SpaceAdLogger
Logger {
get;
private set; }
96 private static readonly Dictionary<string, TAd> cachedAdUnits =
new();
98 private bool wasShown;
99 private bool wasAwakened;
108 Options ??= !Application.isEditor
109 ?
throw new UnityException($
"The {nameof(SpaceAdMobileBase)} script must be added to the first scene.")
115 var debug = Options.AdMode !=
AdMode.Development;
117 if (debug && RuntimePlatformGuard.IsRuntimePlatformSupported &&
118 string.IsNullOrEmpty(androidId) &&
string.IsNullOrEmpty(iOSId))
120 throw new UnityException(
"At least one ID is required, but both Android and iOS IDs are empty!");
130 if (!RuntimePlatformGuard.IsRuntimePlatformSupported)
return;
136 IEnumerator WaitForReady()
142 StartCoroutine(WaitForReady());
181 cachedAdUnits.Clear();
204 if (!RuntimePlatformGuard.EnsureSupported())
return false;
206 if (
Options.CacheAds && cachedAdUnits.ContainsKey(
GetId()))
212 cachedAdUnits.Remove(
GetId());
237 RuntimePlatformGuard.IsRuntimePlatformSupported &&
250 if (!RuntimePlatformGuard.EnsureSupported())
return;
301 private void EnsureScriptReady()
304 throw new InvalidOperationException(
"The script is not ready yet. Wait until Awake has completed before calling this method.");
306 if (SystemAdType ==
null)
307 throw new InvalidOperationException(
"The component is not initialized yet. Enable it before calling this method.");
323 protected internal string GetRealId() =>
324 RuntimePlatformGuard.GetAdUnitId(androidId, iOSId);
333 RuntimePlatformGuard.GetAdUnitId(
Options and behaviors that control how ads are handled, loaded, and displayed.
override bool Load()
Loads the ad.
bool SdkInitialized
Indicates if the necessary SDK has been properly initialized. This is critical for ensuring that ad o...
override void Unload()
Unloads the ad.
override void OnApplicationQuit()
string GetId()
Determines and returns the appropriate ad ID based on the current platform and ad mode....
override void OnAdLoadedInternal()
TAd AdObject
The ad object associated with this unit. This property allows for direct interaction with the specifi...
virtual bool ShouldUnloadOnLoad
Determines whether the ad object should be unloaded when loading a new ad instance....
override void OnDestroy()
override bool CanShowAd()
Verifies if the ad is ready to be shown.True if the ad can be shown, otherwise false.
virtual bool ShouldUnloadOnShow
Determines whether the ad object should be treated as unavailable after being shown....
virtual IInternetConnectionChecker InternetConnection
override void Show()
Shows the ad.
Type SystemAdType
Stores the type of the system ad, facilitating reflection and type-specific operations.
override AdBehaviour AdBehaviour
override MessageOptions MessageOptions
virtual AdvertisingOptions Options
string SystemAdTypeName
A convenient string representation of the system ad type, used primarily for logging and debugging pu...
SpaceAdLogger InitLogger()
Initializes and returns a logger.
bool TryPrepareLoad()
Performs shared loading preflight used by synchronous and asynchronous provider implementations....
virtual LogOptions LogOptions
virtual void OnInternetNotAvailable()
Raised when the Internet connection isn't available. Can be overridden to handle this scenario.
string TestAndroidId
Gets the Android test ad unit identifier for the active provider.
void ReleaseFullscreenAdAudio()
Releases the audio policy for the current fullscreen ad show.
string TestIOSId
Gets the iOS test ad unit identifier for the active provider.
void AcquireFullscreenAdAudioLease()
Replaces the current fullscreen audio lease with a new one.
void OnAttachToCache()
Method to be called when the object is attached to the cache. It needs to unsubscribe from events it ...
void OnLoadFromCache()
Method to be called when the object is loaded from the cache. It needs to subscribe to needed events.
virtual void UnityOnDestroy()
Unity OnDestroy.
virtual void OnUnload()
Called when an ad is unloaded. Can be overridden to perform clean-up or other logic when the ad is no...
virtual void UnityOnApplicationQuit()
Unity OnApplicationQuit.
virtual void UnityOnEnable()
Unity OnEnable.
virtual void UnityAwake()
Unity Awake.
void DestroyInternal()
Internal method for unloading an ad. Must be implemented to handle the specific unloading logic.
void ShowInternal()
Internal method for showing an ad. Must be implemented to handle the specific showing logic.
override void OnAdLoaded()
Raised when the AdObject is loaded.
Serves as a base handler for ad unit operations, abstracting common functionality for different types...
Defines general configuration options for ad display, testing, and SDK initialization.
Defines options for enabling message callbacks related to ad events. These options allow you to subsc...
static AdvertisingOptions Options
General configuration options for ad display, testing, and SDK initialization.
static IInternetConnectionChecker InternetConnection
Pluggable internet checker instance. Assign a custom implementation if needed; null assignments are i...
Base class of the main SpaceAd mobile advertising manager. It provides a framework for initializing a...
Contract for pluggable internet connectivity checkers. Implementations should return true when the ne...
AdMode
Enumerates options for ad testing types, affecting whether real or test ads are displayed.