Skip to content

Commit

Permalink
Addded support for Unity 5.0 & ARC and additional Banner positions
Browse files Browse the repository at this point in the history
  • Loading branch information
rampara committed Mar 25, 2015
1 parent b7d42a4 commit 6a86f39
Show file tree
Hide file tree
Showing 14 changed files with 172 additions and 85 deletions.
42 changes: 42 additions & 0 deletions unity/ChangeLog.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
Google Mobile Ads Unity Plugin Change Log

***********
Version 2.2
***********
- Support for Unity 5.0 & ARC
- Additional Banner positions
- iOS Ads SDK 7.0.0 compatibility

***********
Version 2.1
***********
- Support for Interstitial Ads
- Ad events use EventHandlers

***********
Version 2.0
***********
- A single package with cross platform (Android/iOS) support
- Mock ad calls when running inside Unity editor
- Support for Banner Ads
- Custom banner sizes
- Banner ad events listeners
- AdRequest targeting methods
- A sample project to demonstrate plugin integration

***********
Version 1.2
***********
- Initial Android version with Google Play services support
- Support for Banner Ads only

***********
Version 1.1
***********
- Initial iOS only version
- Support for Banner Ads only

***********
Version 1.0
***********
- Initial version for Android (using now deprecated legacy Android SDK)
12 changes: 7 additions & 5 deletions unity/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ the plugin, as well as the source code for those that want to iterate on it.

