openfl-unityads

UnityAds Implementation for OpenFL/Haxe


Keywords
ads, cross, openfl, unity
License
MIT
Install
haxelib install openfl-unityads 1.0.2

Documentation

openfl-unityads

UnityAds implementation for OpenFL/Haxe

With love from:

Ipsilon Developments Inc. released under MIT license

Like our Facebook page to get news about our releases

Or Follow us on Twitter

You can also contact us at info [AT] ipsilondev.com

Known problems:

When compiling to Android, if you find an error like: Can't read [/PATH/TO/unity-ads.jar] ( Can't process class [com/unity3d/ads/android/cache/UnityAdsCacheThread.class] (15360))

For now, you can disable Proguard, by commenting line 16 in project.properties. On next release, or the .jar will be replaced with the SDK source code, or this line will be commented forever.

How to use

First of all, install the lib:

haxelib install openfl-unityads

Once this is done, you just need to add this to your project.xml

<haxelib name="openfl-unityads" />

Then, you must set up the event listeners, and then initialize.

    import extension.unityads.UnityAds;

		UnityAds.onVideoStarted = function():Void {
			Lib.trace("onVideoStarted");
		};
		UnityAds.onVideoCompleted = function(key:String,reward:Bool):Void {
			Lib.trace("onVideoCompleted = "+key+" = "+reward);
		};
		UnityAds.onShow = function() {
		Lib.trace("onShow");
		};
		UnityAds.onHide = function() {
			Lib.trace("onHide");
		};
		UnityAds.onFetch = function(res:Bool):Void {
			Lib.trace("fetchResult = " + res);
			if (res) {
			var resShowAd:Bool = UnityAds.showAd("rewardedVideoZone");
			if (resShowAd) {
			Lib.trace("showing ad OK");
			}else {
			Lib.trace("notshowing ad");
			}
			}
		};
		UnityAds.init("YOUR_GAME_ID", true,true);
		
		//check statically if you are enable to show ads
		if(UnityAds.canShowAds()){
		Lib.trace("I can show ads !");
		}else{
		Lib.trace("I can NOT show ads !");
		}

Important Notes

  1. Drag and Drop the UnityAds.bundle file inside the Resources folder in xCode !!! If you don't do this, your app will crash at showing the ad !

  2. This are all the available events that you can listen to. Is optional if you want to support all, or just a few. But be sure to catch up onFetch event, that say if the connection to UnityAds servers was successful and if is ready to show ads.

  3. init() function, need GAMEID as mandatory parameter, and the other 2, are to enable test mode and debug mode. be sure to disable both when you package your game !

  4. showAd() function requires of a zoneID to be passed, and optional, a rewardKey. you can get both from the UnityAds admin panel. i know that the documentation say's that zoneID is optional, but i discovered that at least in android, if you don't pass it, it never show an ad.