Implementation

Maker sure you have Setup the Mediation Profile, before starting to use mediation API.

First of all you need to initalize it. Basicaly initalization will simply pick mediation profile, so there is no initialization callback, just call Init method on your game start.

AdMediation.Instance.Init ();

Interstitial

You need to load Interstitial before you can load this. As soon the intersitisal is loaded you will get OnVideoLoadComplete callback. After Interstisial is loaded you can show it anytime you want.

The sample bellow will show how to load interstitial and show it as soon as it's loaded.

AdMediation.Instance.OnVideoLoadComplete += HandleOnVideoLoadComplete;
AdMediation.Instance.LoadInterstitial();

private void HandleOnInterstitialLoadComplete (M_InterstitialLoadResult res) {
	Debug.Log("Ad Mediation Example: Interstitial Loaded: " + res.AdProviderNetwork + " " + res.IsSucceeded);
	if(res.IsSucceeded) {
		AdMediation.Instance.ShowInterstitial();
	} else {
		Debug.Log("Interstitial Loading failed");
	}
}

You can also findout if interstisial ready to be displayed using IsInterstitialReady property

void FixedUpdate() {
	if(AdMediation.Instance.IsInterstitialReady) {
		AdMediation.Instance.ShowInterstitial();
	}
}

There OnInterstitialFinished callback will be fired when interstisial is finished. So if you paused your game after ShowInterstitial method call, you can use OnInterstitialFinished callback to unpause it.

AdMediation.Instance.OnInterstitialFinished += HandleOnInterstitialFinished;
AdMediation.Instance.ShowInterstitial();

private void HandleOnInterstitialFinished (M_InterstitialFinishResult res) {
	Debug.Log("Ad Mediation Example: Interstitial Finished: " + res.AdProviderNetwork + " " + res.IsSucceeded);
}

Video Ad

Loading and displaying video ad is pretty much the same as for interstitial.

AdMediation.Instance.OnVideoLoadComplete += HandleOnVideoLoadComplete;
AdMediation.Instance.LoadVideo();

private void HandleOnVideoLoadComplete (M_VideoLoadResult res) {
	Debug.Log("Ad Mediation Example: Video Loaded: " + res.AdProviderNetwork + " " + res.IsSucceeded);
	if(res.IsSucceeded) {
		AdMediation.Instance.ShowVideo();
	}else {
		Debug.Log("Video Loading failed");
	}
}

The IsVideoReady property can be used as alternatie to the OnVideoLoadComplete callback

void FixedUpdate() {
	if(AdMediation.Instance.IsVideoReady) {
		AdMediation.Instance.ShowVideo();
	}
}

Some video Ad netroks allow user to skip Video before it will be finished. So analytzing the M_VideoFinishResult witch is comes with the OnVideoFinished will let you know if you should reward your user for watching the video ad.

AdMediation.Instance.OnVideoFinished += HandleOnVideoFinished;
AdMediation.Instance.LoadVideo();

private void HandleOnVideoFinished (M_VideoFinishResult res) {
	Debug.Log("Ad Mediation Example: Video Finished: " + res.AdProviderNetwork + " " + res.IsSucceeded);
	if(res.IsSucceeded) {
		//Reward user for watching
	}
}

Testing in Editor

Ad Mediation allows you to test your implementation in editor, in fact if Editor testing is enabled Ad Meadion SDK will show the Test Ad UI, simulating the behavior on a real device. You can enable or disable the Editor Testing feature with the plugin settings, and also set the Ad fill rate for testing.

In case Editor Testing will be disable calls to AdMediation API inside the Unity Editor will be simply ignored.

 

More use examples can be found under the UnifiedAdsTestScene Scene.