Platform | version |
Unity | 2019.4.15f1 and above |
Android | Android Studio 3.5 and above, App requires Android 4.1 and above |
iOS | Xcode 11.0 and above,Please ensure that your project has a valid developer signature certificate. |



{"dependencies": {"com.tencent.imsdk.unity": "https://github.com/TencentCloud/chat-sdk-unity.git#unity"}}

public static void Init() {int sdkappid = 0;SdkConfig sdkConfig = new SdkConfig();sdkConfig.sdk_config_config_file_path = Application.persistentDataPath + "/TIM-Config";sdkConfig.sdk_config_log_file_path = Application.persistentDataPath + "/TIM-Log"; // Set local log addressTIMResult res = TencentIMSDK.Init(long.Parse(sdkappid), sdkConfig);}public static void Login() {if (userid == "" || user_sig == ""){return;}TIMResult res = TencentIMSDK.Login(userid, user_sig, (int code, string desc, string json_param, string user_data)=>{// callback after login});}
using com.tencent.imsdk.unity.uikit;// The demo login logic is as followspublic static void Init() {Core.SetConfig(sdkappid, userId, sdkUserSig);Core.Init();Core.Login();}// If you run the unity demo directly, it is recommended to log in through the mobile phone number/verification code input box on the Main page. It can ensure the normal operation of callbacks and so on.// Since Unity on the computer does not support mobile phone number login, please enter userid into the mobile phone number input box and userSig into the verification code input box.// Assets/Example/Scripts/Main.csprivate void Login(){// Comment out the previous Login function content and add the following contentloginButton.interactable = false;Core.SetConfig(Config.sdkappid, phoneNumber.text, captcha.text);Core.Init();Core.Login(HandleAfterLogin);loginButton.interactable = true;}

Main.cs (login interface) and Chat.cs (chat interface).Prefabs, you can modify the display content and style by modifying Prefabs.ConvMessagePanelConversationNamePanelMessageContentPanelActionPanelOverlayPanelCloseButton
Script/Components/Conversation.cs. Styles for each conversation are in ConversationItem.prefabs.FriendPanelSearchPanelConversationListPanel
World, Channel, Team, Friends. The first three channels are group chat channels, and the friend channel is a c2c channel and will display a list of c2c conversations. Click events and styles for channel buttons are in Script/Components/Chat.cs.MessageSenderPanelMessageContentPanelSenderNamePanelMessageSenderIcon and TextPanelusing com.tencent.imsdk.unity.uikit;// The demo login logic is as followspublic static void Init() {Core.SetConfig(sdkappid, userId, sdkUserSig);Core.Init();Core.Login();// you can pass function// Core.Login(HandleAfterLogin);}// If you run the unity demo directly, it is recommended to log in through the mobile phone number/verification code input box on the Main page. It can ensure the normal operation of callbacks and so on.// Since Unity on the computer does not support mobile phone number login, please enter userid into the mobile phone number input box and userSig into the verification code input box.// Assets/Example/Scripts/Main.csprivate void Login(){// Comment out the previous Login function content and add the following contentloginButton.interactable = false;Core.SetConfig(Config.sdkappid, phoneNumber.text, captcha.text);Core.Init();Core.Login(HandleAfterLogin);loginButton.interactable = true;}
World, Channel, Team, and Friends. Among them, the Friends channel displays a list of C2C sessions and added friends, click on a session to start chatting.create_group in the background RestAPI. See Link for details.Assets/Example/Scripts/Config/Config.cs, fill in the group ID of the created group into communityID (community), channelID (channel), groupID (team).
And call joinGroup after login to enter the corresponding group after login and send messages in the group.UserProfileCustemStringInfo teer = new UserProfileCustemStringInfo{user_profile_custom_string_info_key:"rank",user_profile_custom_string_info_value:"teer"}List<UserProfileCustemStringInfo> customArray = new List<UserProfileCustemStringInfo>();customArray.Add(teer);TencentIMSDK.ProfileModifySelfUserProfile(new UserProfileItem{user_profile_item_custom_string_array:customArray;});
completeConvList. The final friend session information displayed is in the friendProfiles list.GenerateList (conversation list rendering) in Conversation.csRenderMessageForScroll of Chat.cs (if you need to modify other display content, you can also get it from here)MsgItem.csOverlayPanel in Chat.cs using StickerPanel. You can import your own emoji to use. (You need to import your own emojis in advance)Assets/Resources folder
Texture Type of the image to Sprite (2D and UI), and modify the Pixels Per Unit according to the size of the image.
// Generate a list of emojis, StickerPackage is a set of emojisList<StickerPackage> stickers = new List<StickerPackage> {new StickerPackage {name = "4350",baseUrl = "custom_sticker_resource/4350",menuItem = new StickerItem {name = "menu@2x",index = 0,},stickerList = new List<StickerItem> {new StickerItem { // emoji package dataname = "menu@2x",index = 0},}}};
using com.tencent.imsdk.unity.uikit;Core.SetStickerPackageList(Config.stickers);
Resources/LanguageTxt. Now contains Chinese.txt(Simplified Chinese) and English.txt(English) for simplified Chinese and English. If you need other languages, you can add the corresponding txt file.
The structure of the file is as follows://English.txtKey: Value//Chinese.txtKey: value
Language in LanguageDataManager.cs, and add the corresponding Key in LanguageTextName.private Dictionary<string,string> EnglishDictionary = new Dictionary<string,string>();LoadLanguageTxt(Language. English);
LanguageUIText(Script) component to the text component that needs to be set, and select the Key of the word to be displayed. The displayed Key corresponds to the enum in LanguageTextName and the Key in the vocabulary file.

SetCurrentLanguageValue when the software starts. If you want to fix the language, you can directly assign a value to currentLanguage in LanguageDataManager.cs (it can be used as the default language). The Demo judges and assigns values according to the system language.sdkappid, userid and usersig.using com.tencent.imsdk.unity.uikit;Core.SetConfig(sdkappid, userid, usersig);
AddRecvNewMsgCallback and SetConvEventCallback callbacks will be automatically bound.using com.tencent.imsdk.unity.uikit;Core.Init();
SetStickerPackageList.using com.tencent.imsdk.unity.uikit;Core.SetStickerPackageList(Config.stickers);
Login, and execute the bound callback function after the login is completed.using com.tencent.imsdk.unity.uikit;Core.Login((params string[] args) => {});
OnMsgListChanged event.using com.tencent.imsdk.unity.uikit;Core.SetMessageList(currentConvID, newMsgList, isFinished);
OnCurrentConvChanged event.using com.tencent.imsdk.unity.uikit;Core.SetMessageList(convID, convType);
OnCurrentStickerIndexChanged event.using com.tencent.imsdk.unity.uikit;Core.SetMessageList(stickerIndex);
using com.tencent.imsdk.unity.uikit;Core.Logout((string[] parameters) => {// Logout callback});
TencentChatSDK to get other chatting related functions. For example, get user information through TencentChatSDK.using com.tencent.imsdk.unity;FriendShipGetProfileListParam param = new FriendShipGetProfileListParam{friendship_getprofilelist_param_identifier_array = new List<string>{"self_userid"}};TIMResult res = TencentIMSDK.ProfileGetUserProfileList(param, (int code, string desc, List<UserProfile> profile, string user_data)=>{});
Feedback