Skip to content

Commit 27ea48f

Browse files
author
Ram Parameswaran
committed
Version 3.0.5 of the Google Mobile Ads Unity Plugin
1 parent 03cf24b commit 27ea48f

File tree

19 files changed

+289
-168
lines changed

19 files changed

+289
-168
lines changed

ChangeLog.txt

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

3+
*************
4+
Version 3.0.5
5+
*************
6+
- Remove use of JSONUtility.
7+
8+
Built and tested with:
9+
- Google Play services 9.2.0
10+
- Google Mobile Ads iOS SDK 7.8.1
11+
- Unity Jar Resolver 1.2
12+
313
*************
414
Version 3.0.4
515
*************

source/android-library/app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ android {
2424

2525
dependencies {
2626
compile fileTree(dir: 'libs', include: ['*.jar'])
27-
compile 'com.android.support:appcompat-v7:23.1.0'
28-
compile 'com.google.android.gms:play-services:8.3.0'
27+
compile 'com.android.support:appcompat-v7:23.4.0'
28+
compile 'com.google.android.gms:play-services:9.2.0'
2929
}
3030

3131
task clearJar(type: Delete) {

source/android-library/app/src/main/java/com/google/unity/ads/CustomNativeAd.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import android.graphics.drawable.BitmapDrawable;
2121
import android.graphics.drawable.Drawable;
2222

23+
import com.google.android.gms.ads.formats.NativeAd;
2324
import com.google.android.gms.ads.formats.NativeCustomTemplateAd;
2425

2526
import java.io.ByteArrayOutputStream;
@@ -93,8 +94,13 @@ public void run() {
9394
* @param key The name of the asset to be retrieved.
9495
*/
9596
public byte[] getImage(String key) {
96-
Drawable image = nativeAd.getImage(key).getDrawable();
97-
Bitmap bitmap = ((BitmapDrawable) image).getBitmap();
97+
NativeAd.Image imageAsset = nativeAd.getImage(key);
98+
if (imageAsset == null) {
99+
return new byte[0];
100+
}
101+
102+
Drawable imageDrawable = imageAsset.getDrawable();
103+
Bitmap bitmap = ((BitmapDrawable) imageDrawable).getBitmap();
98104
ByteArrayOutputStream stream = new ByteArrayOutputStream();
99105
bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
100106
return stream.toByteArray();
@@ -106,6 +112,11 @@ public byte[] getImage(String key) {
106112
* @param key The name of the asset to be retrieved.
107113
*/
108114
public String getText(String key) {
115+
CharSequence assetText = nativeAd.getText(key);
116+
if (assetText == null) {
117+
return "";
118+
}
119+
109120
return nativeAd.getText(key).toString();
110121
}
111122
}

source/plugin/Assets/GoogleMobileAds/Api/AdLoader.cs

Lines changed: 58 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414

1515
using System;
1616
using System.Collections.Generic;
17-
using UnityEngine;
17+
1818
using GoogleMobileAds.Common;
19+
using UnityEngine;
1920

2021
namespace GoogleMobileAds.Api
2122
{
@@ -26,43 +27,84 @@ public enum NativeAdType
2627

2728
public class AdLoader
2829
{
30+
private IAdLoaderClient adLoaderClient;
31+
32+
private AdLoader(Builder builder)
33+
{
34+
this.AdUnitId = string.Copy(builder.AdUnitId);
35+
this.CustomNativeTemplateClickHandlers =
36+
new Dictionary<string, Action<CustomNativeTemplateAd, string>>(
37+
builder.CustomNativeTemplateClickHandlers);
38+
this.TemplateIds = new HashSet<string>(builder.TemplateIds);
39+
this.AdTypes = new HashSet<NativeAdType>(builder.AdTypes);
40+
this.adLoaderClient = GoogleMobileAdsClientFactory.BuildAdLoaderClient(this);
41+
42+
this.adLoaderClient.OnCustomNativeTemplateAdLoaded +=
43+
delegate(object sender, CustomNativeEventArgs args)
44+
{
45+
this.OnCustomNativeTemplateAdLoaded(this, args);
46+
};
47+
this.adLoaderClient.OnAdFailedToLoad += delegate(
48+
object sender, AdFailedToLoadEventArgs args)
49+
{
50+
this.OnAdFailedToLoad(this, args);
51+
};
52+
}
53+
2954
public event EventHandler<AdFailedToLoadEventArgs> OnAdFailedToLoad;
30-
public event EventHandler<CustomNativeEventArgs> onCustomNativeTemplateAdLoaded;
3155

32-
private IAdLoaderClient adLoaderClient;
56+
public event EventHandler<CustomNativeEventArgs> OnCustomNativeTemplateAdLoaded;
57+
58+
public Dictionary<string, Action<CustomNativeTemplateAd, string>>
59+
CustomNativeTemplateClickHandlers
60+
{
61+
get; private set;
62+
}
3363

3464
public string AdUnitId { get; private set; }
65+
3566
public HashSet<NativeAdType> AdTypes { get; private set; }
67+
3668
public HashSet<string> TemplateIds { get; private set; }
37-
public Dictionary<string, Action<CustomNativeTemplateAd, string>>
38-
CustomNativeTemplateClickHandlers { get; private set; }
3969

40-
public class Builder
70+
public void LoadAd(AdRequest request)
4171
{
42-
internal string AdUnitId { get; private set; }
43-
internal HashSet<NativeAdType> AdTypes { get; private set; }
44-
internal HashSet<string> TemplateIds { get; private set; }
45-
internal Dictionary<string, Action<CustomNativeTemplateAd, string>>
46-
CustomNativeTemplateClickHandlers { get; private set; }
72+
this.adLoaderClient.LoadAd(request);
73+
}
4774

75+
public class Builder
76+
{
4877
public Builder(string adUnitId)
4978
{
5079
this.AdUnitId = adUnitId;
5180
this.AdTypes = new HashSet<NativeAdType>();
5281
this.TemplateIds = new HashSet<string>();
53-
this.CustomNativeTemplateClickHandlers = new Dictionary<string,
54-
Action<CustomNativeTemplateAd, string>>();
82+
this.CustomNativeTemplateClickHandlers =
83+
new Dictionary<string, Action<CustomNativeTemplateAd, string>>();
84+
}
85+
86+
internal string AdUnitId { get; private set; }
87+
88+
internal HashSet<NativeAdType> AdTypes { get; private set; }
89+
90+
internal HashSet<string> TemplateIds { get; private set; }
91+
92+
internal Dictionary<string, Action<CustomNativeTemplateAd, string>>
93+
CustomNativeTemplateClickHandlers
94+
{
95+
get; private set;
5596
}
5697

57-
public Builder forCustomNativeAd(string templateId)
98+
public Builder ForCustomNativeAd(string templateId)
5899
{
59100
this.TemplateIds.Add(templateId);
60101
this.AdTypes.Add(NativeAdType.CustomTemplate);
61102
return this;
62103
}
63104

64-
public Builder forCustomNativeAd(string templateId,
65-
Action<CustomNativeTemplateAd, string> callback)
105+
public Builder ForCustomNativeAd(
106+
string templateId,
107+
Action<CustomNativeTemplateAd, string> callback)
66108
{
67109
this.TemplateIds.Add(templateId);
68110
this.CustomNativeTemplateClickHandlers[templateId] = callback;
@@ -75,31 +117,5 @@ public AdLoader Build()
75117
return new AdLoader(this);
76118
}
77119
}
78-
79-
private AdLoader(Builder builder)
80-
{
81-
AdUnitId = String.Copy(builder.AdUnitId);
82-
CustomNativeTemplateClickHandlers = new Dictionary<string,
83-
Action<CustomNativeTemplateAd, string>>(builder.CustomNativeTemplateClickHandlers);
84-
TemplateIds = new HashSet<string>(builder.TemplateIds);
85-
AdTypes = new HashSet<NativeAdType>(builder.AdTypes);
86-
87-
adLoaderClient = GoogleMobileAdsClientFactory.BuildAdLoaderClient(this);
88-
89-
adLoaderClient.onCustomNativeTemplateAdLoaded +=
90-
delegate(object sender, CustomNativeEventArgs args) {
91-
onCustomNativeTemplateAdLoaded(this, args);
92-
};
93-
94-
adLoaderClient.OnAdFailedToLoad += delegate(object sender, AdFailedToLoadEventArgs args)
95-
{
96-
OnAdFailedToLoad(this, args);
97-
};
98-
}
99-
100-
public void LoadAd(AdRequest request)
101-
{
102-
adLoaderClient.LoadAd(request);
103-
}
104120
}
105121
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace GoogleMobileAds.Api
2020
{
2121
public class AdRequest
2222
{
23-
public const string Version = "3.0.4";
23+
public const string Version = "3.0.5";
2424
public const string TestDeviceSimulator = "SIMULATOR";
2525

2626
public class Builder

source/plugin/Assets/GoogleMobileAds/Api/CustomNativeTemplateAd.cs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414

1515
using System;
1616
using System.Collections.Generic;
17-
using UnityEngine;
1817

1918
using GoogleMobileAds.Common;
19+
using UnityEngine;
2020

2121
namespace GoogleMobileAds.Api
2222
{
@@ -31,32 +31,44 @@ internal CustomNativeTemplateAd(ICustomNativeTemplateClient client)
3131

3232
public List<string> GetAvailableAssetNames()
3333
{
34-
return client.GetAvailableAssetNames();
34+
return this.client.GetAvailableAssetNames();
3535
}
3636

3737
public string GetCustomTemplateId()
3838
{
39-
return client.GetTemplateId();
39+
return this.client.GetTemplateId();
4040
}
4141

42+
// Get image asset corresponding to the key parameter of custom native template ad as a
43+
// Texture2D. If the asset key does not map to an existing asset, a null object will be
44+
// returned.
4245
public Texture2D GetTexture2D(string key)
4346
{
44-
return Utils.GetTexture2DFromByteArray(client.GetImageByteArray(key));
47+
byte[] imageAssetAsByteArray = this.client.GetImageByteArray(key);
48+
if (imageAssetAsByteArray == null)
49+
{
50+
return null;
51+
}
52+
53+
return Utils.GetTexture2DFromByteArray(imageAssetAsByteArray);
4554
}
4655

56+
// Get text asset corresponding to the key parameter of custom native template ad as a
57+
// string. If the asset key does not map to an existing asset, a null object will be
58+
// returned.
4759
public string GetText(string key)
4860
{
49-
return client.GetText(key);
61+
return this.client.GetText(key);
5062
}
5163

5264
public void PerformClick(string assetName)
5365
{
54-
client.PerformClick(assetName);
66+
this.client.PerformClick(assetName);
5567
}
5668

5769
public void RecordImpression()
5870
{
59-
client.RecordImpression();
71+
this.client.RecordImpression();
6072
}
6173
}
6274
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414

1515
using System;
1616
using System.Reflection;
17-
using UnityEngine;
1817

1918
using GoogleMobileAds.Api;
19+
using UnityEngine;
2020

2121
namespace GoogleMobileAds.Common
2222
{
@@ -30,7 +30,7 @@ internal class DummyClient : IBannerClient, IInterstitialClient, IRewardBasedVid
3030
public event EventHandler<EventArgs> OnAdClosed = delegate {};
3131
public event EventHandler<Reward> OnAdRewarded = delegate {};
3232
public event EventHandler<EventArgs> OnAdLeavingApplication = delegate {};
33-
public event EventHandler<CustomNativeEventArgs> onCustomNativeTemplateAdLoaded = delegate {};
33+
public event EventHandler<CustomNativeEventArgs> OnCustomNativeTemplateAdLoaded = delegate {};
3434

3535
public String UserId
3636
{

source/plugin/Assets/GoogleMobileAds/Common/IAdLoaderClient.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,17 @@
1111
// limitations under the License.
1212

1313
using System;
14+
1415
using GoogleMobileAds.Api;
1516

1617
namespace GoogleMobileAds.Common
1718
{
1819
internal interface IAdLoaderClient
1920
{
2021
event EventHandler<AdFailedToLoadEventArgs> OnAdFailedToLoad;
21-
event EventHandler<CustomNativeEventArgs> onCustomNativeTemplateAdLoaded;
22+
23+
event EventHandler<CustomNativeEventArgs> OnCustomNativeTemplateAdLoaded;
24+
2225
void LoadAd(AdRequest request);
2326
}
2427
}

source/plugin/Assets/GoogleMobileAds/Editor/PostProcessor.cs

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
using System;
22
using System.Collections.Generic;
33
using System.IO;
4-
using UnityEditor.Callbacks;
54
using UnityEditor;
5+
using UnityEditor.Callbacks;
66

77
#if (UNITY_5 && UNITY_IOS)
88
using UnityEditor.iOS.Xcode;
@@ -22,21 +22,33 @@ public static void OnPostprocessBuild(BuildTarget target, string pathToBuiltProj
2222
iOSBuildTarget = BuildTarget.iPhone;
2323
#endif
2424

25-
if(target == iOSBuildTarget)
25+
if (target == iOSBuildTarget)
2626
{
27-
runPodUpdate(pathToBuiltProject);
27+
RunPodUpdate(pathToBuiltProject);
2828
}
2929
}
3030

31-
static void runPodUpdate(string path)
31+
public static void RunPodUpdate(string path)
3232
{
3333
#if !UNITY_CLOUD_BUILD
3434
// Copy the podfile into the project.
3535
string podfile = "Assets/GoogleMobileAds/Editor/Podfile";
36-
string destpodfile = path + "/Podfile";
37-
if(!System.IO.File.Exists(destpodfile))
36+
string destPodfile = path + "/Podfile";
37+
38+
if (!System.IO.File.Exists(podfile))
39+
{
40+
UnityEngine.Debug.LogWarning(@"Could not locate Podfile in
41+
Assets/GoogleMobileAds/Editor/");
42+
return;
43+
}
44+
45+
if (!System.IO.File.Exists(destPodfile))
46+
{
47+
FileUtil.CopyFileOrDirectory(podfile, destPodfile);
48+
}
49+
else
3850
{
39-
FileUtil.CopyFileOrDirectory(podfile, destpodfile);
51+
FileUtil.ReplaceFile(podfile, destPodfile);
4052
}
4153

4254
try
@@ -45,8 +57,8 @@ static void runPodUpdate(string path)
4557
}
4658
catch (Exception e)
4759
{
48-
UnityEngine.Debug.Log("Could not create a new Xcode project with CocoaPods: " +
49-
e.Message);
60+
UnityEngine.Debug.LogWarning("Could not create a new Xcode project with " +
61+
"CocoaPods: " + e.Message);
5062
}
5163
#endif
5264

source/plugin/Assets/GoogleMobileAds/Platforms/Android/AdLoaderClient.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public class AdLoaderClient : AndroidJavaProxy, IAdLoaderClient
2929
private Dictionary<string, Action<CustomNativeTemplateAd, string>>
3030
CustomNativeTemplateCallbacks { get; set; }
3131
public event EventHandler<AdFailedToLoadEventArgs> OnAdFailedToLoad;
32-
public event EventHandler<CustomNativeEventArgs> onCustomNativeTemplateAdLoaded;
32+
public event EventHandler<CustomNativeEventArgs> OnCustomNativeTemplateAdLoaded;
3333

3434
public AdLoaderClient(AdLoader unityAdLoader) : base(Utils.UnityCustomNativeAdListener)
3535
{
@@ -62,7 +62,7 @@ public void onCustomTemplateAdLoaded(AndroidJavaObject ad)
6262
CustomNativeEventArgs args = new CustomNativeEventArgs() {
6363
nativeAd = new CustomNativeTemplateAd(new CustomNativeTemplateClient(ad))
6464
};
65-
onCustomNativeTemplateAdLoaded(this, args);
65+
OnCustomNativeTemplateAdLoaded(this, args);
6666
}
6767

6868
void onAdFailedToLoad(string errorReason)

0 commit comments

Comments
 (0)