首页 > 解决方案 > Unity - 尝试使用 GooglePlay 服务将播放器登录到 GooglePlay

问题描述

我正在尝试使用 GooglePlay 服务将玩家登录到 GooglePlay。该应用程序已发布。开始游戏时,您应该使用 GooglePlay 自动登录,但没有任何反应。这是我使用的代码。如果有人可以在这个话题上帮助我,我将不胜感激。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using GooglePlayGames;
using UnityEngine.SocialPlatforms;
using GooglePlayGames.BasicApi;


public class GooglePlayServices : MonoBehaviour
{
    void Start()
    {
        Initialize();
    }
    private void Initialize()
    {
        PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder()
            .RequestServerAuthCode(false).
            Build();
        PlayGamesPlatform.InitializeInstance(config);
        PlayGamesPlatform.Activate();
        SignInUserWithPlayGames();
    }
    void SignInUserWithPlayGames()
    {
        PlayGamesPlatform.Instance.Authenticate(SignInInteractivity.CanPromptOnce, (success) =>
         {
             switch(success)
             {
                 case SignInStatus.Success:
                     Debug.Log("Signed in Player successfully");
                     break;
                 default:
                     Debug.Log("Login failed");
                     break;
             }
         });
    }

    public void SignInByHand()
    {
        PlayGamesPlatform.Instance.Authenticate(SignInInteractivity.CanPromptAlways, (success) =>
        {

        });
    }

    public void SignOut()
    {
        PlayGamesPlatform.Instance.SignOut();
    }
}

标签: c#unity3dgoogle-play-services

解决方案


private void Initialize()
{
    PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder().RequestServerAuthCode(false).Build();
    PlayGamesPlatform.InitializeInstance(config);
    PlayGamesPlatform.DebugLogEnabled = true;
    PlayGamesPlatform.Activate();
    SignInUserWithPlayGames();
}

void SignInUserWithPlayGames()
{
    if (!Social.localUser.authenticated)
    {
        Social.localUser.Authenticate(success => {
            if(success)
            {
                // signed in
            }
        });
    }
}

尝试使用社交而不是直接调用 Google Play 插件。如果我需要其他社交平台没有的特定功能,我只会直接调用插件。


推荐阅读