As some of you may have noticed, Unity3D currently has a public preview period for their Flash exporting feature. During this preview period, you can export your Unity3D games as a .swf game for free.
Now, loving Mochi as much as we all do, we want to make some money from our games using MochiAds right? And not just make some money, but we want those awesome leader boards and medals too!
Yes, but unfortunately, that’s not just a matter of adding the Mochi API and exporting the game.
So, to be able to put MochiAds in our games, I’ve been working on a Mochi-Unity3D bridge which I would like to share with you all! And I won’t just share it, I’ll even show you how to use it!
Wait, what is Unity3D?
Unity3D is an awesome game engine that can target multiple platforms, like standalone win/mac, iOS, Android and now Flash (Stage3D). Later this year, Unity3D 4.0 will be released with full Flash export capabilities. But as of version 3.5 earlier this year, they have added a preview of this new targeting platform.
Unity3D can be downloaded for free here: http://unity3d.com/unity/download/.
So, what do I need?

- Unity3D (I’m using version 3.5.3 in this demo)
- Flash Develop (I’m using version 4.0.4 in this demo)
- The Mochi-Unity3D bridge and the FlashDevelop .AS files.
I’m all set, what’s next?
So you’ve got your state-of-the-art Unity3D flash game ready? Awesome! Here is a step-by-step guide on how to enable MochiAds and some of its basic functions to your game!
First, set up your game in your MochiAds Dashboard
- If you don’t have a MochiAds account yet, sign up here.
- Add the game to your account.
- Once added, you can create leader boards, a store, awards etc..
- Import the Mochi_Unity3D_Bridge.unitypackage file (Assets->Import Package->Custom Package)
- In your FIRST scene, drag the MochiObject prefab (from the prefabs folder) to your hierarchy
- *Optionally, you can set the Award notice in the inspector when you’ve selected the MochiObject*Format can be: “ShortForm”, “LongForm” or “NoForm”
Alignment can be: “ALIGN_TL”, “ALIGN_T”, “ALIGN_TR”, “ALIGN_L”, “ALIGN_C”, “ALIGN_R”, “ALIGN_BL”, “ALIGN_B”, “ALIGN_BR”. For Top Left, Top, Top Right, etc.
- You only have to call the methods to the API from here on! Check the list of functions below.
- Build the game (File -> Build Settings)
*Make sure all the scenes u use are added to the build and the selected platform is flash. Uncheck “development build” and set the Flash version to 11.0 (higher doesn’t work with Mochi yet).
- Open FlashDevelop and create a new project (Project -> New project -> AS3 project)
- Set the project properties (Project -> properties) to Flash Player 11.0 (higher won’t work on Mochi yet) and your game dimensions.
- Add the .swf file to the “src” folder.
- Add the UnityShared.swc file to the “lib” folder and add it to the library (In FlashDevelop- right click -> Add to Library)
- Replace Main.as in the “src” folder with the Main.as from the resources downloaded earlier.
- In this new Main.as change MOCHI_GAME_ID to your mochi game id.
- Also in this Main.as change GAME_NAME.swf to your games swf name (Should be the same as in the “src” folder
- Add MochiStuff.as from the resources to the “src” folder
- Create 3 images in the games dimensions that should be shown 1. while loading, 2. If wmode is not direct, 3. if Stage3D is not being used. Add these images to your “src” folder with the names: “loading.jpg”, “wmode_not_direct.jpg” and “no_stage3d.jpg”
- Build your project! (set configuration to “Release” then go to Project -> Build Project).
- The game should now have been published to the “bin” folder. You can upload this .swf file in your MochiAds dashboard!
- Flash exporting is currently free with Unity3D 3.5, but will be a paid add-on for Unity3D 4. The basic license costs $400, the pro license $1500. As far as I now, the preview version will stay avaiable in 3.5.
- Stage3D is flash player 11+ only.
- The game HAS to be embedded using “wmode=direct” (this is bad for distribution)
- As of late August 2012, you’ll require a license from Adobe to develop games that use Domain memory AND Stage3D (which all games created with Unity3D do). Though this fee is only 9% of the net revenue ABOVE $50.000 per project -so most of us indie developers will actually never have to pay Adobe-, this might dramatically hurt distribution too, depending on how Adobe is going to track every project. They don’t have details on this yet, but if for instance every publishing portal has to keep track of the revenue made from one of these games too, then NO portal is going to add them. We will know more about this soon! For games you’ll release before their licensing site goes live, make sure to use the Mochi live updates wrapper so that you can update the game with the license later, when it becomes available. If you release it without a license, the game will fall back to software rendering 8 weeks after the licensing site has gone live, if you don’t update the game with the proper license.
More info on Adobe’s website: Adobe Flash premium features
Second, let’s prepare your game in Unity3D
Now let’s build the game with FlashDevelop!
Can you show me how this works?
Sure, take a look at this demonstration video!
Things to keep in mind
There are some things you should keep in mind before focussing your life on Stage3D games made with tools like Unity3D.
Hooray! My game is working!
Neat! I’d love to see it! Make sure to drop by on the Mochi Forums and let us know!
Boohoo! It won’t work :(
Too bad!
I kid, let me know on the Mochi Forums and I’ll do my best to help!
Is this a WIP?
Yes it is! There are some things that I didn’t test much with yet (like the stores). I’ll keep updating this bridge to enable more of Mochi’s functions. Next thing in line are decent callbacks. (look at the bottom in MochiObject.cs for a few callbacks that already work, like when items are bought from the store).
Available MochiAds methods
// Log a gameplay
MochiObject.startPlay();
// Log a gameplay end
MochiObject.endPlay();
// Show a leader board
MochiObject.showLeaderBoard(string leaderBoardID);
// Send a score to a leader board
MochiObject.sendScore(string leaderBoardID, int score);
// Send a score to a leader board with a player name
MochiObject.sendScoreWithName(string leaderBoardID, int score, string playerName);
// Show awards
MochiObject.showAwards();
// Unlock an award/achievement
MochiObject.unlockAchievement(string achievementID);
// Show a click-away ad at position x, y
MochiObject.showClickAwayAd(int xpos, int ypos);
// Hide the click-away ad
MochiObject.hideClickAwayAd();
// Show the login widget at position x, y
MochiObject.showLoginWidget(float xPos, float yPos);
// Hide the login widget
MochiObject.hideLoginWidget();
// Show the player profile
MochiObject.showProfile();
// Show the login page
MochiObject.requestLogin();
// Show the store.
MochiObject.showStore();
//*Optionally: to show only specific items, you can send id’s when calling the store
MochiObject.showStore(“id1, id2, id3″);
// Show an item from the store
MochiObject.showItem(string id);
// *Optionally: show an item from the store at a certain position
MochiObject.showItem(string id, int xPos, int yPos);
// Show the video of a store item
MochiObject.showVideo(string id);
/ Set the inventory amount of a consumable shop item
MochiObject.setInventory(string itemName, int amount);
/ Change the inventory amount of a consumable item
MochiObject.changeInventoryBy(string itemName, int amount);
/ Delete an item from the inventory
MochiObject.deleteInventory(string itemName);
