Unity

From Ad4Game Developers
Revision as of 11:48, 21 October 2014 by Mostapha (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search


Contents

Android Unity

Publishers

Download Android SDK

What's new!
   
The new Android SDK v3.0 for Unity supports now Google’s Advertising Identifier
The new Android SDK v4.0 for Unity allows you handling ads events.

Download the [Android SDKv4.0 publishers for Unity]. Decompress the zip file and extract the files to your development computer.
The Android SDK for Unity is provided as three java JAR files (AndroidSDKPublisher4.0.jar, a4gpublisherunity.jar et et google-play-services.jar), making it easy to include in your Android project.

Setup the Unity Project

- Create a ‘Plugins’ folder and within this create another folder called ‘Android’ (Assets­>Plugins­>Android).

- Copy the AndroidSDKPublisher4.0.jar, a4gpublisherunity.jar and the google-play-services.jar into this folder.

- Create a ‘res’ folder and within this create another folder called ‘values’ (Assets­>Plugins­>Android­>res­>values). Copy the version.xml to this folder.

Build the project for Android and then go into the ‘Temp\StagingArea’ folder with your project folder and copy the AndroidManifest.xml file into the ‘Android’ folder.
This manifest file now needs to be edited to look like this:

Display Mobile Ads

You will create a C# file that will attach to a Unity GameObject as a script. The C# file need to be under the Assets folder.
You'll then need to call the loadTopAds or loadBottomAds (you can call the both methods to display two ads (one on the top, and the other on the bottom of the screen) methods in the Awake() function of an empty GameObject in your startup scene:

   
AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); AndroidJavaObject a4g = jc.GetStatic<AndroidJavaObject>("currentActivity"); a4g.Call("loadTopAds", "yourZoneID"); a4g.Call("loadBottomAds", "yourSecondZoneID");

Handling Events

If you want to handle ads events, you need first to set your GameObject in the Awake() function as follow :

   a4g.Call("setGameObject", "game object name");// Main Camera for example

Then, you can call the following functions :

   void onAdLoaded() {
      // Do your treatment
   }
   void onAdFailed() {
      // Do your treatment
   }
   void onAdClicked() {
      // Do your treatment
   }

Now, go to File ­>Build Settings ­>Player Settings, and change the Bundle Identifier to com.a4gpublisherunity.
Build the Unity project for Android platform and run it on your device to see the ads.

Display Android Editorials

To display Android Editorials inside your unity project, you need to use one of the three methods (you can use all of them) bellow:
1­- showA4GEditos : If you want to display the editorials once the activity's started.
2­- showA4GEditosWithStartTime : If you want to display the editorials after certain time.
3­- showA4GEditosWithStartAndEndTime : If you want to display the editorials after certain time and close them automatically after certain time.
4­- showA4GEditosOnClick : If you want to display the editorials when the user click on a button.

   
Note: The three first methods mentioned above are valid only if your project target android 3.0 or above, showA4GEditoOnClick is
valid from android 2.3 or above.

Handling Events

If you want to handle Editorials events, you need first to set your GameObject in the Awake() function as follow :

   a4g.Call("setGameObject", "game object name");// Main Camera for example

Then, you can call the following functions :

   void onEditorialLoaded() {
      // Do your treatment
   }
   void onEditorialFailed() {
      // Do your treatment
   }
   void onEditorialClicked() {
      // Do your treatment
   }
   void onEditorialClosed() {
      // Do your treatment
   }

Display Android Interstitials

To display Android interstitials inside your unity project, you need to use one of the three methods (you can use all of them) bellow:
1- showA4GInterstitials : If you want to display the interstitials once the activity's started.
2- showA4GInterstitialsWithStartTime : If you want to display the interstitials after certain time.
3- showA4GInterstitialsWithStartAndEndTime : If you want to display the interstitials after certain time and close them automatically after certain time.

Handling Events

If you want to handle Interstitials events, you need first to set your GameObject in the Awake() function as follow :

   a4g.Call("setGameObject", "game object name");// Main Camera for example

Then, you can call the following functions :

   void onInterstitialsLoaded() {
      // Do your treatment
   }
   void onInterstitialsFailed() {
      // Do your treatment
   }
   void onInterstitialsClicked() {
      // Do your treatment
   }
   void onInterstitialsClosed() {
      // Do your treatment
   }

Advertisers

Download Android SDK

What's new!
   
The new Android SDK v2.0 for Unity supports now Google’s Advertising Identifier

