Created
April 11, 2016 12:01
-
-
Save kankikuchi/6035770eb285ce8e8cf83b3a9fde8100 to your computer and use it in GitHub Desktop.
プラグインを書かずにGoogle Play Game Servicesのランキングとアチーブメントを実装【Unity】【Android】【アセット】
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// AndroidRankingUtility.cs | |
// http://kan-kikuchi.hatenablog.com/entry/AndroidRankingUtility | |
// | |
// Created by kan.kikuchi on 2016.04.01. | |
using UnityEngine; | |
using System; | |
using System.Collections; | |
using System.Collections.Generic; | |
/// <summary> | |
/// Androidのランキング用便利クラス | |
/// </summary> | |
public static class AndroidRankingUtility { | |
//コールバック | |
private static Action<bool> _reportScoreCallBack; | |
private static Action<bool> _reportProgressCallBack; | |
//================================================================================= | |
//初期化 | |
//================================================================================= | |
/// <summary> | |
/// ユーザー認証 | |
/// </summary> | |
public static void Auth(Action<bool> callBack = null){ | |
//コールバックが設定されていない場合はログを設定 | |
if(callBack == null){ | |
callBack = (success) => { | |
Debug.Log(success ? "認証成功" : "認証失敗"); | |
}; | |
} | |
//コールバックを登録して、接続 | |
GooglePlayManager.ActionScoreSubmited += ReportScoreCallBack; | |
GooglePlayManager.ActionAchievementUpdated += ReportProgressCallBack; | |
GooglePlayConnection.ActionConnectionResultReceived += (result) =>{ | |
callBack(result.IsSuccess); | |
}; | |
GooglePlayConnection.Instance.Connect ();; | |
} | |
//================================================================================= | |
//ランキング | |
//================================================================================= | |
/// <summary> | |
/// リーダーボードを表示する | |
/// </summary> | |
public static void ShowLeaderboardUI(){ | |
GooglePlayManager.Instance.ShowLeaderBoardsUI (); | |
} | |
/// <summary> | |
/// リーダーボードにスコアを送信する | |
/// </summary> | |
public static void ReportScore (string leaderboardID, long score, Action<bool> callBack = null){ | |
//コールバックが設定されていない場合はログを設定 | |
if(callBack == null){ | |
callBack = (success) => { | |
Debug.Log(success ? "スコア送信成功" : "スコア送信失敗"); | |
}; | |
} | |
_reportScoreCallBack = callBack; | |
GooglePlayManager.Instance.SubmitScoreById (leaderboardID, score); | |
} | |
//スコア送信後のコールバック | |
private static void ReportScoreCallBack(GP_LeaderboardResult result){ | |
_reportScoreCallBack(result.IsSucceeded); | |
} | |
//================================================================================= | |
//実績 | |
//================================================================================= | |
/// <summary> | |
/// 実績一覧を表示する | |
/// </summary> | |
public static void ShowAchievementsUI(){ | |
GooglePlayManager.Instance.ShowAchievementsUI (); | |
} | |
/// <summary> | |
/// 実績の進捗状況を送信する | |
/// </summary> | |
public static void ReportProgress(string achievementKey, Action<bool> callBack = null){ | |
//コールバックが設定されていない場合はログを設定 | |
if(callBack == null){ | |
callBack = (success) => { | |
Debug.Log(success ? "進捗送信成功" : "進捗送信失敗"); | |
}; | |
} | |
_reportProgressCallBack = callBack; | |
GooglePlayManager.Instance.UnlockAchievementById(achievementKey); | |
} | |
//実績送信後のコールバック | |
private static void ReportProgressCallBack(GP_AchievementResult result){ | |
_reportProgressCallBack(result.IsSucceeded); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment