如何在游戏开始前登录google play服务?
How to login to google play services before game starts?
我正在测试要在 Play 商店发布的游戏。一切似乎都运行良好,除了我有一个节点每次打开主菜单时都会登录 Google Play Games。我没想到它真的会登录,用控制器显示绿色 window,每次都显示所有内容。
我知道一定有办法做到这一点,但我就是不知道怎么做。在打开第一级之前,我需要连接到 Google Play Games。有人在介意帮助菜鸟之前做过这件事吗?
这仍然取决于您的实施。
Implementing player sign-in
If your game activity calls connect() in onStart(), the GoogleApiClient will attempt to sign in silently. If the user signed in successfully before and has not signed out, the system calls the onConnected() method. If sign in fails, the system calls the onConnectionFailed() method.
您可以检查启动时让玩家登录:
After users sign in successfully for the first time in your game, your game should sign them in automatically whenever they start the game again, until they explicitly sign out.
To add automatic sign-in, implement the following behavior in the onStart()
callback.
boolean mExplicitSignOut = false;
boolean mInSignInFlow = false; // set to true when you're in the middle of the
// sign in flow, to know you should not attempt
// to connect in onStart()
GoogleApiClient mGoogleApiClient; // initialized in onCreate
@Override
protected void onStart() {
super.onStart();
if (!mInSignInFlow && !mExplicitSignOut) {
// auto sign in
mGoogleApiClient.connect();
}
}
@Override
public void onClick (View view) {
if (view.getId() == R.id.sign_out_button) {
// user explicitly signed out, so turn off auto sign in
mExplicitSignOut = true;
if (mGoogleApiClient != null && mGoogleApiClient.isConnected()) {
Games.signOut(mGoogleApiClient);
mGoogleApiClient.disconnect();
}
}
// ...
}
希望对您有所帮助。
我正在测试要在 Play 商店发布的游戏。一切似乎都运行良好,除了我有一个节点每次打开主菜单时都会登录 Google Play Games。我没想到它真的会登录,用控制器显示绿色 window,每次都显示所有内容。
我知道一定有办法做到这一点,但我就是不知道怎么做。在打开第一级之前,我需要连接到 Google Play Games。有人在介意帮助菜鸟之前做过这件事吗?
这仍然取决于您的实施。
Implementing player sign-in
If your game activity calls connect() in onStart(), the GoogleApiClient will attempt to sign in silently. If the user signed in successfully before and has not signed out, the system calls the onConnected() method. If sign in fails, the system calls the onConnectionFailed() method.
您可以检查启动时让玩家登录:
After users sign in successfully for the first time in your game, your game should sign them in automatically whenever they start the game again, until they explicitly sign out.
To add automatic sign-in, implement the following behavior in the
onStart()
callback.
boolean mExplicitSignOut = false;
boolean mInSignInFlow = false; // set to true when you're in the middle of the
// sign in flow, to know you should not attempt
// to connect in onStart()
GoogleApiClient mGoogleApiClient; // initialized in onCreate
@Override
protected void onStart() {
super.onStart();
if (!mInSignInFlow && !mExplicitSignOut) {
// auto sign in
mGoogleApiClient.connect();
}
}
@Override
public void onClick (View view) {
if (view.getId() == R.id.sign_out_button) {
// user explicitly signed out, so turn off auto sign in
mExplicitSignOut = true;
if (mGoogleApiClient != null && mGoogleApiClient.isConnected()) {
Games.signOut(mGoogleApiClient);
mGoogleApiClient.disconnect();
}
}
// ...
}
希望对您有所帮助。