From e490f2d6b0541f77dae1efaf93971de9d5d14bbf Mon Sep 17 00:00:00 2001 From: Eric Leichtenschlag Date: Thu, 8 May 2014 16:47:42 -0700 Subject: [PATCH] Update README with API updates --- unity/README.md | 49 +++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 45 insertions(+), 4 deletions(-) diff --git a/unity/README.md b/unity/README.md index c4ece75f1..047a6efc4 100644 --- a/unity/README.md +++ b/unity/README.md @@ -8,13 +8,12 @@ applications. Plugin features include: * A single package with cross platform (Android/iOS) support * Mock ad calls when running inside Unity editor * Support for Banner Ads +* Support for Interstitial Ads * Custom banner sizes * Banner ad events listeners * AdRequest targeting methods * A sample project to demonstrate plugin integration -Interstitial support coming soon. - The plugin contains a .unitypackage file for those that want to easily import the plugin, as well as the source code for those that want to iterate on it. @@ -109,6 +108,27 @@ Here is the minimal code needed to create a banner. The _AdPosition_ enum specifies where to place the banner. +Basic Interstitial Flow +----------------------- +Here is the minimal banner code to create an interstitial. + + using GoogleMobileAds.Api; + ... + // Initialize an InterstitialAd. + InterstitialAd interstitial = new InterstitialAd("MY_AD_UNIT_ID"); + // Create an empty ad request. + AdRequest request = new AdRequest.Builder().Build(); + // Load the interstitial with the request. + interstitial.LoadAd(request); + +Unlike banners, interstitials need to be explicitly shown. At an appropriate +stopping point in your app, check that the interstitail is ready before +showing it: + + if (interstitial.isLoaded()) { + interstitial.Show(); + } + Custom Ad Sizes --------------- In addition to constants on _AdSize_, you can also create a custom size: @@ -161,7 +181,10 @@ also want to get test ads on the simulator. Here is how to set up the request: Ad Events --------- -_BannerView_ contains ad events that you can register for: +Both _BannerView_ and _InterstitialAd_ contain the same ad events that you can +register for. These events are of type +[EventHandler](http://msdn.microsoft.com/en-us/library/db0etb8x%28v=vs.110%29.aspx). +Here we'll demonstrate setting ad events on a banner: using GoogleMobileAds.Api; ... @@ -182,12 +205,21 @@ _BannerView_ contains ad events that you can register for: bannerView.AdLeftApplication += HandleAdLeftApplication; ... - public void HandleAdLoaded() + public void HandleAdLoaded(object sender, EventArgs args) { print("HandleAdLoaded event received."); // Handle the ad loaded event. } +The only event with special event args is _AdFailedToLoad_. It passes an +instance of _AdFailedToLoadEventArgs_ with a _Message_ describing the error. + + public void HandleAdFailedToLoad(object sender, AdFailedToLoadEventArgs args) + { + print("Interstitial Failed to load: " + args.Message); + // Handle the ad failed to load event. + }; + You only need to register for the events you care about. Banner Lifecycle @@ -208,6 +240,15 @@ your reference to it: This lets the plugin know you no longer need the object, and can do any necessary cleanup on your behalf. +Interstitial Lifecycle +---------------------- +Similar to banners, interstitials also have a destroy method: + + interstitial.Destroy(); + +It is important to explicitly destroy the interstitial before letting it go +out of scope so that it can be properly released by the plugin. + Additional Resources ==================== * [Developer documentation](https://developers.google.com/mobile-ads-sdk/docs)