Google Play Overview
GPGS版本:0.9.26
1. 開啟 CodeLab 連結
2. 下載 Sample Game 和 Google Play Service Plugin
3. Google Play Console 新增測試 App
4. 設定 Bundle ID 與 SHA1 連結應用程式
5. 設定成就與排行榜
6. 設定測試人員
Unity Overview
Unity版本:5.2.2f
1. 匯入 Lollygager Sample Game 和 Google Player Service Plugin
2. 設定 Google Play Service Android Configuration
3. 補齊 CodeLab 中的 UI 與程式功能
4. Build 測試
開啟 CodeLab 連結
下載 Sample Game 和 Google Play Service Plugin
匯入 Lollygagger Sample Game
設定 Bundle Identifier
由於是測試用專案,所以遊戲名稱可以隨便取
剪刀是直接叫 GooglePlayService
加入場景
將 MainMenu 和 GameScene 都加入 Build Settings
MainMenu 擺在第一個
建立測試用App
這裡測試用同樣可以隨便取名
剪刀的 App 與遊戲名稱
跟 Bundle ID 結尾一樣,取名叫 GooglePlayService
建立好後就跳到 Game Service 設定
連結 Android 應用程式
接下來要連結 APK,主要靠兩個東西
1. Bundle ID
2. SHA1
Bundle ID 我們已經取好了
SHA1 則是要透過 keystore 來產生
範例是使用 debugkey 來產生
不過剪刀已經有 keystore 了,就不用使用 debugkey
指令如下,由於使用 Windows 命令提示字元無法複製
可以在指令結尾加上 > Certificate.txt 輸出到一個檔案中
順便可以備份一下,之後還可以用
keytool -list -v -keystore ./yourKey.keystore -alias yourAlias > Certificate.txt
取得 Client ID
應用程式連結成功後會得到一組 Client ID
這組 ID 在 Unity 設定會使用到
設定成就和排行榜
按照 CodeLab 的第七、八步驟
先把成就和排行榜設一設
取得資源 XML
設定好成就和排行榜後
在其中一個頁面的底部可以點選 “取得資源”
把這個 XML 複製下來
待會 Unity 裡面一樣會用到
設定測試人員
記得要加入測試手機所登入的帳號
匯入 Google Play Service Plugin
開啟 Android 設定
Window => Google Play Games => Setup => Android setup…
Google Play Configuration
這裡有三個東西要設定
1. Contants class name: 隨便取,這邊一樣叫 GooglePlayService
2. Resources Definition: 在 Console 的成就和排行榜頁面中取得
3. Web App Client ID (Optional): 這裡寫到 Game Services 並不需要這個 ID,不過填上也無礙
複製貼上後點選 Setup 按鈕
如果出現找不到 google-play-services_lib 的錯誤
請先打開 Android 的 SDK Manager 下載
設定成功就會出現以下視窗
UI Setting
接下來就是把 CodeLab 的功能補齊
UI 的部分一開始只有 Start 按鈕
要把 Login、Show Achievement 與 Show LeaderBoard
這三顆按鈕補上並加上監聽事件
Google Play Service API
程式部分一樣要把功能都補上
API 整理如下
初始化:
PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder().Build(); PlayGamesPlatform.DebugLogEnabled = true; PlayGamesPlatform.InitializeInstance(config); PlayGamesPlatform.Activate();
帳號驗證:
後面的布林參數代表是否要 silent login
CodeLab 中一開始提到要設為 true
但剪刀並沒成功,各位可以再試試看
PlayGamesPlatform.Instance.Authenticate( SignInCallback, false );
成就與排行榜
// 顯示成就 PlayGamesPlatform.Instance.ShowAchievementsUI(); // 更新成就進度 PlayGamesPlatform.Instance.ReportProgress( AchieveID, progress, callback ); // 成就 ++ PlayGamesPlatform.Instance.IncrementAchievement( AchieveID, steps, callback ); // 顯示排行榜 PlayGamesPlatform.Instance.ShowLeaderboardUI(); // 更新分數 PlayGamesPlatform.Instance.ReportScore( score, ID, callback );
測試
測試時若還沒安裝 Google Play Games 要先安裝
若是一切沒問題,就可以成功看到登入頁面與遊戲的成就和排行榜了
如果還有問題,可以再確認以下幾點
1. Bundle ID 是否一致(Unity 和 Console)
2. Keystore 是否一致(Console 中的 SHA1 是否和 Unity 用的 keystore 是同一個)
3. Unity 中的 Google Play Console 是否漏設
4. 測試帳號有無新增
Reference
Google Play Game Services
Plugin for Unity (Github)
以上,希望有幫助到各位!
太神了
很高興對您有所幫助喔!
[…] Google Play Game Service CodeLab – Android Google Play Game Service – iOS Google Play Game Service 問題彙整 […]