「Unity/GooglePlayGames」の版間の差分

提供: 初心者エンジニアの簡易メモ
ナビゲーションに移動 検索に移動
編集の要約なし
4行目: 4行目:


[[Unity/GooglePlayGames/ver2]]
[[Unity/GooglePlayGames/ver2]]
===PlayGameプラグインバージョンアップ===
0.10.12から0.11.01に上げると以下エラーが出る
<pre>
error CS1061: 'PlayGamesPlatform' does not contain a definition for 'SignOut' and no accessible extension method 'SignOut' accepting a first argument of type 'PlayGamesPlatform' could be found (are you missing a using directive or an assembly reference?)
error CS1061: 'PlayGamesPlatform' does not contain a definition for 'GetServerAuthCode' and no accessible extension method 'GetServerAuthCode' accepting a first argument of type 'PlayGamesPlatform' could be found (are you missing a using directive or an assembly reference?)
error CS0246: The type or namespace name 'PlayGamesClientConfiguration' could not be found (are you missing a using directive or an assembly reference?)
error CS0117: 'PlayGamesPlatform' does not contain a definition for 'InitializeInstance'
</pre>
===firebaseのバージョンが11.8.0の場合===
PlayGameは0.10.12を使わないと、play-sevice周りのライブラリのバージョンが合わなくてエラーが出る。
===play管理画面設定===
#play.google.com/consoleで、ユーザを増やす/PlayGamesサービスを設定する
#Google Cloud Platformで、APIとサービス/OAuth 同意画面を作成する→外部ユーザで作る。承認済みドメインはfirebaseのurlとか?使う。(例:hoge-xxxx.firebaseapp.com)
#play.google.com/consoleの、テストとリリース/設定/アプリの署名/アップロード鍵の証明書のSHA-1証明書のフィンガープリントをコピー
#Google Cloud Platformで、APIとサービス/認証情報から上部の認証情報を作成を選択、OAuthクライアントを選択→Androidを選択→上のSHA-1証明書のフィンガープリントを貼り付け→jsonダウンロード(クライアントidがある)
#Google Cloud Platformで、APIとサービス/認証情報から上部の認証情報を作成を選択、OAuthクライアントを選択→ウェブ アプリケーションを選択→jsonダウンロード(クライアントidとクライアントシークレットがある)
#play.google.com/consoleで、ユーザを増やす/PlayGamesサービスのAndroidとゲームサーバに、上記クライアントを、それぞれ登録する
#play.google.com/consoleのPlayGameの[テスター] ページで、Play Store にゲームをリリースする前に、ゲームにログインできるようにするユーザーのメールアドレスを追加。
====play.google.com/consoleにクラアントが出ない====
登録直下はクラアントがでないので、20分ぐらい待って更新押したりすると、クライアントが選択できるようになる。
====コマンドでSHA取得====
keytool -exportcert -list -v -alias release_aleas_hoge1 -keystore /d/src/android/release_hoge1.keystore
===公開設定===
#play.google.com/consoleのPlayGameの公開ページで、エラーメッセージが出る項目を登録しておく。
==設定==
===unityのGamePlayの初期設定===
Assets/GooglePlayGames/GameInfo.cs
<pre>
public const string ApplicationId = ""; // Filled in automatically
public const string IosClientId = "__IOS_CLIENTID__"; // Filled in automatically
public const string WebClientId = ""; // Filled in automatically
public const string NearbyConnectionServiceId = "";
</pre>
上のClientIdなどをいれる。
===Google Play GamesのAndroid Setupの設定===
公式:https://firebase.google.com/docs/auth/unity/play-games?hl=ja
#unityのplatformをAndroidにする。
#unityメインメニューから[Window] > [Google Play Games] > [Setup] > [Android Setup] を開き、
#Directory to save Constantに、Assets/GooglePlayGamesを入れる
#WebAppClientIdに、上の項目で入れた、ウェブアプリケーションのClientIdをいれる。
Assets/GooglePlayGames/Plugins/Android/GooglePlayGamesManifest.plugin/AndroidManifest.xml に APP_IDが入ることを確認。
====[Window] > [Google Play Games] > [Setup]でAndroidSetupが選択できないとき====
#unityのplatformをAndroidにする。
====AndroidSetup実行中に"Android SDK Not found"エラーが発生したとき====
<pre>
Android SDK Not found
The Android SDK path was not found. Please configure it in the Unity preferences window (under External Tools).
</pre>
UnityメインメニューのUnity/Settings/ExternalTools/AndroidSDKのrecommendチェックを外して、同じpathを欄に入れると、表示されなくなった。
====androidビルドしたときに"Google Play Games not configured!"以下エラー====
エラー詳細
<pre>
Google Play Games not configured!
Warning!! Google Play Games was not configured, Game Services will not work correctly.
</pre>
AndroidSetupがうまくいってないので、↑の項目を確認する。
===="Error SignInRequest Sign-in failed with status code: 10"エラーが発生するとき====
PlayConsoleのアップロード鍵の証明書が表示されてるか確認する。
apkを上げてなければ、署名付きのapkをupして、アップロード鍵の証明書が表示されるか確認する
==FirebaseAuthで連携する==
#firebaseAuthのログイン情報のプロバイダにPlayGameを追加し、↑のウェブアプリケーションのクライアントIDとシークレットを登録する
#FirebaseのプロジェクトAndroidのSHA 証明書フィンガープリントに↑のフィンガープリントを追加
==サンプル実行==
===PlayGameログインまで設定===
初期設定
<pre>
using GooglePlayGames;
using GooglePlayGames.BasicApi;
using UnityEngine.SocialPlatforms;
using System.Threading.Tasks;
PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder()
    .RequestServerAuthCode(false /* Don't force refresh */)
    .Build();
