1) Unity 5.3.+ (free or pro)
2) ORK Framework 2.7.1 (free or paid)
3) Playmaker v1.8.0f43 beta + Ecosystem Addon (paid)
4) Playmaker Actions For ORK Framework (ORKPMAction1.0.8forPM1.8.0beta) (paid)
5) Android or iOS device
In this tutorial we´ll show you how easy is to setup Unity Ads with your ORK mobile game. We are going to add an NPC that will ask the player to watch an Ad in exchange of gold.
If the Ad is successful we are going to receive the gold, if the Ad is skipped no gold for us.
Before starting you need to have basic understanding of Unity, ORK Framework, Playmaker, how to setup Unity Ads.
1 - Creating the project and importing the assets
a .Open Unity and create a brand new 3D project and target the Build Settings to Android or iOS.
b. Import ORK Framework package from the Asset Store
c. Import Playmaker package from the Asset Store
you need to select v1.8.0f43 beta from the installed packages.
d. Download and Import the Ecosystem from the Playmaker website
e. Import the Playmaker Actions for ORK Framework either from Assets Store
or Gamekakkak website
f. Import the DemoProject_v1.0.1 from your Account Page at Gamekakkak
g. Follow the steps to install and test the DemoProject
Note: The DemoProject_v1.0.1 package contains an ORK Project named DemoProject.asset, I would suggest to duplicate it, then rename it to ORKProject.asset and replace the existing ORKProject.assets found under the ORK Framework installation (Assets/ORK Framework folder).
h. If Playmaker and Ecosystem was installed successfully you will find a Playmaker Item in the Unity´s toolbar, then from the menu items, choose Addons->Ecosystem->Ecosystem Browser:
Start the Ecosystem browser and type: Unity Ads in the filter box and click search.
From the result set scroll down until you see. Unity Ads Show Ad and click the Get button:
You will get the following screenshot if installation went successful:
i. Open the ORK Framework Editor and make sure that you have listed all the DemoProject Combatants and click Save Settings
2 - Creating the NPC and Events
a. Open the MainMenu Scene under Assets\ORK PlayMakerAction\OrkPlaymakerDemo\Scenes path and change the ORK Game Starter Component to load the ORKProject.assets project file instead the DemoProject.asset.
Save the scene
b. Open and do the same for the GameEventDemo Scene under the same path.
c. With the GameEventDemo scene open, go to the Project Folder->Assets\ORK PlayMakerAction\OrkPlaymakerDemo\Prefabs\NPCs and drag the RedNPC to the scene. Rename the GameObject to something like "UnityAddsNPC".
d. With the NPC selected press Ctrl+Alt+W to open the ORK Framework Scene Wizard and choose Add Component->Event Interaction.
e. Leave the component as it is and save the scene.
f. Go to Unity Menu->Window->ORK Playmaker Wizard and select "Create FSM Game Event".
g. Lets call the new event "UnityAdsNPCEvent" and save it under Assets\ORK PlayMakerAction\OrkPlaymakerDemo\_Events\NPC folder path. This will create an ORK Game Event and a Prefab with Playmaker FSM for you (awsome).
h. Select the prefab from the Project View
i. From the Inspector find the ORK to FSM Event Component script and click the ORK Event Editor.
This will open the ORK Event Editor, click the Event Settings Node and change:
- Blocking Event -> Checked
- Block Player Control -> Checked
The result screen should look like this one:
Now scroll to Event Actors section and add two Actors to the Event Settings.
Actor 0 will be the Ads Giver (Red NPC), change the settings:
- Type -> Object
- Event Object -> Checked
- Set Name -> Checked
- English -> Ads Giver
Actor 1 will be the Player, change the settings:
- Type -> Player
Save the Event and close the ORK Editor.
j. Now, back to the GameEventDemo scene and with our "UnityAddsNPC" selected find the Event Interaction script component in the Inspector View and Click the little circle to find our "UnityAdsNPCEvent" Event asset under Assets\ORK PlayMakerAction\OrkPlaymakerDemo\_Events\NPC folder path.
Nothing the change here, save the scene.
3 - Playmaker FSM time
a. Select the "UnityAdsNPCEvent" Prefab from the Project View and in the Inspector expand the Play Maker FSM Component and click the Edit... button. This will open the PlayMaker Editor window.
b. From PlayMaker Editor window go to the Variables Tabs and add two new local variables.
- cointCount -> Type -> float
- coinCountDisplay -> Type -> string
c. Go to the Events Tab and add 8 local Events as shown in the screen below.
d. By default the Playmaker Actions for ORK FSM Editor will create a FSM Canvas with an empty state1 and the Finished Event state that will handle return to ORK Framework.
And this is how the FSM will look at the end.
e. Lets start by opening the Playmaker Action Browser window and dock it in the unity editor to have quick access to the actions will be using.
f. From the FSM Canvas, lets right click it and add 7 new states
g. Rename the following states as follows:
-ADS NOT READY
h. Now select the state 1 node, change its name to "Talking Animation", and from the Action Browser´s search box type "ORK_" to have access to all related ORK actions.
Search for ORK_Legacy Animation and double click the action or drag it to the selected state panel and change the values as show below.
i. Lets add the transition events for the rest of the states to have a better look of the logic. This is done by right clicking the state and choosing "Add Transition" option
So, following the Final screen for the FSM, we need to add:
Talking Animation -> FINISHED
Ads Choice ->SHOW AD,CANCEL
Show Ad ->ADS NOT READY, ADS SUCCESS, ADS SKIPPED, ADS FAILED
ADS NOT READY ->FINISHED
ADS SKIPPED ->FINISHED
Note: Don´t pay attention of the Transition missing target errors for now.
j. Select the "Ads Choice" state and add an ORK_Show Dialogue Action to it and change:
-GUI Box->1: Inventory
-Actor->0: Ads Giver
-Message Settings->English->"Hello I´m the Ads Giver. Would you like to watch an Ad and earn some coins?.
Scroll down and add two choices, choice 0 will be our "Yes show the add" choice while the second will be to discard the offer.
For choice0 change:
-Choice Text->English->"yes, please."
-Events->Send Event->SHOW AD
For choice1 change:
-Choice Text->English->"Not now."
k. Select the "Show Ad" state and from the Action Browser search for the "Unity Ads Show Ad" Action and add it to the state. Fill the Result section as shown below:
l. Select the "ADS NOT READY" state and add an ORK_Show Dialogue action to it and fill it values as shown below:
m. Select the "ADS SKIPPED" state and add an ORK_Show Dialogue action to it and fill it values as show below:
n. Select the "ADS FAILED" state and add an ORK_Show Dialogue action to it and fill it values as show below:
o. Select the "ADS SUCCESS" state and add an ORK_Show Dialogue action to it and fill it values as show below:
p. Select the "UPDATE INVENTORY" state and for this one we are going to add 3 actions from the Actions Browser:
- ORK_Change Game Variable
- ORK_Add to Inventory
- ORK_Show Dialogue
q. Now we need to add targets to all the orphan transitions we have so far. This is simply done by left clicking the transition from the state and dragging to other state or transition, so following the Final FSM screen you can see were each transition needs to go to.
r. Close the PlayMaker FSM Editor and go to Unity->Window->Services to make sure your account is ready to display the Ads. Login to your account if required to create a dummy application.
Its important to check the Test Mode
s. if you hit the Play button from the Unity Editor with the GameEventDemo scene the player can approach to our UnityAddsNPC to start the interaction.
As you can see this is partially working since we are getting the Ad Giver Dialogue and the Ad is returning a Fail event. Unity Ads wont be showed inside Unity Editor so we need to actually deploy the Game to a device.
t. First we need to change ORK Framework Player Controller in order to use Touch Controls, open the ORK Editor and go to Base Control->Game Controls->Player Controls and change the Player Control Type to Mouse
And the Camera Control to Look
Save the Settings and close the ORK Editor.
u. Before building the project make sure that from Player Settings, your Company Name, Product Name, and Bundle Identifier for the target device are set properly. Change the Default Orientation to Landscape Left. If targeting Android make sure Android SDK and JDK are already mapped.
v. Connect your device (Android or iOS) to your computer
Depending of the target device after build you will need to open XCode to compile and deploy the game or if Android copy the apk file to your device and install it from within the device.
Now you can really test the Game with Unity Ads in Test mode.
Since the Game is not completely ported to Mobile there is no easy way to display the Inventory to check if we actually got the 2 coins from the Ad, so what we can do after watching the Ad is go to Blue Pants NPC which is expecting you to have 4 coins in order to join your combat group. Give a try ;).
I hope you enjoy it and feel free to comment any issue or improvements you may find.
PD: Makinom also has Unity Ads steps so this can be reproduced using Makinom+ORK Framework