The MobileAds
class provides global settings for the Google Mobile Ads SDK.
Raise ad events on the Unity main thread
The Google Mobile Ads SDK raises events on a different thread than the Unity main thread. If you implement ad events and interact with Unity objects, you must synchronize the Mobile Ads SDK events with the Unity main thread.
If you would like the Mobile Ads SDK to handle this threading concern for you,
set MobileAds.RaiseAdEventsOnUnityMainThread
to true
. This forces the
SDK to raise all events and callbacks on the Unity main thread.
...
using GoogleMobileAds.Api;
...
public class GoogleMobileAdsDemoScript : MonoBehaviour
{
public void Start()
{
// When true all events raised by GoogleMobileAds will be raised
// on the Unity main thread. The default value is false.
MobileAds.RaiseAdEventsOnUnityMainThread = true;
}
}
Video ad volume control
If your app has its own volume controls, such as custom music or sound effect volumes, disclosing app volume to the Google Mobile Ads SDK enables video ads to respect app volume settings. This ensures users receive video ads with the expected audio volume.
The device volume, controlled through volume buttons or OS-level volume slider, determines the volume for device audio output. However, apps can independently adjust volume levels relative to the device volume to tailor the audio experience.
You can report the relative app volume to the Google Mobile Ads SDK by calling
the SetApplicationVolume()
method. Valid ad volume values range from 0.0
(silent) to 1.0
(current device volume). Here's an example of how to report
the relative app volume to the SDK:
// Set app volume to be half of current device volume.
MobileAds.SetApplicationVolume(0.5f);
To inform the SDK that the app volume has been muted, use the
SetApplicationMuted()
method:
// Set app to be muted.
MobileAds.SetApplicationMuted(true);
By default, the app volume is set to 1
, the current device volume, and the
app is not muted.
Consent for cookies
If your app has special requirements, you can set the optional
ApplicationPreferences
key gad_has_consent_for_cookies
to zero to enable
limited ads (LTD):
// Enable limited ads (LTD)
ApplicationPreferences.SetInt("gad_has_consent_for_cookies", 0);