Unity3.5 GameCenter基础教程(转载)
原地址:
http://forum.unity3d.com/threads/116901-Game-Center-Support/page3
using UnityEngine;
using UnityEngine.SocialPlatforms; public class Startup : MonoBehaviour
{
// we'll create some buttons in OnGui, allowing us to bump achievement and
// score values for testing private double ach1 = ;
private double ach2 = ;
private double ach3 = ;
private double ach4 = ; private long score1 = ;
private long score2 = ; private int buttonWidth = ;
private int buttonHeight = ;
private int buttonGap = ; void Start()
{
Social.localUser.Authenticate(HandleAuthenticated);
} // authentication private void HandleAuthenticated(bool success)
{
Debug.Log("*** HandleAuthenticated: success = " + success);
if (success) {
Social.localUser.LoadFriends(HandleFriendsLoaded);
Social.LoadAchievements(HandleAchievementsLoaded);
Social.LoadAchievementDescriptions(HandleAchievementDescriptionsLoaded);
}
} private void HandleFriendsLoaded(bool success)
{
Debug.Log("*** HandleFriendsLoaded: success = " + success);
foreach (IUserProfile friend in Social.localUser.friends) {
Debug.Log("* friend = " + friend.ToString());
}
} private void HandleAchievementsLoaded(IAchievement[] achievements)
{
Debug.Log("*** HandleAchievementsLoaded");
foreach (IAchievement achievement in achievements) {
Debug.Log("* achievement = " + achievement.ToString());
}
} private void HandleAchievementDescriptionsLoaded(IAchievementDescription[] achievementDescriptions)
{
Debug.Log("*** HandleAchievementDescriptionsLoaded");
foreach (IAchievementDescription achievementDescription in achievementDescriptions) {
Debug.Log("* achievementDescription = " + achievementDescription.ToString());
}
} // achievements public void ReportProgress(string achievementId, double progress)
{
if (Social.localUser.authenticated) {
Social.ReportProgress(achievementId, progress, HandleProgressReported);
}
} private void HandleProgressReported(bool success)
{
Debug.Log("*** HandleProgressReported: success = " + success);
} public void ShowAchievements()
{
if (Social.localUser.authenticated) {
Social.ShowAchievementsUI();
}
} // leaderboard public void ReportScore(string leaderboardId, long score)
{
if (Social.localUser.authenticated) {
Social.ReportScore(score, leaderboardId, HandleScoreReported);
}
} public void HandleScoreReported(bool success)
{
Debug.Log("*** HandleScoreReported: success = " + success);
} public void ShowLeaderboard()
{
if (Social.localUser.authenticated) {
Social.ShowLeaderboardUI();
}
} // gui public void OnGUI()
{
// four buttons, allowing us to bump and test setting achievements
int yDelta = buttonGap;
if (GUI.Button(new Rect(buttonGap, yDelta, buttonWidth, buttonHeight), "Ach 1")) {
ReportProgress("A0001", ach1);
ach1 = (ach1 == ) ? : ach1 + ;
}
yDelta += buttonHeight + buttonGap;
if (GUI.Button(new Rect(buttonGap, yDelta, buttonWidth, buttonHeight), "Ach 2")) {
ReportProgress("A0002", ach2);
ach2 = (ach2 == ) ? : ach2 + ;
}
yDelta += buttonHeight + buttonGap;
if (GUI.Button(new Rect(buttonGap, yDelta, buttonWidth, buttonHeight), "Ach 3")) {
ReportProgress("A0003", ach3);
ach3 = (ach3 == ) ? : ach3 + ;
}
yDelta += buttonHeight + buttonGap;
if (GUI.Button(new Rect(buttonGap, yDelta, buttonWidth, buttonHeight), "Ach 4")) {
ReportProgress("A0004", ach4);
ach4 = (ach4 == ) ? : ach4 + ;
}
// show achievements
yDelta += buttonHeight + buttonGap;
if (GUI.Button(new Rect(buttonGap, yDelta, buttonWidth, buttonHeight), "Show Achievements")) {
ShowAchievements();
} // two buttons, allowing us to bump and test setting high scores
int xDelta = Screen.width - buttonWidth - buttonGap;
yDelta = buttonGap;
if (GUI.Button(new Rect(xDelta, yDelta, buttonWidth, buttonHeight), "Score 1")) {
ReportScore("L01", score1);
score1 += ;
}
yDelta += buttonHeight + buttonGap;
if (GUI.Button(new Rect(xDelta, yDelta, buttonWidth, buttonHeight), "Score 2")) {
ReportScore("L02", score2);
score2 += ;
}
// show leaderboard
yDelta += buttonHeight + buttonGap;
if (GUI.Button(new Rect(xDelta, yDelta, buttonWidth, buttonHeight), "Show Leaderboard")) {
ShowLeaderboard();
}
}
}
Unity3.5 GameCenter基础教程(转载)的更多相关文章
- jQuery官方基础教程笔记(转载)
本文转载于阮一峰的博文,内容基础,结构清晰,是jquery入门不可多得的资料,非常好,赞一个. 阮一峰:jQuery官方基础教程笔记 jQuery是目前使用最广泛的javascript函数库. 据统计 ...
- [转载] 《Hadoop基础教程》之初识Hadoop
转载自http://blessht.iteye.com/blog/2095675 Hadoop一直是我想学习的技术,正巧最近项目组要做电子商城,我就开始研究Hadoop,虽然最后鉴定Hadoop不适用 ...
- 《Hadoop基础教程》之初识Hadoop(转载)
转载自博主:上善若水任方圆http://blessht.iteye.com/blog/2095675 Hadoop一直是我想学习的技术,正巧最近项目组要做电子商城,我就开始研究Hadoop,虽然最后鉴 ...
- [转载]Unity3D游戏引擎最详尽基础教程
原文地址:Unity3D游戏引擎最详尽基础教程作者:ShangShang 我一直向所有想做游戏的朋友推荐Unity3D,为什么呢?首先是因为专业,Unity3D非常强大,用它创建一个类似MiniGor ...
- <<Bootstrap基础教程>> 新书出手,有心栽花花不开,无心插柳柳成荫
并非闲的蛋疼,做技术也经常喜欢蛋疼,纠结于各种技术,各种需求变更,还有一个很苦恼的就是UI总是那么不尽人意.前不久自己开源了自己做了多年的仓储项目(开源地址:https://github.com/he ...
- html快速入门(基础教程+资源推荐)
1.html究竟是什么? 从字面上理解,html是超文本标记语言hyper text mark-up language的首字母缩写,指的是一种通用web页面描述语言,是用来描述我们打开浏览器就能看到的 ...
- 【Unity3D基础教程】给初学者看的Unity教程(四):通过制作Flappy Bird了解Native 2D中的RigidBody2D和Collider2D
作者:王选易,出处:http://www.cnblogs.com/neverdie/ 欢迎转载,也请保留这段声明.如果你喜欢这篇文章,请点[推荐].谢谢! 引子 在第一篇文章[Unity3D基础教程] ...
- WCF基础教程之异常处理:你的Try..Catch语句真的能捕获到异常吗?
在上一篇WCF基础教程之开篇:创建.测试和调用WCF博客中,我们简单的介绍了如何创建一个WCF服务并调用这个服务.其实,上一篇博客主要是为了今天这篇博客做铺垫,考虑到网上大多数WCF教程都是从基础讲起 ...
- Django 基础教程
Django 基础教程 这是第一篇 Django 简介 » Django 是由 Python 开发的一个免费的开源网站框架,可以用于快速搭建高性能,优雅的网站! 你一定可以学会,Django 很简单 ...
随机推荐
- CodeForces 733D Kostya the Sculptor
排序.把每一个长方体拆成$6$个做,然后排序做即可. #pragma comment(linker, "/STACK:1024000000,1024000000") #includ ...
- ARM开发板不工作的几个原因
刚焊了5块ARM(LPC2478)的开发板,上程序测试了一下,发现只有一个板子工作其他四个全部歇菜.努力地找了一会最终发现是板子的来个电阻焊翻了.因为是1206 的封装而且来个电阻在PCB上摆放的位置 ...
- cobol COMP-3最后1位
"C" hex is positive, "D" hex is negative, and "F" hex is unsigned.
- 解决cordova命令行方式下build或者run的时候报错问题
phonegap3.0之后就将项目的生成方式做了很大的更改,原来是在eclipse里面修改生成并编译运行,但是3.0之后它的目录结构发生了很大变化,只修改主目录下面的index.html如果不buil ...
- Linux下屏幕截图
Ubuntu使用教程——截屏 http://www.linuxidc.com/Linux/2014-02/96827.htm Ubuntu下使用(xfce截屏)及GNOME下一个好用的截屏工具 htt ...
- 【BZOJ 1027】 (凸包+floyd求最小环)
[题意] 某公司加工一种由铁.铝.锡组成的合金.他们的工作很简单.首先进口一些铁铝锡合金原材料,不同种类的原材料中铁铝锡的比重不同.然后,将每种原材料取出一定量,经过融解.混合,得到新的合金.新的合金 ...
- Codeforces 538 F. A Heap of Heaps
\(>Codeforces \space 538 F. A Heap of Heaps<\) 题目大意 :给出 \(n\) 个点,编号为 \(1 - n\) ,每个点有点权,将这些点构建成 ...
- B 君的第二题 (hongkong)
B 君的第二题 (hongkong) 题目大意: 一个长度为\(n(n\le2\times10^5)\)的数组,给定一个数\(k(k\le40)\).用\(a[i][j]\)表示该数组\(i\)次前缀 ...
- (原创)Stanford Machine Learning (by Andrew NG) --- (week 6) Advice for Applying Machine Learning & Machine Learning System Design
(1) Advice for applying machine learning Deciding what to try next 现在我们已学习了线性回归.逻辑回归.神经网络等机器学习算法,接下来 ...
- Problem G: 零起点学算法86——Fibonacc
#include<stdio.h> int main(){ ]={,,}; ;i<=;i++) { a[i]=a[i-]+a[i-]; } scanf("%d", ...