如何解决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();
}
}
解决方法
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
}
});
}
}
尝试使用 Social 而不是直接调用 Google Play 插件。如果我需要其他社交平台没有的特定功能,我只会直接调用插件。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。