Requirements
------------
* Unity 4.3 (untested on previous versions)
* Unity 4.5
* An ad unit ID
* To deploy on Android:
* Android SDK 3.2 or higher
Expand All @@ -28,6 +28,7 @@ Requirements
* To deploy on iOS:
* XCode 5.1 or above
* [Google Mobile Ads SDK](https://developers.google.com/mobile-ads-sdk/download#downloadios)
7.0.0 or higher


Integrate the Plugin into your Game
Expand Down Expand Up @@ -68,8 +69,10 @@ To build and run on iOS, click **File -> Build Settings**, select the iOS
platform, then **Switch Platform**, then **Build**. This will export an
XCode project. You'll need to do the following before you can run it:

1. Add the Google Mobile Ads iOS SDK library.
2. Add the following frameworks if they aren't already part of the project:
1. From the Xcode project navigator, right-click on the project, and choose
Add Files To "<Project Name>".
2. Navigate to and select **GoogleMobileAds.framework**.
3. Add the following frameworks if they aren't already part of the project:
* AdSupport
* AudioToolbox
* AVFoundation
Expand All @@ -80,7 +83,7 @@ XCode project. You'll need to do the following before you can run it:
* MessageUI
* StoreKit
* SystemConfiguration
3. Add the **-ObjC** linker flag to your **Other Linker Flags** in
4. Set **Enable Modules (C and Objective-C)** to **Yes** in
**Build Settings**.

If these steps didn't work, the [developer docs](https://developers.google.com/mobile-ads-sdk/docs/admob/ios/quick-start#manually_using_the_sdk_download)
Expand Down Expand Up @@ -254,4 +257,3 @@ Additional Resources
* [Developer documentation](https://developers.google.com/mobile-ads-sdk)
* [Developer forum](https://groups.google.com/group/google-admob-ads-sdk)
* [Google Ads +Page](https://plus.google.com/+GoogleAdsDevelopers)

6 changes: 5 additions & 1 deletion unity/source/Assets/GoogleMobileAds/Api/AdPosition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ namespace GoogleMobileAds.Api
public enum AdPosition
{
Top = 0,
Bottom = 1
Bottom = 1,
TopLeft = 2,
TopRight = 3,
BottomLeft = 4,
BottomRight = 5
}
}
2 changes: 1 addition & 1 deletion unity/source/Assets/GoogleMobileAds/Api/AdRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace GoogleMobileAds.Api
{
public class AdRequest
{
public const string Version = "2.1";
public const string Version = "2.2";
public const string TestDeviceSimulator = "SIMULATOR";

public class Builder
Expand Down
14 changes: 10 additions & 4 deletions unity/source/Assets/Plugins/Android/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.unity.helloworld" android:installLocation="preferExternal" android:theme="@android:style/Theme.NoTitleBar" android:versionName="1.0" android:versionCode="1">
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.unity.package" android:versionName="1.0" android:versionCode="1" android:installLocation="preferExternal">
<supports-screens android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:xlargeScreens="true" android:anyDensity="true" />
<application android:icon="@drawable/app_icon" android:label="@string/app_name" android:debuggable="true">
<activity android:name="com.unity3d.player.UnityPlayerNativeActivity" android:label="@string/app_name">
<application android:theme="@android:style/Theme.NoTitleBar" android:icon="@drawable/app_icon" android:label="@string/app_name" android:debuggable="false" android:isGame="true" android:banner="@drawable/app_banner">
<activity android:name="com.unity3d.player.UnityPlayerActivity" android:label="@string/app_name" android:screenOrientation="fullSensor" android:launchMode="singleTask" android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
</intent-filter>
<meta-data android:name="unityplayer.UnityActivity" android:value="true" />
<!--
Expand All @@ -22,5 +23,10 @@
<meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="true" />
</activity>
</application>
<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="19" />
<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="21" />
<uses-feature android:glEsVersion="0x00020000" />
<uses-feature android:name="android.hardware.touchscreen" android:required="false" />
<uses-feature android:name="android.hardware.touchscreen.multitouch" android:required="false" />
<uses-feature android:name="android.hardware.touchscreen.multitouch.distinct" android:required="false" />
</manifest>

10 changes: 7 additions & 3 deletions unity/source/Assets/Plugins/iOS/GADUBanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@

/// Positions to place a banner.
typedef NS_ENUM(NSUInteger, GADAdPosition) {
kGADAdPositionTopOfScreen = 0, ///< Ad positioned at top of screen.
kGADAdPositionBottomOfScreen = 1 ///< Ad positioned at bottom of screen.
kGADAdPositionTopOfScreen = 0, ///< Ad positioned at top of screen.
kGADAdPositionBottomOfScreen = 1, ///< Ad positioned at bottom of screen.
kGADAdPositionTopLeftOfScreen = 2, ///< Ad positioned at top left of screen.
kGADAdPositionTopRightOfScreen = 3, ///< Ad positioned at top right of screen.
kGADAdPositionBottomLeftOfScreen = 4, ///< Ad positioned at bottom left of screen.
kGADAdPositionBottomRightOfScreen = 5 ///< Ad positioned at bottom right of screen.
};

/// A wrapper around GADBannerView. Includes the ability to create GADBannerView objects, load them
Expand All @@ -35,7 +39,7 @@ typedef NS_ENUM(NSUInteger, GADAdPosition) {
@property(nonatomic, assign) GADUTypeBannerClientRef *bannerClient;

/// A GADBannerView which contains the ad.
@property(nonatomic, retain) GADBannerView *bannerView;
@property(nonatomic, strong) GADBannerView *bannerView;

/// The ad received callback into Unity.
@property(nonatomic, assign) GADUAdViewDidReceiveAdCallback adReceivedCallback;
Expand Down
31 changes: 21 additions & 10 deletions unity/source/Assets/Plugins/iOS/GADUBanner.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#import "UnityAppController.h"

@interface GADUBanner ()<GADBannerViewDelegate>
@interface GADUBanner () <GADBannerViewDelegate>

/// Defines where the ad should be positioned on the screen.
@property(nonatomic, assign) GADAdPosition adPosition;
Expand Down Expand Up @@ -39,7 +39,7 @@ - (id)initWithSmartBannerSizeAndBannerClientReference:(GADUTypeBannerClientRef *
adUnitID:(NSString *)adUnitID
adPosition:(GADAdPosition)adPosition {
// Choose the correct Smart Banner constant according to orientation.
UIDeviceOrientation currentOrientation = [[UIDevice currentDevice] orientation];
UIDeviceOrientation currentOrientation = [UIApplication sharedApplication].statusBarOrientation;
GADAdSize adSize;
if (UIInterfaceOrientationIsPortrait(currentOrientation)) {
adSize = kGADAdSizeSmartBannerPortrait;
Expand Down Expand Up @@ -68,6 +68,10 @@ - (id)initWithBannerClientReference:(GADUTypeBannerClientRef *)bannerClient
return self;
}

- (void)dealloc {
_bannerView.delegate = nil;
}

- (void)loadRequest:(GADRequest *)request {
if (!self.bannerView) {
NSLog(@"GoogleMobileAdsPlugin: BannerView is nil. Ignoring ad request.");
Expand Down Expand Up @@ -114,6 +118,21 @@ - (void)adViewDidReceiveAd:(GADBannerView *)adView {
center = CGPointMake(CGRectGetMidX(unityView.bounds),
CGRectGetMaxY(unityView.bounds) - CGRectGetMidY(_bannerView.bounds));
break;
case kGADAdPositionTopLeftOfScreen:
center = CGPointMake(CGRectGetMidX(_bannerView.bounds), CGRectGetMidY(_bannerView.bounds));
break;
case kGADAdPositionTopRightOfScreen:
center = CGPointMake(CGRectGetMaxX(unityView.bounds) - CGRectGetMidX(_bannerView.bounds),
CGRectGetMidY(_bannerView.bounds));
break;
case kGADAdPositionBottomLeftOfScreen:
center = CGPointMake(CGRectGetMidX(_bannerView.bounds),
CGRectGetMaxY(unityView.bounds) - CGRectGetMidY(_bannerView.bounds));
break;
case kGADAdPositionBottomRightOfScreen:
center = CGPointMake(CGRectGetMaxX(unityView.bounds) - CGRectGetMidX(_bannerView.bounds),
CGRectGetMaxY(unityView.bounds) - CGRectGetMidY(_bannerView.bounds));
break;
}

// Remove existing banner view from superview.
Expand Down Expand Up @@ -161,12 +180,4 @@ - (void)adViewWillLeaveApplication:(GADBannerView *)adView {
}
}

#pragma mark Cleanup

- (void)dealloc {
_bannerView.delegate = nil;
[_bannerView release];
[super dealloc];
}

@end
Loading

0 comments on commit 6a86f39

Please sign in to comment.