Posted by: bearc0025 | July 20, 2013

Adding ChartBoost to an iOS Unity3d Project

Screen Shot 2013-07-20 at 10.40.13 AMI decided to add ChartBoost to a Unity game I was developing. I went to chartboost.com and got the unity plugin. The doco there was pretty good, but seemed to end w/ “These scripts demonstrate how to hook up exposed methods” and I wasn’t sure where to go.

Once you’ve followed their directions and installed the custom package (“Right-click Assets in the Project section, then mouse over Import Package and click Custom Package”), there’s 5 key items:

  • ChartBoostBinding (ChartBoost plugin)
  • ChartBoostManager (ChartBoost plugin)
  • ChartBoostGUIManager (ChartBoost demo)
  • ChartBoostEventListener (ChartBoost demo)
  • ChartBoostTestScene (ChartBoost demo)

The plugin items do the work behind the scenes. We need to replicate what is done in the demo project in our project.

Load and run the demo scene (double click on the ChartBoostTestScene under Plugins->ChartBoost->demo). You’ll see the buttons created by ChartBoostGUIManager. Select the ChartBoostGUIManager (click to view in the Inspector or double-click to load in the editor). Notice the buttons created in the test scene match the ‘if’s in the script.

Copy the ChartBoostEventListener to your project by loading your project scene and dragging it to your main character or similar ‘main’ type object. This will create the event listeners etc. This is first half of replicating their demo project items.

To replicate the ChartBoostGUIManager, we need to make the same calls it does but in ways that make sense to our project. The calls are:

  • ChartBoostBinding.init ( “CHARTBOOST_APP_ID”, “CHARTBOOST_APP_SIGNATURE” );
  • ChartBoostBinding.cacheInterstitial( “default” );
  • Debug.Log( “is cached: ” + ChartBoostBinding.hasCachedInterstitial( “default” ) );
  • ChartBoostBinding.showInterstitial( “default” );
  • ChartBoostBinding.cacheMoreApps();
  • ChartBoostBinding.showMoreApps();

NOTE: Get your chartboost app id and signature when you create your app via chartboost.com. I won’t duplicate their steps here.

In my Start function, I added:

ChartBoostBinding.init ( "CHARTBOOST_APP_ID", "CHARTBOOST_APP_SIGNATURE" );
ChartBoostBinding.cacheInterstitial( "default" );
ChartBoostBinding.cacheMoreApps();

This, obviously, initializes the ChartBoost framework. It then caches both an ad (interstitial) and ‘more apps’ for showing the more apps type ad.

Then I have two functions for launching these during the game…

function ShowAd()
{
print ("Show ad");
if (ChartBoostBinding.hasCachedInterstitial( "default" ))
{
ChartBoostBinding.showInterstitial( "default" );
ChartBoostBinding.cacheInterstitial( "default" );
}
else
print ("No ad cached");
}

function ShowMoreApps()
{
print (“Show more apps”);
ChartBoostBinding.showMoreApps();
ChartBoostBinding.cacheMoreApps();
}

In my game logic, I set a counter/flag and increment it each time a game is played. When the magic number is reached, I call ShowAd() or ShowMoreApps(). That logic is, of course, specific to whatever game I am/you are developing.

NOTE/WARNING: From what I’ve seen, once I add this code, I can only now build for iOS. I can test w/in Unity, but I can’t build a web player w/ this setup. I haven’t looked into how to have both exist so it might be easy, but I haven’t messed w/ switching it and such. If you do, please post a comment.

Overall, I think using ChartBoost has been really easy. I first went the route of adding it in my Xcode project which was pretty easy, but w/ Unity recreating the project, I obviously didn’t want to re-add everything each time or automate some process.

My only confusion was how to get past the end of their quick-setup style doco and get the same setup in my project.

About these ads

Responses

  1. Find the latest Chartboost Unity Plugin and documentation here: https://help.chartboost.com/documentation/unity


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

Follow

Get every new post delivered to your Inbox.

Join 388 other followers

%d bloggers like this: