The Evident project has two primary components: EVIDENT Platform and EVIDENT Serious Game. During the development of the Serious game, we faced the challenge of communication between the Game and the Platform. As the Serious game runs in different platforms, it is important to find a way to support seamless multi-platform connectivity. This creates an opportunity for us to present a quick guide for developing a Unity game that can communicate with different platforms.
Creating a WebGL version
In the WebGL version, the game receives input from the platform through the unityInstance.SendMessage function. The platform utilises the SendMessage function twice: (i) to send the user input and the game configuration information; and (ii) time to send the text which is translated according to user preferences.
The SendMessage function exchanges information through the json data format. Bellow you can see two examples of the format: one for the configurable fields and game configuration; and one for the language translations.
Configurable fields and game configuration
Section 1 refers to configurable fields and section 2 the game configuration. The parameters names (e.g. conf_field_1, appliance_breakdown, etc) are provided by the game developer.
Receive input from the platform
From the side of developers, some code is required to receive this input generated by the platform. This can be achieved by using the following two methods in C#, when the game starts.
Function TakeScenarioJSON() is used to receive user input and game configuration, while the TakeConfigurationJSON() function is used to parse the translations and to call a routine to change the game language accordingly.
Send the output to the platform
After the player finishes the game, the collected data should be dispatched to the platform. To support this, the platform already implements a read function, which should be used by the developer. To do this, create a file named MyPlugin.jlib inside the project folder and use the following C# code.
Then add the dll file in the script which returns the user’s request.
Now you can use the ParseUserAnswers method to return the answer to the platform. Make sure that the str parameter is a valid json. Your output should look like the following:
Creating a mobile version
The communication between the EVIDENT platform and the mobile application is achieved through an API.
In both Android and iOS, the user receives a unique code from the application, when the application starts. Using that unique code, the application returns the user’s answers to the platform when the game ends. Also, the application receives the configuration file as a second input.
When the platform identifies that a mobile browser is used to access it, it employs intents to open the application, as follows:
Using Android intent
Using iOS intent
In those cases, the android host, android scheme, android app package and IOS url scheme parameters are used (see next below).
Android Host, Scheme and App Package
To allow a mobile browser open a mobile application in Android, developers need to use intents and more specifically, to define the android host, android scheme, android app package. All these can be found at the manifest file. A simple application manifest can be found below:
In the above manifest, the android host is equivalent to “ANDROID_HOST“, the android scheme to “ANDROID_SCHEME” and the android app package to “ANDROID_APP_PACKAGE“.
In the above manifest, the android host is equivalent to “ANDROID_HOST“, the android scheme to “ANDROID_SCHEME” and the android app package to “ANDROID_APP_PACKAGE“.
iOS URL Schema
Receive input from the platform
Here is an example of code that receives the unique id and the configuration json. In this example, the getIntentData() method should be called in the Awake of a script.
Send the output to the platform
After the game is completed, you should send the collected data to the platform. To do so, send a message to the Endpoint with the data is. To reach the correct endpoint, you need the unique id from the input of the serious game in Android and iOS. The REST API endpoint for the Evident Serious game can be called in the form: