Unity SDK
Learn about the CrateBytes Unity SDK and how to use it.
CrateBytes Unity SDK
The CrateBytes Unity SDK provides a set of tools for implementing player authentication, session management, leaderboards, and metadata management in your Unity game. This document guides you through setup and usage of key features.
Installation
- Download the SDK: Visit the CrateBytes Unity SDK releases page to download the latest
.unitypackage
file. - Import the SDK: In Unity, go to
Assets > Import Package > Custom Package
, then select the downloaded.unitypackage
file to import. - Add the Prefab: Add the
CrateBytesManager
prefab to your scene to enable SDK functionality.
Initial Setup
-
Configure Project Key: Retrieve your Project Key from the CrateBytes Project Dashboard under Settings > API Keys. Add this Project Key to the
CrateBytesManager
component in your Unity scene. -
Add Namespace: To use the SDK functions in your scripts, add:
-
Initialize API Calls: Use the following syntax to call SDK functions:
Authentication
Guest Login
Logs in a player as a guest.
Parameters
playerId
(optional): A unique identifier for the player.callback
: Action to handle theGuestLoginResponse
.
Example
Steam Login
Logs in a player using a Steam authentication ticket.
Parameters
steamAuthTicket
: The player’s Steam authentication ticket obtained from Steamworks SDK.callback
: Action to handle theSteamLoginResponse
.
Example
Sessions
Start Session
Starts a new session for the player.
Parameters
callback
: Action called after the session starts.
Example
Heartbeat Session
Sends a heartbeat to keep the session active.
Example
End Session
Ends the current session.
Example
Leaderboards
Submit Score to Leaderboard
Submits a score to a specified leaderboard.
Parameters
leaderboardId
: The ID of the leaderboard.score
: The player’s score.callback
: Action called after the score is submitted.
Example
Get Leaderboard
Retrieves leaderboard data for a specific leaderboard ID.
Parameters
leaderboardId
: The ID of the leaderboard.page
(optional): The page number for leaderboard pagination.callback
: Action to handle theLeaderboardResponse
.
Example
Metadata
Get Metadata
Retrieves metadata information.
Example
Add/Update Metadata
Adds or updates metadata for the game.
Parameters
data
: The metadata to add or update.callback
: Action to call after the metadata is updated.
Example
Delete Metadata
Deletes the specified metadata.
Example
Additional Notes
- Prefab Requirement: Ensure the
CrateBytesManager
prefab is added to your scene. - Project Key: Retrieve your Project Key from the CrateBytes Dashboard for authentication setup.
- Callbacks: Always check the responses from callbacks to verify operation success.
For further support, create an issue at CrateBytes SDK GitHub Repository.