Unity's Social API

Source: Internet
Author: User

Sun Guangdong 2015.12.23


Social API

The social API is a point social feature that accesses unity, such as:
? User Configuration Files
? Friends List
? Achievement
? Statistics/Leaderboard

It offers different social backend, such as XBox Live or Gamecenter, a unified interface, primarily for use by programmers on game projects.

The social API is primarily an asynchronous API, and the typical way to use it is through a function call and registering a callback method to the function when it is completed. Asynchronous functions may have side effects, such as hyperplasia of certain state variables in the API, and callbacks may contain data from the server to process.

The social class resides in the Unityengine namespace, so it is always available, but other social API classes are saved in their own namespace, unityengine.socialplatforms. furthermore. In addition, the implementation of the social API is in a child namespace, such as Socialplatforms.gamecenter.
Here is an example (JavaScript) of how to use the social API:


Import Unityengine.socialplatforms;function Start () {//Authenticate and register a processauthentication callback This call needs to being made before we can proceed to other calls in the social API Social.localUser.Authenticate (Pr ocessauthentication);}  This function gets called when authenticate completes//Note that if the operation is successful, Social.localuser would Contain data from the server. function Processauthentication (Success:boolean) {if (success) {Debug.Log ("authenticated, checking Achieveme        NTS "); Request loaded achievements, and register a callback for processing them social.loadachievements (Processloadeda    chievements); } else Debug.Log ("Failed to Authenticate");} This function gets called when the loadachievement call Completesfunction processloadedachievements (Achievements:iach Ievement[]) {if (achievements.    Length = = 0) Debug.Log ("Error:no achievements found"); else Debug.Log ("Got"+ achievements.        Length + "achievements");        can also call to the functions like this social.reportprogress ("Achievement01", 100.0, function (result) {        if (result) Debug.Log ("Successfully reported achievement progress");    else Debug.Log ("Failed to report Achievement"); });}


the sameitis aUseC #Example


Using unityengine;using Unityengine.socialplatforms;public class Socialexample:monobehaviour {void Start () { Authenticate and register a processauthentication callback//This call needs to be made before we can proc    Eed to other calls in the social API Social.localUser.Authenticate (processauthentication); }//This function gets called when authenticate completes//Note that if the operation is successful, social.local     User'll contain data from the server. void Processauthentication (bool success) {if (success) {Debug.Log ("authenticated, checking Achieveme            NTS "); Request loaded achievements, and register a callback for processing them social.loadachievements (Processloa        dedachievements);    } else Debug.Log ("Failed to authenticate"); }//This function gets called when the loadachievement call completes void processloadedachievements (iachievement[ ] Achievements) {if (achievements.        Length = = 0) Debug.Log ("Error:no achievements found"); else Debug.Log ("Got" + achievements.             Length + "achievements");            can also call to the functions like this social.reportprogress ("Achievement01", 100.0, result = = {            if (result) Debug.Log ("Successfully reported achievement progress");        else Debug.Log ("Failed to report Achievement");    }); }}

For more information on the social API, see the Social API scripting reference

and see Also:gamecenterplatform. class



Unity's Social API

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.