Download the [Android SDKv2.0 advertisers for Unity]. Decompress the zip file and extract the files to your development computer.
The Android SDK for Unity is provided as three java JAR files (AndroidSDKTracker2.0.jar , A4GTrackerUnity.jar et google­_play­_services.jar), making it easy to include in your Unity project.

Setup the Unity Project

- Create a ‘Plugins’ folder and within this create another folder called ‘Android’ (Assets­>Plugins­>Android). Copy the AndroidSDKTracker2.0.jar, A4GTrackerUnity.jar and the google-play-services.jar into this folder.

- Create a ‘res’ folder and within this create another folder called ‘values’ (Assets­>Plugins­>Android­>res­>values). Copy the version.xml to this folder.

- Build the project for Android and then go into the ‘Temp\StagingArea’ folder with your project folder and copy the AndroidManifest.xml file into the ‘Android’ folder.

This manifest file now needs to be edited to look like this:

You will then create a C# file that will attach to a Unity GameObject as a script. The C# file need to be under the Assets folder.
You'll then need to call the loadTrack method in the Awake() function of an empty GameObject in your startup scene:

   
AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); AndroidJavaObject a4g = jc.GetStatic<AndroidJavaObject>("currentActivity"); a4g.Call("loadTrack", "yourTrackerID");

Now, go to File ­>Build Settings ­>Player Settings, and change the Bundle Identifier to com.a4gtrackerunity.

iOS Unity

Publishers

Download iOS SDK

Download the [iOS SDKv3.0 publishers for Unity]. Decompress the zip file and extract the files to your development computer.
The iOS SDK for Unity is provided as a single framework file (A4GPubUnity.framework), making it easy to include in your iOS project.

Include the A4GPubUnity.framework

Build your Unity project for iOS, then open the generated xcode project.
To include the A4GPubUnity.framework to your xcode project, you need to select your target project, and then go to Build Phases → Link Binary With Libraries, then click on the + sign → Add Other, and select the A4GPubUnity.framework saved on your computer.

Include the AdSupport.framework

You need to include the AdSupport.framework to your project target to enable the Advertiser Identifier functionality. Go to Build Phases → Link Binary With Libraries, then click on the + sign to add the AdSupport.framework.
Then, change the value of AdSupport.framework from Required to Optional.

Include the SystemConfiguration.framework

You need to include the SystemConfiguration.framework to your project target to enable the detection of the connection type. Go to Build Phases → Link Binary With Libraries, then click on the + sign to add the SystemConfiguration.framework.

Display Mobile Ads

To display ads on your iOS project, you need to follow the steps bellow:
– You need to add this line into your appController.h file
@property (strong , nonatomic) UIWindow *window;
In your appController.mm file
– You need to import the A4GPubUnity.framework, after the last #import.
#import <A4GPubUnity/A4GPubUnityViewController.h>
– Go to startUnity method and do these steps :
– Instantiate the window declared inside appController.h file.
– Instantiate an object of A4GPubUnityViewController.
– Add a imageView and Button with the same size of the ad to display (the button need to be above the imageView and need to be transparent).
– call the different method to display ads. The methods are:
* setZoneID method allows you to set the zoneID.
* getRefresh method to refresh the display of banners.
* loadAds method to get banners from ad4game servers.
Your code need to be similar to this:

Display iOS Editorials

