Unity Hand Travel Chat SDK integration and use a

Source: Internet
Author: User

There are chat functions in the hand tour, such as Guild, private chat, world chat, so find a good, powerful SDK can save a lot of energy, help us improve the speed of development and game quality.

Write a blog post is to facilitate the use of this SDK to do the chat module program, to avoid many pits, I in the study process, consulted the SDK developers a lot of problems, so I will detail the use of the process and the pit record down.

Integration Plug-in

I am using the Instant Messenger SDK provided by the pro-plus communication cloud, with the following address.

Here is a description of the document, please see the Instant Messenger cloud-enhanced version, which contains Unity's documentation:

Http://www.gotye.com.cn/docs.html?product=im&apiType=start
There is a unity version of the SDK plugin:
Http://www.gotye.com.cn/download.html

Probably using the process is to create a new unity project, in the editor mode to switch to the Android platform for editor debugging.

Import the Unity SDK plug-in package gotyeapi.unitypackage.

If prompted plugins/windows/32bit/gotyeapi.dll such as plug-ins and other conflicts, you can delete the Plugins/windows/32bit folder under the plug-in, because I am a 64-bit operating system, so plugins/windows/ The plugins in the 64bit folder are on the line.

Export Android Project

The Android package must first be exported to the Android project:

The Plugins/android/libs/armeabi folder and the plugins/android/libs/armeabi-v7a folder in the Unity Project plugin are then copied to the Libs folder in the exported Android project to replace it. Because the export Android project lacks libs.

Open the Android project with Ellipse:

File->import->anroid->existing Android Code into Workspace:next

Select the Android folder path, after import guarantee Libs is not missing, normal should be as follows:

Then open the Src->com.gotye.unitytest->unityplayernativeactivity.java file and initialize the SDK Gotypeapi inside:

In the @Override protected void onCreate (Bundle savedinstancestate) function, add the last line:

Gotyeapi.getinstance (). Init (Getapplicationcontext (), "19ff98c3-f93d-477f-81ba-be68859433a8", GotyeAPI.SCENE_ Unity3d);

Don't forget to add the namespaces: Import com.gotye.api.*;

The app key is changed to the appkey you applied for on the official website.

Then open the Android project root directory of the Androidmanifest.xml file, modify Appkey into your application on the official website Appkey, and save.

Android:value= "19ff98c3-f93d-477f-81ba-be68859433a8"

Ellipse Fat apk bag

File->export->anroid->export Android Application Next,

Select the project you want to export, continue next,

There is no keystore can, first create a, Testkey.keystore casually write, save in the root directory, fill in Paasword, repeat the password, Next,

In this way, select the address of the exported package, you can package the APK, and then through the DDMS can debug apk, view log. API Usage

usingUnityengine;usingSystem.Collections;usingGotye; Public classInitapi:gotyemonobehaviour { PublicGOTYEAPI API; voidAwake () {invokerepeating ("Mainloop",0.0f,0.050f); }    //Use this for initialization    voidStart () {API=gotyeapi.getinstance (); if(Application.platform! =runtimeplatform.android) {API. Init ("19ff98c3-f93d-477f-81ba-be68859433a8","Com.gotyeapi"); }        //for speech recognition, optionalAPI.            Initiflyspeechrecognition (); }            voidMainloop () {API.    Mainloop (); }}


It is important to note that there must be mainloop (), without which the server will not callback any client callbacks accordingly. The API is required in editor mode. Init (Appkey, "Com.gotyeapi"), the second parameter cannot be changed, the first parameter is changed to its own appkey. The following is a login callback script:
usingUnityengine;usingSystem.Collections;usingGotye; Public classLogin:gotyemonobehaviour, Loginlistener { PublicGOTYEAPI API; voidStart () {API=gotyeapi.getinstance (); Api. AddListener ( This); }     Public voidonlogin (gotyestatuscode code,gotyeuser user) {Debug.Log ("onlogin--"+ code +","+user.        Name); Api.        Reqfriendlist (); Api.    Beginreceiveofflinemessage (); }     Public voidonlogout (Gotyestatuscode code) {} Public voidonreconnecting (gotyestatuscode code, Gotyeuser currentUser) {}}

Similarly, you should write a script for each listener, similar to the login listener, in order to receive a response from the server.
This is done using:
API. Logout (); // Note that the second parameter of the login function must be NULL, otherwise the server callback to Login.cs's Onlogin callback code is a validation failure.  null);

Can be landed, the reason for the previous call logout, is to not exit the words, the first direct exit, and then landing.

Send a private conversation to a friend

Monitor Buddy Events:

usingUnityengine;usingSystem.Collections;usingGotye;usingSystem.Collections.Generic; Public classFriend:gotyemonobehaviour, Userlistener { PublicGOTYEAPI API;  PublicList<gotyeuser> friendlist =NewList<gotyeuser>(); voidStart () {API=gotyeapi.getinstance (); Api. AddListener ( This); }     Public voidonaddfriend (gotyestatuscode code,gotyeuser friend) {//After you've added a friend, refresh your friends listAPI.    Reqfriendlist (); }     Public voidOngetfriendlist (Gotyestatuscode code,list<gotyeuser>list) {Friendlist=list; }}

The following code can be called in the login successful callback Onlogin:

Add Friends:

// account "Zhangsan" must exist in order to add a friend success, callback to implement the Userlistener interface class. API. Reqaddfriend (new Gotyeuser ("zhangsan"));

Get a list of friends:

Api. Reqfriendlist ();

Send a private chat to a friend:

// receiver can use the friend account name of the new one
gotyeuser Receiver = new Gotyeuser ("Zhangsan"); Gotyemessage msg = gotyemessage.createtextmessage (receiver, content); Api. SendMessage (msg);

After sending, Zhangsan will receive the message: Onreceivemessage.

The text message is sent.

Next, I will study the SDK voice Chat feature.

Unity Hand Travel Chat SDK integration and use a

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.