Initial configuration
Before building your chat app, you must initialize and configure the Unity Chat SDK.
Start by signing into the Admin Portal or creating an account if you don't have one yet.
Then, create an app on the Admin Portal. You will need a PubNub app to get a keyset that consists of a Subscribe Key and a Publish Key. These keys will let you establish a connection between PubNub and the chat app you're going to create with the Unity Chat SDK.
When you create a new app on the Admin Portal, the first set of demo keys is generated automatically, but a single app can have as many keysets as you like. We recommend that you create separate keysets for production and test environments.
Enable features on your keyset
Each keyset has its own configuration settings in the Admin Portal. To use some features in your chat app, you must enable appropriate settings on your app's keyset on the Admin Portal.
To use the Chat SDK, create or update users, track presence, and store messages in history, you must enable App Context, Presence, and Message Persistence.
Download the SDK
Download the SDK from any of the following sources:
Get the source code
https://github.com/pubnub/unity-chat.git?path=/unity-chat/PubnubChatUnity/Assets/PubnubChat
Install via Package Manager
-
Open Unity Editor and navigate to Window -> Package Manager.
-
In the Package Manager window, click + and select Add package from git URL.
-
Paste the PubNub Unity package link and click Add.
https://github.com/pubnub/unity-chat.git?path=/unity-chat/PubnubChatUnity/Assets/PubnubChat
Initialize PubNub
Once you have a PubNub account and an app created on the Admin Portal, you can start initializing PubNub Client API context and establish account-level credentials.
To initialize PubNub with the Unity Chat SDK, create a new Chat
object.
var chat = new Chat(new PubnubChatConfig(
"PublishKey",
"SubscribeKey",
"UserId")
);
Input parameters
Parameter | Type | Required | Default | Feature | Description |
---|---|---|---|---|---|
PublishKey | string | Yes | n/a | Send messages | Specifies the key used to publish messages on a channel. |
SubscribeKey | string | Yes | n/a | Receive messages | Specifies the key used to subscribe to a channel. |
UserId | string | Yes | n/a | n/a | Unique User ID that becomes your app's current user. It's a string of up to 92 characters that identifies a single client (end user, device, or server) that connects to PubNub. Based on User ID, PubNub calculates pricing for your apps' usage. User ID should be persisted and remain unchanged. If you don't set userId , you won't be able to connect to PubNub. |
AuthKey | string | No | n/a | Access Manager | Authentication key for Access Manager. Use it for all requests made to PubNub APIs to authenticate users in your application and grant them access to PubNub resources (other users' metadata and channels). |
TypingTimeout | int | No | 5000 | Typing Indicator | Specifies the default timeout after which the typing indicator automatically stops when no typing signals are received. The default and maximum value is set to 5000 milliseconds (5 seconds). |
TypingTimeoutDifference | int | No | 1000 | Typing Indicator | Specifies the difference in time between actually sending the typing indicator and the value of TypingTimeout . This is designed to cover for any network lag that may occur. If you set the TypingTimeout to 5 seconds and the TypingTimeoutDifference to 1 second, the typing signal stops between the fourth and fifth second. The default value is set to 1000 milliseconds (1 second). |
StoreUserActivityTimestamp | bool | No | false | User's last online activity, global presence | Specifies if you want to track the user's global presence in your chat app. The user's activity is tracked through the LastActiveTimeStamp parameter on the User object. |
StoreUserActivityInterval | int | No | 600000 | User's last online activity, global presence | Specifies how often the user global presence in the app should be updated. Requires StoreUserActivityTimestamp to be set to true . The default value is set to 600000 milliseconds (10 minutes), and the minimum possible value is 60000 milliseconds (1 minute). If you try to set it to a lower value, you'll get the StoreUserActivityInterval must be at least 60000ms error. |
Output parameters
Type | Description |
---|---|
Chat | Object returning a new PubNub chat instance. |
Next steps
Now that you've initialized and configured the Unity Chat SDK, you can start creating channels, adding users, and powering your app with all sorts of features.