To display mobile Editorials on your iOS project developed by Unity, you need to follow the steps bellow:
– You need to add this line into your appController.h file
@property (strong , nonatomic) UIWindow *window;
In your appController.mm file
– You need to import the A4GPubUnity.framework, after the last #import.
#import <A4GPubUnity/A4GPubUnityViewController.h>
#import <A4GPubUnity/A4GEdito.h>
– Go to startUnity method and do these steps :
– Instantiate the window declared inside appController.h file.
– Instantiate an object of A4GEdito.
– You need to add a UIButton if you want to launch the editorials when the user clicks on that button.
– call the different method to display mobile Editorials. The methods are:
* setZoneID method allows you to set the zoneID.
* showA4GEditos method, to display directly the Editorials when the app started.
* showA4GEditosWithStartTime method, to display the Editorials after a certain time.
* showA4GEditosWithStartAndEndTime method, to display the Editorials after a certain time, and close them automatically after a certain time.
Your code need to be similar to this: ­

     -(void) startUnity:(UIApplication*)application {
     self.window = [[UIWindow alloc] initWithFrame:[[UIScreen    mainScreen] bounds]];
     A4GEdito *a4gEdito = [[A4GEdito alloc]init];
     [a4gEdito setZoneID:@"32593"]; // set ZoneID
     UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
     button.frame = CGRectMake(20, 20, 50, 50); // Create a button where x=20, y=20, width=50, height=50;
     [button setTitle:@”Editorials” forState:UIControlStateNormal];
     [button addTarget:a4gEdito action:@selector(showA4GEditos) forControlEvents:UIControlEventTouchUpInside];

     [self.window addSubview:button];
     [self.window makeKeyAndVisible];
     [a4gEdito showA4GEditos]; // Show Editorials when the app started.
     [a4gEdito showA4GEditosWithStartTime : 10]; // Show Editorials after 10 seconds.
     [a4gEdito showA4GEditosWithStartAndEndTime : 10 withArg2 : 20]; // Show Editorials after 10 seconds and close it automatically after 20 seconds.

Display iOS Interstitials

To display mobile Interstitials on your iOS project developed by Unity, you need to follow the steps bellow:
– You need to add this line into your appController.h file
@property (strong , nonatomic) UIWindow *window;
In your appController.mm file
– You need to import the A4GPubUnity.framework, after the last #import.
#import <A4GPubUnity/A4GPubUnityViewController.h>
#import <A4GPubUnity/A4GInterstitials.h>
– Go to startUnity method and do these steps :
– Instantiate the window declared inside appController.h file.
– Instantiate an object of A4GInterstitials.
– call the different method to display mobile Editorials. The methods are:
* setZoneID method allows you to set the zoneID.
* showA4GInterstitials method, to display directly the Interstitials when the app started.
* showA4GInterstitialsWithStartTime method, to display the Interstitials after a certain time.
* showA4GInterstitialsWithStartAndEndTime method, to display the Interstitials after a certain time, and close them automatically after a certain time.
Your code need to be similar to this: ­

     -(void) startUnity:(UIApplication*)application {
     self.window = [[UIWindow alloc] initWithFrame:[[UIScreen    mainScreen] bounds]];
     A4GInterstitials *a4gInter = [[A4GInterstitials alloc]init];
     [a4gInter setZoneID:@"32593"]; // set ZoneID
     [a4gInter showA4GInterstitials]; // Show Interstitials when the app started.
     [a4gInter showA4GInterstitialsWithStartTime : 10]; // Show Interstitials after 10 seconds.
     [a4gInter showA4GInterstitialsWithStartAndEndTime : 10 withArg2 : 20]; // Show Interstitials after 10 seconds and close them automatically after 20 seconds.
     [self.window makeKeyAndVisible];

Advertisers

Download iOS SDK

Download the [iOS SDKv1.0 advertisers for Unity]. Decompress the zip file and extract the files to your development computer.
The iOS SDK for Unity is provided as a single framework file (A4GUnityTracker.framework), making it easy to include in your iOS project.

Setup the Unity project

To integrate the Ad4game iOS plugin in your Unity app, you will be creating a C# file that will attach to a Unity GameObject as a script.
The C# file need to be under the Assets folder.
In the C# scripts, DllImport attribute needs to be set for the trackInstall method to be imported from the plugin code.
Remember that you need to add this line on the top of the C# file:

  
using System.Runtime.InteropServices; [DllImport ("__Internal")] private static extern void trackInstall(string trackerID);

You'll then need to call the trackInstall function in the Awake() function of an empty GameObject in your startup scene:

  
void Awake () { trackInstall("yourTrackerID"); }

Build the Unity project for iOS platform. Note that a new iOS Xcode project is generated.

Include the A4GUnityTracker.framework

Open the iOS project in Xcode.
To include the A4GUnityTracker.framework to your xcode project, you need to select your target project,
and then go to Build Phases → Link Binary With Libraries, then click on the + sign → Add Other, and select the A4GUnityTracker.framework saved on your computer.

Include the AdSupport.framework

You need to include the AdSupport.framework to your project target to enable the Advertiser Identifier functionality.
Go to Build Phases → Link Binary With Libraries, then click on the + sign to add the AdSupport.framework.
Then, change the value of AdSupport.framework from Required to Optional.

Include the SystemConfiguration.framework

You need to include the SystemConfiguration.framework to your project target to enable detection of the internet availability.
Go to Build Phases → Link Binary With Libraries, then click on the + sign to add the SystemConfiguration.framework.

Contact

If you've got questions, we've got answers! Please Contact Us at tech@ad4game.com with any technical queries.

Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox