孙广东  2015.12.23

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 completes
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");
});
}
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");
});
}
}

对Social API的很多其它信息。看看Social API脚本參考

还有 See Also: GameCenterPlatform.类

unity的 Social API的更多相关文章

  1. Unity的常用API

    1.Event Function:事件函数   Reset() :被附加脚本时.在游戏物体的组件上按Reset时会触发该事件函数 Start() :在游戏初始化时会执行一次 Update() :每一帧 ...

  2. Unity 相关经典博客资源总结(持续更新)

    就作为一个记录吧,把平时看过的Unity相关的一些好的Blog记录并分享. 好的论坛: Unity官方脚本  点评:这个不用说了,最核心的内容,理解整个Unity引擎的方方面面,梳理结构. Unity ...

  3. HoloLens开发手记 - Unity development overview 使用Unity开发概述

    Unity Technical Preview for HoloLens最新发行版为:Beta 24,发布于 09/07/2016 开始使用Unity开发HoloLens应用之前,确保你已经安装好了必 ...

  4. Unity Assets目录下的特殊文件夹名称

    1.隐藏文件夹以.开头的文件夹会被Unity忽略.在这种文件夹中的资源不会被导入,脚本不会被编译.也不会出现在Project视图中.2.Standard Assets在这个文件夹中的脚本最先被编译.这 ...

  5. 【Unity基础知识之三】Unity Assets目录下的特殊文件夹名称

    Unity3D的特殊目录名称   Unity预留了一些目录名称,这些目录有着特殊的含义.比较重要的有: Resources这个目录下的所有文件都会被打包到发布版本中,程序可以通过文件路径来访问它们.这 ...

  6. unity两点之间抛物线,完美金手指

    学校享受的日子一去不复还了,呜呜.话说面试了几个公司,真心没准备好就上了,结果当然是小悲催.还好有容身之处,就算是搬砖,也有可能为自己盖楼,吼吼. 好,下面我来分享一道有意思的面试题,说他有意思,是因 ...

  7. C#程序员整理的Unity 3D笔记(十):Unity3D的位移、旋转的3D数学模型

    遇到一个想做的功能,但是实现不了,核心原因是因为对U3D的3D数学概念没有灵活吃透.故再次系统学习之—第三次学习3D数学. 本次,希望实现的功能很简单: 如在小地图中,希望可以动态画出Player当前 ...

  8. 【转】Unity 相关经典博客资源总结(持续更新)

    原文:http://blog.csdn.net/prothi/article/details/20123319 就作为一个记录吧,把平时看过的Unity相关的一些好的Blog记录并分享. 好的论坛: ...

  9. Unity 触屏缩放模型

    现在的手机都是触屏控制的,那么在游戏中我们想通过手指在屏幕上滑动捕获相应的动作呢?Unity官网API中提供了Input类和Touch类,在该类里提供了许多接口.相信只要我们稍微看下,就可以自己应用了 ...

随机推荐

  1. SharePoint Online 创建文档库

    前言 本文介绍如何在Office 365中创建文档库,以及文档库的一些基本设置. 正文 通过登录地址登录到Office 365的SharePoint Online站点中,我们可以在右上角的设置菜单中, ...

  2. 2016 移动应用质量大数据报告--转自腾讯Bugly

    2016年,在“互联网+”战略的推动下,移动互联网与越来越多传统行业的结合更加紧密,用户使用移动互联网的工作场景.生活场景.消费场景都在悄然发生着改变, 移动互联网产品在智能硬件.医疗.汽车.旅游.教 ...

  3. [Web 前端] this作用域问题

    如何不用这种写法:理想的写法是this.setState({ .... }) 可能是我没有描述清楚,我不想用这种学法而已,这样多了一个变量,我觉得很不舒服.我尝试了先把 setState 赋值到变量里 ...

  4. TeXworks使用教程指南

    TeXworks是Windows版本的TeX Live默认提供的编辑器.值得注意的是,TeXworks 是XeTeX 作者 Jonathan Kew 开发的,其特点是界面简洁友好,集成了轻便的 PDF ...

  5. Installing Hyperledger Fabric v1.1 on Ubuntu 16.04 — Part I

    There is an entire library of Blockchain APIs which you can select according to the needs that suffi ...

  6. 洛谷P1972 [SDOI2009]HH的项链 题解

    [SDOI2009]HH的项链 题目背景 无 题目描述 HH 有一串由各种漂亮的贝壳组成的项链.HH 相信不同的贝壳会带来好运,所以每次散步完后,他都会随意取出一段贝壳,思考它们所表达的含义.HH 不 ...

  7. [已解决]下载chromium源码 download_from_google_storage 无法下载文件

    当使用 gclient runhooks 后 出现下面的错误 File gs://chromium-gn/1088992877b3a13f25b61c8fc18e25296d8cab33 for sr ...

  8. CPLUSPLUS 获得 一个源文件的头文件依赖。即该文件所需要的所有头文件

    核心命令:gcc -M *.h.*.cpp 转: 自动处理头文件的依赖关系 http://blog.csdn.net/su_ocean16/article/details/5374696 现在我们的M ...

  9. google chrome 删除重复的书签 about sync

    之前 由于 谷歌 同步的不智能,且不询问用户同步方法和细节,导致我的书签包括了大量重复的书签,想去除重复的书签. 由于谷歌书签文件 存储在:C:\Documents and Settings\Admi ...

  10. qt.qpa.plugin: Could not find the Qt platform plugin "windows" in ""

    转载:https://forum.qt.io/topic/97484/qt-5-12-make-mingw-32-release/12 I build Qt 5.12 with MinGW 7.3.0 ...