查看: 2391|回复: 0
打印 上一主题 下一主题

[Unity 组件参考手册]桌面:网络参考指南之网络交互API

[复制链接]
.    

3797

主题

11

听众

5万

积分

首席设计师

Rank: 8Rank: 8

纳金币
32328
精华
41

活跃会员 优秀版主 荣誉管理 论坛元老

跳转到指定楼层
楼主
发表于 2013-2-19 17:09:47 |只看该作者 |倒序浏览
Social API is Unity's point of access to social features, such as:网络交互API是unity的访问网络交互(如:ios的GameCenter)的功能点。比如:    User profiles 用户配置文件
    Friends lists 好友列表
    Achievements 成就
    Statistics / Leaderboards 统计/排行榜It provides a unified interface to different social back-ends, such as XBox Live or GameCenter, and is meant to be used primarily by programmers on the game project.它在不同的网络交互(social)的两端(back-ends)提供了一个统一的接口,比如 XBox Live 或者 GameCenter,主要由程序员用于游戏项目上。The Social API is mainly an asynchronous API, and the typical way to use it is by making a function call and registering for a callback to when that function completes. The asynchronous function may have side effects, such as populating certain state variables in the API, and the callback could contain data from the server to be processed.网络交互API主要是一个异步API,使用它的典型方法是通过一个函数调用和在函数结束时注册一个回调函数。异步函数可能会有一些副作用,比如:在API中添入某些状态变量,回调可能包含数据,数据来自服务器或者是处理好的。The Social class resides in the UnityEngine namespace and so is always available but the other Social API classes are kept in their own namespace, UnityEngine.SocialPlatforms. Furthermore, implementations of the Social API are in a sub-namespace, like SocialPlatforms.GameCenter.Social 类是属于UnityEngine命名空间,所以可以直接使用,但是其他的网络交互API类都有自己的命名空间:UnityEngine.SocialPlatforms。 此外网络交互API的实现是在一个子命名空间,像这样:SocialPlatforms.GameCenter。Here is an example (JavaScript) of how one might use the Social API:下面是如何使用网络交互API的JavaScript例子:import UnityEngine.SocialPlatforms;function Start () {
// Authenticate and register a ProcessAuthentication callback
// 验证和注册一个ProcessAuthentication回调函数
// This call needs to be made before we can proceed to other calls in the Social API
//这个调用需要在其他网络交互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.
// 注意:如果操作陈功,Social.localUser将包含来自服务器的数据。
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 completes
// 当LoadAchievement调用完成时这个函数被调用。
function 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");
    });
}Here is the same example using C#.下面是C#的例子:using UnityEngine;
using UnityEngine.SocialPlatforms;public class SocialExample : MonoBehaviour {    void Start () {
// Authenticate and register a ProcessAuthentication callback
// 验证和注册一个ProcessAuthentication回调函数
// This call needs to be made before we can proceed to other calls in the Social API
//这个调用需要在其他网络交互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.
// 注意:如果操作陈功,Social.localUser将包含来自服务器的数据。
    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
// 当LoadAchievement调用完成时这个函数被调用。
    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");
        });
    }
}For more info on the Social API, check out the Social API Scripting Reference关于网络交互API的更多信息,请参考网络交互API的脚本参考
【来源:互联网】
更多精彩教程,尽在web3D纳金网http://www.narkii.com/college/
分享到: QQ好友和群QQ好友和群 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
转播转播0 分享淘帖0 收藏收藏0 支持支持0 反对反对0
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

关闭

站长推荐上一条 /1 下一条

手机版|纳金网 ( 闽ICP备08008928号

GMT+8, 2024-5-11 22:46 , Processed in 0.089992 second(s), 33 queries .

Powered by Discuz!-创意设计 X2.5

© 2008-2019 Narkii Inc.

回顶部