unity的 Social API介紹

來源:互聯網
上載者:User

unity的 Social API介紹
Social API

Social API 是訪問的Unity 的point 社會功能,如:
• 使用者設定檔
• 好友名單
• 成就
• 統計 / 熱門排行榜

     它提供了不同的social 後端,如 XBox Live 或 GameCenter,一個統一的介面,主要為了由程式員在遊戲項目上使用。

  Social API 主要是非同步 API,並使用它的典型方式是 通過一個函數調用 和註冊一個回調方法向該函數完成時。非同步函數可能有副作用,如 增生某些狀態變數在 API 中,和回調可能包含來自伺服器要處理的資料。

   Social 類駐留在 UnityEngine 命名空間中,所以始終是可用,但其他社會 API 類都儲存在自己的命名空間,UnityEngine.SocialPlatforms. Furthermore。此外,Social  API 的實現是在子命名空間,如 SocialPlatforms.GameCenter。
     在這裡是一個例子 (JavaScript) 如何使用Social  API:

import UnityEngine.SocialPlatforms;function Start () {    // Authenticate and register a ProcessAuthentication callback    // This call needs to be made before we can proceed 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.localUser will contain data from the server. function ProcessAuthentication (success: boolean) {    if (success) {        Debug.Log ("Authenticated, checking achievements");        // Request loaded achievements, and register a callback for processing them        Social.LoadAchievements (ProcessLoadedAchievements);    }    else        Debug.Log ("Failed to authenticate");}// This function gets called when the LoadAchievement call completesfunction ProcessLoadedAchievements (achievements: IAchievement[]) {    if (achievements.Length == 0)        Debug.Log ("Error: no achievements found");    else        Debug.Log ("Got " + achievements.Length + " achievements");        // You can also call into 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");    });}

 

同樣的這是使用c#樣本
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 proceed 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.localUser will contain data from the server.     void ProcessAuthentication (bool success) {        if (success) {            Debug.Log ("Authenticated, checking achievements");            // Request loaded achievements, and register a callback for processing them            Social.LoadAchievements (ProcessLoadedAchievements);        }        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");             // You can also call into 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");        });    }}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.