Unity SDK Getting Started Guide
Overview
You can use AccelByte Cloud's Unity SDK to help implement AccelByte Cloud services in your game. The SDK acts as a bridge between your game and our services, making those services easy to access.
Prerequisites
Tutorials
Follow the tutorials below to learn how to set up our Unity SDK.
Install AccelByte Cloud's Unity SDK Plugin
There are two different ways to install the Unity plugin: from the source code or from the package. Make sure you've already configured the game client before installing the Unity plugin.
From the Source Code
Create a file for Game Client configuration named AccelByteSDKConfig.json.
Copy the AccelByteSDKConfig.json file to the Assets/Resource directory.
Fill in the AccelByteSDKConfig.json with the information based on your game. Here is the contents of the JSON file:
{
"PublisherNamespace": "PUBLISHER_NAMESPACE",
"Namespace": "GAME_NAMESPACE",
"UseSessionManagement": true,
"BaseUrl": "https://api.demo.accelbyte.io/",
"LoginServerUrl": "https://api.demo.accelbyte.io/",
"IamServerUrl": "https://api.demo.accelbyte.io/iam",
"PlatformServerUrl": "https://api.demo.accelbyte.io/platform",
"BasicServerUrl": "https://api.demo.accelbyte.io/basic",
"LobbyServerUrl": "wss://api.demo.accelbyte.io/lobby/",
"CloudStorageServerUrl": "https://api.demo.accelbyte.io/binary-store",
"TelemetryServerUrl": "https://api.demo.accelbyte.io/telemetry",
"GameProfileServerUrl": "https://api.demo.accelbyte.io/soc-profile",
"StatisticServerUrl": "https://api.demo.accelbyte.io/statistic",
"LeaderboardServerUrl": "https://api.demo.accelbyte.io/leaderboard",
"AgreementServerUrl": "https://api.demo.accelbyte.io/agreement",
"ClientId": "GAME_CLIENT_ID",
"ClientSecret": "GAME_CLIENT_SECRET",
"RedirectUri": "http://127.0.0.1"
}Note
Leave the Client Secret empty if the Game Client uses Public Client Type.
Copy the AccelByteServerSDKConfig.json from the repository and add it to your project in the Assets/Resource directory.
Fill in the AccelByteServerSDKConfig.json with code below that'll be reserved as the Game Server configuration. Here is the contents of the JSON file:
{
"PublisherNamespace": "PUBLISHER_NAMESPACE",
"Namespace": "GAME_NAMESPACE",
"BaseUrl": "https://api.demo.accelbyte.io/",
"DSMServerUrl": "https://api.demo.accelbyte.io/dsm",
"IamServerUrl": "https://api.demo.accelbyte.io/iam",
"ClientId": "GAME_SERVER_ID",
"ClientSecret": "GAME_SERVER",
"RedirectUri": "http://127.0.0.1"
}NOTE
For game servers, you need to define the Client Secret since Game Server uses Confidential Client Type.
For the next steps, it depends on your game.
From the Package
Download the Unity package.
Open the Unity package using the Unity Editor and select all of the components, including any API you want to use.
NOTE
- You can exclude any API that you're sure you won't use, such as CloudStorage, Telemetry, etc. If you need these APIs at a later date, you'll be able to import them without having to reinstall the Unity plugin.
Click Import and wait for the installation to finish.
Plugin Usage
Here's an example of how to use AccelByte Cloud's Unity SDK to create a new user profile. Please note that you must be authorized before you can implement any backend services.
using AccelByte.Api;
using AccelByte.Models;
using AccelByte.Core;
class MainMenu
{
public void OnLoginClick(string email, string password)
{
var user = AccelBytePlugin.GetUser();
user.LoginWithUsername(email, password,
result =>
{
if (result.IsError)
{
Debug.Log("Login failed");
}
else
{
Debug.Log("Login successful");
}
});
}
public void OnCreateProfileClick()
{
var userProfiles = AccelBytePlugin.GetUserProfiles();
userProfiles.CreateUserProfile(
new CreateUserProfileRequest
{
language = "en",
timeZone = "Asia/Jakarta",
firstName = "John",
lastName = "Doe",
dateOfBirth = "2000-01-01"
},
result =>
{
if (result.IsError)
{
Debug.Log("Creating user profile failed");
}
else
{
Debug.Log("User profile created.");
Debug.Log("First Name: " + result.firstName);
Debug.Log("Last Name: " + result.lastName);
}
});
}
}
Debug Log
AccelByte Cloud's Unity SDK includes a debug log, which appears both in the Unity editor and on a player's device. You can filter which types of messages are included in this log, or even disable the log altogether. Disabling the log can be useful in the build process to skip logs from the AccelByte services.
The log is enabled by default. To disable it, open the AccelByteSDKConfig.json file and change the EnableDebugLog value to false. To enable the log again, just change this value back to true.
{
...
"UsePlayerPrefs": false,
"EnableDebugLog": true,
"DebugLogFilter": "log",
…
}
You can also filter which messages are included in the log by defining the Log Type, as seen below:
Log Type | Remarks |
---|---|
Log | This is the default setting, used to display all log messages |
Warning | Display warning, assert, error, and exception log messages |
Assert | Display assert, error, and exception log messages |
Error | Display error and exception log messages |
Exception | Display exception log messages |
Here's an example of how to apply filtering messages based on the Log Type. You can make this change in AccelByteSDKConfig.json.
{
...
"UseSessionManagement": true,
"UsePlayerPrefs": false,
"EnableDebugLog": true,
"DebugLogFilter": "log",
…
}
Related Concepts
- Make sure you check out our guide on Authorization and Authentication, you'll need it to implement our services in your game.
- The Initial Setup guides will provide you with additional information about how to get started using our services.