This page describes how to use the Game Chat Unity SDK.
Requirements
The specifications required to use the Game Chat Unity SDK are as follows.
Minimum specifications: 2018.4.0 or later
(If you need support for the lower version of Unity, then make an inquiry through Contact us.)
If you are a user of Unity editor in the 2019.4.X/2020.3.X/2021.1.X version, then make sure to use a version at or above 2019.4.29f1/2020.3.15f2/2021.1.16f1 respectively (versions where the Unity editor bug is fixed when building the AAB version).
Install SDK and configure environment
The following describes how to download Game Chat Unity SDK and configure a project in Unity.
Click the Settings > Download SDK menus, in that order, and then click Download Unity SDK.
Run Unity, and create a project.
In Unity, click the Assets > Import Package > Custom Package... menus, in that order.
Open the "GameChatUnitySDK_xxxxxxxx" file downloaded in the dashboard.
Select all files in the package, and then click the [Import] button.
Save the project.
Authentication
Reset Game Chat instance
To initialize Game Chat instances using the Game Chat project ID, use the code below.
GameChat.initialize(PROJECT_ID);// When using in the Singapore regionGameChat.setRegion("sg");GameChat.initialize(PROJECT_ID);
Connect to Game Chat socket server
The following describes how to connect to a Game Chat socket server.
Use the chat user ID to access a Game Chat socket server.
In a Game Chat project, the chat user ID is a unique value.
Get the token value for using the API.
The token value renewed can be viewed after GameChat.connect.
After acquiring the token value, check if the chat user information is renewed for the currently connected device.
The member data received with the GameChat.connect's callback is renewed data.
Use the following code to connect to the Game Chat socket server.
Use the following code to import channel data using the channel ID and unique ID.
//Put null in the CHANNEL_UNIQUE_ID parameter if you want to search only by CHANNEL_ID.//If both the CHANNEL_ID and CHANNEL_UNIQUE_ID values exist, then it searches by prioritizing the CHANNEL_UNIQUE_ID value.
GameChat.getChannel(CHANNEL_ID, CHANNEL_UNIQUE_ID, (Channel Channel,GameChatException Exception) => {if(Exception !=null) { // Error handlingreturn; } //handling channelInfo instance});
You must use an open API to create or delete a new channel within a project.
Due to security concerns, we recommend that you use an open API to create and update channels directly from Server to Server. For more information, see the Game Chat API Guide.
If the automatic translation feature is activated, then arbitrary text can be translated into the specified language. The automatic translation feature can be used after integrating with the Papago Translation service.
(Received) Translation Data Class (per Unit)
publicclassTranslation{publicstring detectLang ="";publicstring lang ="";publicbool translated =false;publicstring message ="";}
publicclassMember{publicstring id ="";publicstring project_id ="";publicstring nickname ="";publicstring profile_url ="";publicstring country ="";publicstring remoteip ="";publicstring adid ="";publicstring device ="";publicstring network ="";publicstring version ="";publicstring model ="";publicstring logined_at ="";publicstring created_at ="";publicstring updated_at ="";}
Chat user information update
You can update the user information of a chat server.
// Chat user nickname update// The strings allowed for nicknames are 2 to 128 characters in length, excluding whitespaces (spaces, tabs, and line breaks).
GameChat.setName(MEMBER_ID, NAME, (Member member,GameChatException Exception) => {if(Exception !=null) { // Error handlingreturn; } //handling updated Member instance});//Chat user profile image URL updateGameChat.setProfileUrl(MEMBER_ID, PROFILE_URL, (Member member,GameChatException Exception) => {if(Exception !=null) { // Error handlingreturn; } //handling updated Member instance});
GameChatExtension (Emoji, HyperLink)
This helper class facilitates easy handling of emojis and hyperlink text included in the received message.
Since TMP_GameChatTextUGUI is an extension class of TextMeshPro, a built-in asset of Unity, you must use first use Package Manager to install TextMeshPro.
The TextMeshPro asset is included as a built-in asset from Unity 2018.2 or later.
The default output of emoji sprite sheets is available from Emoji v13.0 (Android). You can change and customize the sprite sheet.
namespaceGameChatUnity.Extension{publicclassTMP_GameChatTextUGUI:TextMeshProUGUI { public bool isHyperLinked { get; set; } // Whether to process link-type addresses as hyperlinks (append html tag)
publicstring LinkTextColor { get; set; } // hyperlink text color }}
<Example>
usingGameChatUnity.Extension;TMP_GameChatTextUGUI message =msgObject.GetComponent<TMP_GameChatTextUGUI>();//Insert text through setMessage for hyperlink recognition and processing.message.setMessage(MESSAGE_CONTENT);message.color=Color.green;message.isHyperLinked=true;...msgObject =Instantiate(msgObject) asGameObject;...// Manually implement the click event listener for hyperlinks.//Handling with TMP_LinkInfoTMP_LinkInfo linkInfoArr =message.textInfo.linkInfo[LINK_INDEX];...