Skip to content

Commit 3183c1e

Browse files
author
Yury Pavlotsky
committed
Version 2.3.0 of the Google Mobile Ads Unity Plugin
1 parent 5462d4d commit 3183c1e

40 files changed

+787
-48
lines changed

unity/ChangeLog.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
Google Mobile Ads Unity Plugin Change Log
22

3+
*************
4+
Version 2.3.0
5+
*************
6+
- Add support for In-App Purchase house ads on Android.
7+
38
*************
49
Version 2.2.1
510
*************

unity/samples/HelloWorld/Assets/GoogleMobileAdsDemoScript.cs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,54 @@
33
using GoogleMobileAds;
44
using GoogleMobileAds.Api;
55

6+
public class GoogleMobileAdsDemoHandler : IInAppPurchaseHandler
7+
{
8+
private readonly string[] validSkus = { "android.test.purchased" };
9+
10+
//Will only be sent on a success.
11+
public void OnInAppPurchaseFinished(IInAppPurchaseResult result)
12+
{
13+
result.FinishPurchase();
14+
GoogleMobileAdsDemoScript.OutputMessage = "Purchase Succeeded! Credit user here.";
15+
}
16+
17+
//Check SKU against valid SKUs.
18+
public bool IsValidPurchase(string sku)
19+
{
20+
foreach(string validSku in validSkus) {
21+
if (sku == validSku) {
22+
return true;
23+
}
24+
}
25+
return false;
26+
}
27+
28+
//Return the app's public key.
29+
public string AndroidPublicKey
30+
{
31+
//In a real app, return public key instead of null.
32+
get { return null; }
33+
}
34+
}
35+
636
// Example script showing how to invoke the Google Mobile Ads Unity plugin.
737
public class GoogleMobileAdsDemoScript : MonoBehaviour
838
{
939

1040
private BannerView bannerView;
1141
private InterstitialAd interstitial;
42+
private static string outputMessage = "";
43+
44+
public static string OutputMessage
45+
{
46+
set { outputMessage = value; }
47+
}
1248

1349
void OnGUI()
1450
{
1551
// Puts some basic buttons onto the screen.
1652
GUI.skin.button.fontSize = (int) (0.05f * Screen.height);
53+
GUI.skin.label.fontSize = (int) (0.025f * Screen.height);
1754

1855
Rect requestBannerRect = new Rect(0.1f * Screen.width, 0.05f * Screen.height,
1956
0.8f * Screen.width, 0.1f * Screen.height);
@@ -63,6 +100,10 @@ void OnGUI()
63100
{
64101
interstitial.Destroy();
65102
}
103+
104+
Rect textOutputRect = new Rect(0.1f * Screen.width, 0.925f * Screen.height,
105+
0.8f * Screen.width, 0.05f * Screen.height);
106+
GUI.Label(textOutputRect, outputMessage);
66107
}
67108

68109
private void RequestBanner()
@@ -111,6 +152,8 @@ private void RequestInterstitial()
111152
interstitial.AdClosing += HandleInterstitialClosing;
112153
interstitial.AdClosed += HandleInterstitialClosed;
113154
interstitial.AdLeftApplication += HandleInterstitialLeftApplication;
155+
GoogleMobileAdsDemoHandler handler = new GoogleMobileAdsDemoHandler();
156+
interstitial.SetInAppPurchaseHandler(handler);
114157
// Load an interstitial ad.
115158
interstitial.LoadAd(createAdRequest());
116159
}

unity/source/.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.gradle
2+
/local.properties
3+
/.idea/workspace.xml
4+
/.idea/libraries
5+
.idea
6+
.DS_Store
7+
/build
8+
*.iml

unity/source/Assets/GoogleMobileAds/Api/AdRequest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace GoogleMobileAds.Api
66
{
77
public class AdRequest
88
{
9-
public const string Version = "2.2.1";
9+
public const string Version = "2.3.0";
1010
public const string TestDeviceSimulator = "SIMULATOR";
1111

1212
public class Builder
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
using GoogleMobileAds.Common;
3+
4+
namespace GoogleMobileAds.Api
5+
{
6+
public interface IInAppPurchaseHandler
7+
{
8+
void OnInAppPurchaseFinished(IInAppPurchaseResult result);
9+
bool IsValidPurchase(string sku);
10+
string AndroidPublicKey { get; }
11+
}
12+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System;
2+
3+
namespace GoogleMobileAds.Api
4+
{
5+
public interface IInAppPurchaseResult
6+
{
7+
void FinishPurchase();
8+
string ProductId { get; }
9+
}
10+
}

unity/source/Assets/GoogleMobileAds/Api/InterstitialAd.cs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33

44
namespace GoogleMobileAds.Api
55
{
6-
public class InterstitialAd : IAdListener
6+
public class InterstitialAd : IAdListener, IInAppPurchaseListener
77
{
88
private IGoogleMobileAdsInterstitialClient client;
9+
private IInAppPurchaseHandler handler;
910

1011
// These are the ad callback events that can be hooked into.
1112
public event EventHandler<EventArgs> AdLoaded = delegate {};
@@ -84,5 +85,30 @@ void IAdListener.FireAdLeftApplication()
8485
}
8586

8687
#endregion
88+
89+
#region IInAppPurchaseListener implementation
90+
91+
bool IInAppPurchaseListener.FireIsValidPurchase(string sku)
92+
{
93+
if (handler != null) {
94+
return handler.IsValidPurchase(sku);
95+
}
96+
return false;
97+
}
98+
99+
void IInAppPurchaseListener.FireOnInAppPurchaseFinished(IInAppPurchaseResult result)
100+
{
101+
if (handler != null) {
102+
handler.OnInAppPurchaseFinished(result);
103+
}
104+
}
105+
106+
public void SetInAppPurchaseHandler(IInAppPurchaseHandler handler)
107+
{
108+
this.handler = handler;
109+
client.SetInAppPurchaseParams(this, handler.AndroidPublicKey);
110+
}
111+
112+
#endregion
87113
}
88114
}

unity/source/Assets/GoogleMobileAds/Common/DummyClient.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,10 @@ public void ShowInterstitial() {
5151
public void DestroyInterstitial() {
5252
Debug.Log("Dummy DestroyInterstitial");
5353
}
54+
55+
public void SetInAppPurchaseParams(IInAppPurchaseListener listener, string androidPublicKey)
56+
{
57+
Debug.Log("Dummy SetInAppPurchaseParams");
58+
}
5459
}
5560
}

unity/source/Assets/GoogleMobileAds/Common/IGoogleMobileAdsInterstitialClient.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,8 @@ internal interface IGoogleMobileAdsInterstitialClient {
1616

1717
// Destroys an InterstitialAd to free up memory.
1818
void DestroyInterstitial();
19+
20+
// Sets in-app purchase params to use in-app purchase house ads.
21+
void SetInAppPurchaseParams(IInAppPurchaseListener listener, string androidPublicKey);
1922
}
2023
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
using GoogleMobileAds.Api;
3+
4+
namespace GoogleMobileAds.Common
5+
{
6+
// Interface for the methods to be invoked by the native plugin.
7+
internal interface IInAppPurchaseListener
8+
{
9+
void FireOnInAppPurchaseFinished(IInAppPurchaseResult result);
10+
bool FireIsValidPurchase(string sku);
11+
}
12+
}

0 commit comments

Comments
 (0)