「Unity/GooglePlayGames/v1からv2へ移行」の版間の差分
(→PlayGamesClientConfigurationエラー対応方法) |
(→FirebaseのAuthStateChangedのタイミング変更) |
||
| (同じ利用者による、間の16版が非表示) | |||
| 行2: | 行2: | ||
Play Games サービス v2 に移行する(Unity) | Play Games サービス v2 に移行する(Unity) | ||
https://developer.android.com/games/pgs/unity/migrate-to-v2?hl=ja | https://developer.android.com/games/pgs/unity/migrate-to-v2?hl=ja | ||
| + | |||
| + | *Firebase:11.8.0 → 12.10.1 | ||
| + | *PlayGame:v.0.10.12→v.2.1.0 | ||
==SignOutエラー対応方法== | ==SignOutエラー対応方法== | ||
| 行11: | 行14: | ||
<pre> | <pre> | ||
- ((PlayGamesPlatform)Social.Active).SignOut(); | - ((PlayGamesPlatform)Social.Active).SignOut(); | ||
| − | + | </pre> | |
| + | 以下は、FirebaseのSignOutなので、これに書き換えると、Firebase認証がログアウトされるので、まずい。単純に、上記コードは、消すだけでよい。 | ||
| + | <pre> | ||
| + | Firebase.Auth.FirebaseAuth.DefaultInstance.SignOut(); | ||
</pre> | </pre> | ||
| 行66: | 行72: | ||
PlayGamesPlatform.Instance.Authenticate(processAuthentication); | PlayGamesPlatform.Instance.Authenticate(processAuthentication); | ||
</pre> | </pre> | ||
| + | |||
| + | ==version2では起動時に自動ログインされる== | ||
| + | https://developer.android.com/games/pgs/unity/migrate-to-v2?hl=ja | ||
| + | <pre> | ||
| + | ゲームが起動すると、自動ログインの試行が表示されます。 | ||
| + | </pre> | ||
| + | |||
| + | <pre> | ||
| + | Play Games サービス v2 SDK は、ユーザーのログインに関して v1 よりもいくつかの機能が強化されています。 | ||
| + | |||
| + | ユーザー向け: | ||
| + | ユーザー エクスペリエンスの向上: デフォルトのアカウントを選択すると、追加のプロンプトが表示されることなく自動的にログインされます。 | ||
| + | |||
| + | デベロッパー向け: | ||
| + | コード実装の簡素化: クライアントサイド コードでログイン / ログアウトのフローを処理する必要がなくなりました。ゲームの起動時にログインが自動的にトリガーされ、アカウント管理は OS 設定内で効率化されます。 | ||
| + | </pre> | ||
| + | |||
| + | |||
| + | 自動ログインについてのコミュニティ投稿 | ||
| + | https://www.reddit.com/r/Unity3D/comments/18th1y1/how_to_stop_auto_logging_into_google_play_games/?tl=ja | ||
| + | |||
| + | 個人ブログ | ||
| + | https://blog.scaredeer.com/2022/07/using-google-play-games-services-v2.html?utm_source=chatgpt.com | ||
| + | |||
| + | ==FirebaseのAuthStateChangedのタイミング変更== | ||
| + | AuthStateChangedのイベントタイミングが、v1とv2で、ズレてるので気をつける。 | ||
| + | |||
| + | <pre> | ||
| + | void InitializeFirebase() { | ||
| + | auth = Firebase.Auth.FirebaseAuth.DefaultInstance; | ||
| + | auth.StateChanged += AuthStateChanged; | ||
| + | AuthStateChanged(this, null); | ||
| + | } | ||
| + | |||
| + | void AuthStateChanged(object sender, System.EventArgs eventArgs) { | ||
| + | if (auth.CurrentUser != user) { | ||
| + | bool signedIn = user != auth.CurrentUser && auth.CurrentUser != null | ||
| + | && auth.CurrentUser.IsValid(); | ||
| + | if (!signedIn && user != null) { | ||
| + | DebugLog("Signed out " + user.UserId); | ||
| + | } | ||
| + | user = auth.CurrentUser; | ||
| + | if (signedIn) { | ||
| + | DebugLog("Signed in " + user.UserId); | ||
| + | displayName = user.DisplayName ?? ""; | ||
| + | emailAddress = user.Email ?? ""; | ||
| + | photoUrl = user.PhotoUrl ?? ""; | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | |||
| + | void OnDestroy() { | ||
| + | auth.StateChanged -= AuthStateChanged; | ||
| + | auth = null; | ||
| + | } | ||
| + | </pre> | ||
| + | 参考:https://firebase.google.com/docs/auth/unity/start?hl=ja | ||
| + | |||
| + | ==SignInStatus.Canceledが返ってくる場合== | ||
| + | SignInStatus.Canceledが実行される場合は、実機のPlayGameアプリ側で、連携が、ログアウトされてる可能性がある。 | ||
2025年8月28日 (木) 21:01時点における最新版
目次
v1からv2へ移行
Play Games サービス v2 に移行する(Unity) https://developer.android.com/games/pgs/unity/migrate-to-v2?hl=ja
- Firebase:11.8.0 → 12.10.1
- PlayGame:v.0.10.12→v.2.1.0
SignOutエラー対応方法
エラー詳細
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?)
対応方法
- ((PlayGamesPlatform)Social.Active).SignOut();
以下は、FirebaseのSignOutなので、これに書き換えると、Firebase認証がログアウトされるので、まずい。単純に、上記コードは、消すだけでよい。
Firebase.Auth.FirebaseAuth.DefaultInstance.SignOut();
GetServerAuthCodeエラー対応方法
エラー詳細
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?)
対応前
string authCode = PlayGamesPlatform.Instance.GetServerAuthCode();
対応後
PlayGamesPlatform.Instance.RequestServerSideAccess(
false,
authCode =>
{
try
{
Debug.Log("GooglePlaySignIn: RequestServerSideAccess Success: " + authCode);
}
catch (Exception ex)
{
Debug.LogError("Error getting credential: " + ex.Message);
}
}
);
PlayGamesClientConfigurationエラー対応方法
エラー詳細
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'
https://developer.android.com/games/pgs/unity/migrate-to-v2?hl=ja の対応の通り
対応後
Action<SignInStatus> processAuthentication = (SignInStatus status) =>
{
if (status == SignInStatus.Success)
{
// 成功
}
else
{
// 失敗
}
};
// GooglePlay認証開始
PlayGamesPlatform.Instance.Authenticate(processAuthentication);
version2では起動時に自動ログインされる
https://developer.android.com/games/pgs/unity/migrate-to-v2?hl=ja
ゲームが起動すると、自動ログインの試行が表示されます。
Play Games サービス v2 SDK は、ユーザーのログインに関して v1 よりもいくつかの機能が強化されています。
ユーザー向け:
ユーザー エクスペリエンスの向上: デフォルトのアカウントを選択すると、追加のプロンプトが表示されることなく自動的にログインされます。
デベロッパー向け:
コード実装の簡素化: クライアントサイド コードでログイン / ログアウトのフローを処理する必要がなくなりました。ゲームの起動時にログインが自動的にトリガーされ、アカウント管理は OS 設定内で効率化されます。
自動ログインについてのコミュニティ投稿
https://www.reddit.com/r/Unity3D/comments/18th1y1/how_to_stop_auto_logging_into_google_play_games/?tl=ja
個人ブログ https://blog.scaredeer.com/2022/07/using-google-play-games-services-v2.html?utm_source=chatgpt.com
FirebaseのAuthStateChangedのタイミング変更
AuthStateChangedのイベントタイミングが、v1とv2で、ズレてるので気をつける。
void InitializeFirebase() {
auth = Firebase.Auth.FirebaseAuth.DefaultInstance;
auth.StateChanged += AuthStateChanged;
AuthStateChanged(this, null);
}
void AuthStateChanged(object sender, System.EventArgs eventArgs) {
if (auth.CurrentUser != user) {
bool signedIn = user != auth.CurrentUser && auth.CurrentUser != null
&& auth.CurrentUser.IsValid();
if (!signedIn && user != null) {
DebugLog("Signed out " + user.UserId);
}
user = auth.CurrentUser;
if (signedIn) {
DebugLog("Signed in " + user.UserId);
displayName = user.DisplayName ?? "";
emailAddress = user.Email ?? "";
photoUrl = user.PhotoUrl ?? "";
}
}
}
void OnDestroy() {
auth.StateChanged -= AuthStateChanged;
auth = null;
}
参考:https://firebase.google.com/docs/auth/unity/start?hl=ja
SignInStatus.Canceledが返ってくる場合
SignInStatus.Canceledが実行される場合は、実機のPlayGameアプリ側で、連携が、ログアウトされてる可能性がある。
