Skip to content

Instantly share code, notes, and snippets.

@mikamikuh
Created December 16, 2012 18:06
Show Gist options
  • Save mikamikuh/4310446 to your computer and use it in GitHub Desktop.
Save mikamikuh/4310446 to your computer and use it in GitHub Desktop.
using UnityEngine;
using System.Collections;
using UnityEngine.SocialPlatforms;
using UnityEngine.SocialPlatforms.GameCenter;
public class GameCenterConnector : MonoBehaviour
{
// GameCenterのユーザ認証を行う
void Start ()
{
Social.localUser.Authenticate (success =>
{
if (success)
{
Debug.Log("Authentication Successful");
string userInfo = "Username:" + Social.localUser.userName + "¥nUser ID:" + Social.localUser.id + "¥nInUnderage:" + Social.localUser.underage;
Debug.Log(userInfo);
}
else
{
Debug.Log("Failed");
}
});
}
void OnGUI()
{
// スコアの送信
if (GUI.Button(new Rect(0, 0, 200, 50), "Send Score"))
{
int score = 10;
Social.ReportScore(score, "me.mkgames.touchandcrash.highscore", SendScoreCallback);
}
// 実績の送信
if (GUI.Button(new Rect(0, 100, 200, 50), "Send Achievement"))
{
Social.ReportProgress("me.mkgames.touchandcrash.achievement", 50.0f, SendAchievementCallback);
}
// スコアボードの閲覧
if (GUI.Button(new Rect(0, 200, 200, 50), "Show LeaderBoard"))
{
Social.ShowLeaderboardUI();
}
// 実績の閲覧
if (GUI.Button(new Rect(0, 300, 200, 50), "Show Achievement"))
{
Social.ShowAchievementsUI();
}
}
// スコアの送信が完了したときに呼ぶ関数
void SendScoreCallback(bool isSuccess)
{
Debug.Log("Send Score Finished:" + isSuccess);
}
// 実績の送信が完了したときに呼ぶ関数
void SendAchievementCallback(bool isSuccess)
{
Debug.Log("Send Achievement Finished:" + isSuccess);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment