「Unity/GooglePlayGames/ver1」の版間の差分
(→PlayGameプラグインバージョンアップ) |
|||
| 行11: | 行11: | ||
error CS0117: 'PlayGamesPlatform' does not contain a definition for 'InitializeInstance' | error CS0117: 'PlayGamesPlatform' does not contain a definition for 'InitializeInstance' | ||
</pre> | </pre> | ||
| + | |||
| + | |||
| + | [[Unity/GooglePlayGames/ver2]] [ショートカット] 側参考 | ||
===firebaseのバージョンが11.8.0の場合=== | ===firebaseのバージョンが11.8.0の場合=== | ||
2025年7月3日 (木) 17:47時点における版
目次
PlayGameプラグインバージョンアップ
0.10.12から0.11.01に上げると以下エラーが出る
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'
Unity/GooglePlayGames/ver2 [ショートカット] 側参考
firebaseのバージョンが11.8.0の場合
PlayGameは0.10.12を使わないと、play-sevice周りのライブラリのバージョンが合わなくてエラーが出る。
設定
unityのGamePlayの初期設定
Assets/GooglePlayGames/GameInfo.cs
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 = "";
上の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"エラーが発生したとき
Android SDK Not found The Android SDK path was not found. Please configure it in the Unity preferences window (under External Tools).
UnityメインメニューのUnity/Settings/ExternalTools/AndroidSDKのrecommendチェックを外して、同じpathを欄に入れると、表示されなくなった。
androidビルドしたときに"Google Play Games not configured!"以下エラー
エラー詳細
Google Play Games not configured! Warning!! Google Play Games was not configured, Game Services will not work correctly.
AndroidSetupがうまくいってないので、↑の項目を確認する。
"Error SignInRequest Sign-in failed with status code: 10"エラーが発生するとき
PlayConsoleのアップロード鍵の証明書が表示されてるか確認する。
apkを上げてなければ、署名付きのapkをupして、アップロード鍵の証明書が表示されるか確認する
FirebaseAuthで連携する
- firebaseAuthのログイン情報のプロバイダにPlayGameを追加し、↑のウェブアプリケーションのクライアントIDとシークレットを登録する
- FirebaseのプロジェクトAndroidのSHA 証明書フィンガープリントに↑のフィンガープリントを追加
サンプル実行
PlayGameログインまで設定
初期設定
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();
ログインボタンを押したときのログイン成功処理
Social.localUser.Authenticate((bool success) => {
// handle success or failure
});
Authenticate実行で"APP ID IS NOT CORRECTLY CONFIGURED TO USE GOOGLE PLAY GAME SERVICES"エラー
PlayConsoleのテスターにandroidアカウントのメアドを登録するとよい。
fingerprintが一致しないエラー
エラー詳細
**** 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).
解決方法:playconsoleにアップロード鍵の証明書が登録されているか確認する。なければリリース用apkを追加して、鍵を追加する。
GetServerAuthCode取得
Social.localUser.Authenticate((bool success) => {
if (success) {
string authCode = PlayGamesPlatform.Instance.GetServerAuthCode();
}
});
authCodeは以下のようなフォーマットとなる
4/0AanRRruZXdYF-oq0ER57XxOgo9lBpHoNKAxdVPmYeiXIA9gI4zJpK8OSfAowK88D2JGxxx
successが失敗して、Error16がでる場合
エラー詳細
Error SignInRequest Setting result error status code to: 16
解決方法
playconsoleのplaygameのテスター数からメアドを登録すると通る。
PlayGameのFirebaseユーザ認証
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);
});
出力
User signed in successfully: hoge1 (pGb9NkG1Q3ZqURJQGLxvXaYXxxxx)
- firebaseのauthにユーザレコードが追加される。idはPlayGame名が追加され、ユーザーuidは、上のカッコ内の28文字ハッシュが追加される。
その他気づき
- PlayGame名に日本語名を入れてもそれが、idに入る。
- firebase登録後にPlayGameの名前を変えたときは、そのゲームにログインしてもFirebase側のidは変わらない。連携解除もされない。
PlayGameのFirebaseユーザ取得
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);
}
出力
playerName= uid=AgGbeT2LIeXWUIRk0uYbeYd4uExx
PlayGameのログアウト
Firebase.Auth.FirebaseAuth auth = Firebase.Auth.FirebaseAuth.DefaultInstance; auth.SignOut();
ログ出力
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
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つにいれる必要がある。
