Unity

The Unity version of the API allows you to extend your game developed in Unity Game Engine to comunicate with the back­-end of Click Jogos.

Getting Started
Specific Documentation

Getting Started

This is a step-by-step guide how to integrate the Click Jogos API in your game.

First, download the CJSDK.package, then in Unity menus go to Asset>Import Package>Custom Package, next accept and the CJSDK will be installed in the plugin folder.

Download CJSDK package

You need to create a GameObject for the CJAPI and a instance of the CJAPI

On the function Awake() you should then initialize the instances and the CJAPI. To initialize the API, after referencing it call the initialize(string, string) method and pass through your Developer Key and Game Key.

Obs: The Developer Key can be obtained in the edition of your developer profile after you register in the DevCenter Click Jogos, and the Game Key in the edition of the game after you register it with success in the DevCenter.

Read more and see the sample code

To make use of the events you can delegate them a function that will be executed everytime the event is triggered. To do so just declare on the Awake() method that you are adding that function to that event, in something like Event += Function.

All the functions need to receive only one parameter, a boolean, often put as “e” just for markup and be void (have no return value).

Read more and the sampler code

The functions on the CJAPI can be stored inside some instances (to be easier to know what are you dealing with) and some are general.

After adding all of event listener for the functions that you intent to use, you are able to call them.

See all API functions

Now you can send any event in your game to Click Jogos, so you need to create the stats and the achievements that will be delivered for users.

See how to create and submmit Stats See how to create Achievements

The submission process for games is very easy and simple, after insert the game name, the description, create stats and achievements, you just need to select the file of your game, insert the width and heigth of the frame, read and accept the terms of licence of the API, and submit.

Submit_en

After upload your game with success you will see a button where is possible take a preview of your game and test sending of stats and the delivering of achievements. This button can also be seen in the edition of your game.

Congrats_en

Downloading and Installing the CJSDK Package

You need to download the CJSDK.package, then in Unity menus go to Asset>Import Package>Custom Package, next accept and the CJSDK will be installed in the plugin folder.

Download CJSDK package

Initializing the API

You need to create a GameObject for the CJAPI and a instance of the CJAPI.

On the function Awake() you should then initialize the instances and the CJAPI. To initialize the API, after referencing it call the initialize(string, string) method and pass through your Developer Key and Game Key.

The CJAPI is now initialized.

Variables

Mainly right now the CJAPI has 2 main variables that are nested and can be accessed through CJApi.variable (or any other reference name that you are using instead of CJApi).

The variables are: username, it’s a string that contains the username of the user being updated if the user login or logout, and isSignedIn, a boolean that tells if the user is signed in the site or not, also updated if the user login or logout.

Events

To make use of the events you can delegate them a function that will be executed everytime the event is triggered. To do so just declare on the Awake() method that you are adding that function to that event, in something like Event += Function.

All the functions need to receive only one parameter, a boolean, often put as “e” just for markup and be void (have no return value).

Sample code for event listeners

Each event will be kept in its class, there are 3 possible classes: CJUserEvents, CJServicesEvents, and CJStatsEvents

Users Stats Services

The event onGetUsername() returns 'Guest' if the current user is not logged on, or if the user is logged returns the user name. The event onGetUsernameErrors() returns false for success and an array containing the errors.

The event onSubmitStat() returns true for sucess, returns an array with the data from the achievement if you have an achievement to be released, also returns the type of stat and its current value. The event onSubmitStatError() returns false for success and an array containing the errors.

The event onIsSignedIn() returns 'Guest' if the current user is not logged in, otherwise returns 'logged Username', where 'username' is the name of the logged in user. The event onIsSignedInError() returns false for success and an array containing the errors.