PlayGamesPlatform.InitializeInstance(config);
PlayGamesPlatform.Activate();
</pre>
ログインボタンを押したときのログイン成功処理
<pre>
Social.localUser.Authenticate((bool success) => {
  // handle success or failure
});
</pre>
====Authenticate実行で"APP ID IS NOT CORRECTLY CONFIGURED TO USE GOOGLE PLAY GAME SERVICES"エラー====
PlayConsoleのテスターにandroidアカウントのメアドを登録するとよい。
====fingerprintが一致しないエラー====
エラー詳細
<pre>
**** APP NOT CORRECTLY CONFIGURED TO USE GOOGLE PLAY GAME SERVICES
**** DEVELOPER_ERROR
**** This is usually caused by one of these reasons:
**** (1) Your package name and certificate fingerprint do not match
****    the client ID you registered in Developer Console.
**** (2) Your App ID was incorrectly entered.
**** (3) Your game settings have not been published and you are
****    trying to log in with an account that is not listed as
****    a test account.
**** (4) A server auth code was requested, but an incorrect client
****    id was provided. The client id for server auth codes should
****    be the client id for the game server (not the android app).
</pre>
解決方法:playconsoleにアップロード鍵の証明書が登録されているか確認する。なければリリース用apkを追加して、鍵を追加する。
===GetServerAuthCode取得===
<pre>
Social.localUser.Authenticate((bool success) => {
  if (success) {
    string authCode = PlayGamesPlatform.Instance.GetServerAuthCode();
  }
});
</pre>
authCodeは以下のようなフォーマットとなる
4/0AanRRruZXdYF-oq0ER57XxOgo9lBpHoNKAxdVPmYeiXIA9gI4zJpK8OSfAowK88D2JGxxx
====successが失敗して、Error16がでる場合====
エラー詳細
Error SignInRequest Setting result error status code to: 16
解決方法
playconsoleのplaygameのテスター数からメアドを登録すると通る。
===PlayGameのFirebaseユーザ認証===
<pre>
Firebase.Auth.FirebaseAuth auth = Firebase.Auth.FirebaseAuth.DefaultInstance;
Firebase.Auth.Credential credential = Firebase.Auth.PlayGamesAuthProvider.GetCredential(authCode);
auth.SignInAndRetrieveDataWithCredentialAsync(credential).ContinueWith(task => {
if (task.IsCanceled)
{
    Debug.LogError("SignInAndRetrieveDataWithCredentialAsync was canceled.");
    return;
}
if (task.IsFaulted)
{
    Debug.LogError("SignInAndRetrieveDataWithCredentialAsync encountered an error: " + task.Exception);
    return;
}
Firebase.Auth.AuthResult result = task.Result;
Debug.LogFormat("User signed in successfully: {0} ({1})",
    result.User.DisplayName, result.User.UserId);
});
</pre>
出力
<pre>
User signed in successfully: hoge1 (pGb9NkG1Q3ZqURJQGLxvXaYXxxxx)
</pre>
*firebaseのauthにユーザレコードが追加される。idはPlayGame名が追加され、ユーザーuidは、上のカッコ内の28文字ハッシュが追加される。
その他気づき
*PlayGame名に日本語名を入れてもそれが、idに入る。
*firebase登録後にPlayGameの名前を変えたときは、そのゲームにログインしてもFirebase側のidは変わらない。連携解除もされない。
===PlayGameのFirebaseユーザ取得===
<pre>
Firebase.Auth.FirebaseUser user = auth.CurrentUser;
if (user != null && user.IsValid())
{
    string playerName = user.DisplayName;
    // The user's Id, unique to the Firebase project.
    // Do NOT use this value to authenticate with your backend server, if you
    // have one; use User.TokenAsync() instead.
    string uid = user.UserId;
    Debug.Log("playerName=" + playerName);
    Debug.Log("uid=" + uid);
}
</pre>
出力
<pre>
playerName=
uid=AgGbeT2LIeXWUIRk0uYbeYd4uExx
</pre>
===PlayGameのログアウト===
<pre>
Firebase.Auth.FirebaseAuth auth = Firebase.Auth.FirebaseAuth.DefaultInstance;
auth.SignOut();
</pre>
ログ出力
<pre>
Debug FirebaseAuth Notifying id token listeners about a sign-out event.
Debug FirebaseAuth Notifying auth state listeners about a sign-out event.
Info TRuntime.CctTransportBackend Making request to: ttps://firebaselogging-pa.googleapis.com/v1/firelog/legacy/batchlog
Info TRuntime.CctTransportBackend Status Code: 200
</pre>
==PlayGameとEmailが連携した場合==
firebaseのauthのユーザレコードに1行レコードがあり、PlayGameアイコンとEmailアイコンが並ぶ。
==PlayConsole公開用アプリでPlayGame認証する場合==
公開前であれば、アップロード鍵の証明書のsha1を以下3つに入れればよかったが、
* FirebaseのプロジェクトAndroidのSHA 証明書フィンガープリント
* Google Cloud Platformで、APIとサービス/認証情報から上部の認証情報を作成を選択、OAuthクライアントを選択→Androidを選択→上のSHA-1証明書のフィンガープリントを貼り付け
* play.google.com/consoleで、ユーザを増やす/PlayGamesサービスのAndroid
PlayConsole経由でDLする場合は、アプリ署名鍵の証明書のsha1を上の3つにいれる必要がある。

2025年7月3日 (木) 08:45時点における版