C# Unity Google Play服务:身份验证始终失败:
我的身份验证有问题。身份验证总是失败,我无法理解原因(不仅在编辑器中失败,在我的设备中也失败)。代码如下:C# Unity Google Play服务:身份验证始终失败:,c#,authentication,google-play-services,google-play-games,unity5,C#,Authentication,Google Play Services,Google Play Games,Unity5,我的身份验证有问题。身份验证总是失败,我无法理解原因(不仅在编辑器中失败,在我的设备中也失败)。代码如下: using UnityEngine; using UnityEngine.SceneManagement; using UnityEngine.UI; using UnityEngine.Advertisements; using System.Collections; using System.Collections.Generic; using GooglePlayGam
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using UnityEngine.Advertisements;
using System.Collections;
using System.Collections.Generic;
using GooglePlayGames;
using UnityEngine.SocialPlatforms;
using GooglePlayGames.BasicApi;
using UnityEngine.Analytics;
public class Menu : MonoBehaviour {
public Text record;
/**
Menu when the player isn´t authenticate
*/
public GameObject signIn;
public GameObject test;
void Awake()
{
PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder ().Build ();
PlayGamesPlatform.InitializeInstance(config);
GooglePlayGames.PlayGamesPlatform.DebugLogEnabled = false;
GooglePlayGames.PlayGamesPlatform.Activate ();
}
void Start()
{
Advertisement.Initialize ("CORRECT_NUMBER", true);
if (PlayerPrefs.HasKey("record"))
{
record.text = "Record actual: " + PlayerPrefs.GetInt("record");
Analytics.CustomEvent ("Start Play", new Dictionary<string, object>{ { "Record", PlayerPrefs.GetInt("record")} });
if (Social.localUser.authenticated)
{
Social.ReportScore (PlayerPrefs.GetInt ("record"), "CORRECT_CODE", (bool success) => { });
}
} else {
record.text = "Consigue un record!!";
}
if (Social.localUser.authenticated)
{
signIn.SetActive (false);
}
test.SetActive (false);
}
public void OnPlay()
{
ShowAd ();
SceneManager.LoadScene("Play");
Time.timeScale = 0;
}
public void OnArchievements()
{
if (Social.localUser.authenticated) {
Social.ShowAchievementsUI ();
} else {
Social.localUser.Authenticate ((bool success) => {
if (success) {
Social.ShowAchievementsUI ();
}
});
}
}
public void OnMatching()
{
if (Social.localUser.authenticated) {
Social.ShowLeaderboardUI ();
} else {
Social.localUser.Authenticate ((bool success) => {
if (success) {
Social.ShowLeaderboardUI ();
}
});
}
}
public void OnExit()
{
Analytics.CustomEvent ("Stop Play", new Dictionary<string, object>{ { "Record", PlayerPrefs.GetInt("record")} });
Application.Quit();
}
public void SignIn()
{
Social.localUser.Authenticate((bool success) => {
if (success)
{
Debug.Log ("Sign in");
signIn.SetActive (false);
}
else
{
Debug.Log ("Fail for some reason...");
test.SetActive (true);
}
});
}
public void Later()
{
signIn.SetActive (false);
}
public void ShowAd()
{
if (Advertisement.IsReady())
{
Advertisement.Show();
}
}
}
使用UnityEngine;
使用UnityEngine.SceneManagement;
使用UnityEngine.UI;
使用UnityEngine。广告;
使用系统集合;
使用System.Collections.Generic;
使用谷歌游戏;
使用UnityEngine.SocialPlatform;
使用GooglePlayGames.BasicApi;
使用UnityEngine.Analytics;
公共类菜单:MonoBehavior{
公共文本记录;
/**
当播放机未进行身份验证时的菜单
*/
公共游戏对象登录;
公开游戏对象测试;
无效唤醒()
{
PlayGamesClientConfiguration配置=新建PlayGamesClientConfiguration.Builder().Build();
PlayGamesPlatform.InitializeInstance(配置);
GooglePlayGames.PlayGamesPlatform.DebugLogEnabled=false;
GooglePlayGames.PlayGamesPlatform.Activate();
}
void Start()
{
广告。初始化(“正确的号码”,true);
如果(PlayerPrefs.HasKey(“记录”))
{
record.text=“实际记录:”+PlayerPrefs.GetInt(“记录”);
Analytics.CustomEvent(“开始播放”,新字典{{“记录”,PlayerPrefs.GetInt(“记录”)});
if(Social.localUser.authenticated)
{
Social.ReportScore(PlayerPrefs.GetInt(“record”),“CORRECT_CODE”,(bool success)=>{});
}
}否则{
record.text=“Consigue un record!!”;
}
if(Social.localUser.authenticated)
{
signIn.SetActive(假);
}
test.SetActive(假);
}
公开播放
{
ShowAd();
场景管理器。加载场景(“播放”);
Time.timeScale=0;
}
公共档案无效()
{
if(Social.localUser.authenticated){
Social.ShowAchievementsUI();
}否则{
Social.localUser.Authenticate((bool成功)=>{
如果(成功){
Social.ShowAchievementsUI();
}
});
}
}
匹配时的公共无效()
{
if(Social.localUser.authenticated){
Social.ShowLeaderboardUI();
}否则{
Social.localUser.Authenticate((bool成功)=>{
如果(成功){
Social.ShowLeaderboardUI();
}
});
}
}
公开无效OnExit()
{
Analytics.CustomEvent(“停止播放”,新字典{{“记录”,PlayerPrefs.GetInt(“记录”)});
Application.Quit();
}
公共无效签名()
{
Social.localUser.Authenticate((bool success)=>{
如果(成功)
{
调试日志(“登录”);
signIn.SetActive(假);
}
其他的
{
Log(“由于某种原因失败…”);
test.SetActive(真);
}
});
}
稍后公开作废()
{
signIn.SetActive(假);
}
公开无效ShowAd()
{
if(advision.IsReady())
{
广告秀;
}
}
}
对象“test”只是一个白框,似乎知道身份验证失败。控制台没有显示任何类型的错误,因此我不知道在哪里可以找到问题。。。知道有什么问题吗?PD:我使用版本0.9.34和Unity 5.3.5f1
提前谢谢 没问题。
我将在这里写下回应,因为它可能相当长
Unity的默认平台设置为Apple。在执行“PlayGamesClientConfiguration”时,您将默认的ISocialPlatform更改为Google+
我的评论是关于Awake()函数的。我建议您将其放在Start()中,如下所示:
void Start()
{
//added code
PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder ().Build ();
PlayGamesPlatform.InitializeInstance(config);
GooglePlayGames.PlayGamesPlatform.DebugLogEnabled = false;
//GooglePlayGames.PlayGamesPlatform.Activate (); //this is wrong
//WHAT YOU ARE MISSING
PlayGamesPlatform.Activate();
//END OF WHAT YOU ARE MISSING
Advertisement.Initialize ("CORRECT_NUMBER", true);
if (PlayerPrefs.HasKey("record"))
{
record.text = "Record actual: " + PlayerPrefs.GetInt("record");
Analytics.CustomEvent ("Start Play", new Dictionary<string, object>{ { "Record", PlayerPrefs.GetInt("record")} });
//you should do this once the user is authenticated and logged in
if (Social.localUser.authenticated)
{
Social.ReportScore (PlayerPrefs.GetInt ("record"), "CORRECT_CODE", (bool success) => { });
}
} else {
record.text = "Consigue un record!!";
}
if (Social.localUser.authenticated)
{
signIn.SetActive (false);
}
test.SetActive (false);
}
CallBackFunction是一个接受bool的void函数。(您这样做是正确的)我喜欢让我的代码易读易懂
void ProcessAuthentication (bool success)
{
if (true == success)
{
Debug.Log ("AUTHENTICATED!");
if (Social.localUser.authenticated)
{
Social.ReportScore (PlayerPrefs.GetInt ("record"), "CORRECT_CODE", (bool success) => { });
}
} else {
record.text = "Consigue un record!!";
}
if (Social.localUser.authenticated)
{
signIn.SetActive (false);
//EDIT: you need to load the achievements to use them
Social.LoadAchievements (ProcessLoadedAchievements);
Social.LoadScores(leaderboardID, CALLBACK) // Callback has to be a Action<IScore[]> callback
}
test.SetActive (false);
}
else
{
Debug.Log("Failed to authenticate");
signIn.SetActive (true);
}
}
void ProcessLoadedAchievements (IAchievement[] achievements) {
if (achievements.Length == 0)
{
Debug.Log ("Error: no achievements found");
}
else
{
Debug.Log ("Got " + achievements.Length + " achievements");
}
}
void进程身份验证(bool成功)
{
if(true==成功)
{
Log(“已验证!”);
if(Social.localUser.authenticated)
{
Social.ReportScore(PlayerPrefs.GetInt(“record”),“CORRECT_CODE”,(bool success)=>{});
}
}否则{
record.text=“Consigue un record!!”;
}
if(Social.localUser.authenticated)
{
signIn.SetActive(假);
//编辑:您需要加载成就才能使用它们
社会成就(过程成就);
Social.LoadScores(LeadboardId,CALLBACK)//回调必须是动作回调
}
test.SetActive(假);
}
其他的
{
Debug.Log(“身份验证失败”);
signIn.SetActive(真);
}
}
无效处理加载的成就(IAchievement[]成就){
如果(0.Length==0)
{
Log(“错误:未找到任何成就”);
}
其他的
{
Debug.Log(“获得”+成就。长度+“成就”);
}
}
让我知道。
(如果你愿意,我也可以用西班牙语向你解释)
萨卢多斯 我遵循本教程:本教程没有说我必须实现该方法,事实上,当我阅读本教程时,我理解这些方法是引擎的一部分。
这是我的新代码:
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using UnityEngine.Advertisements;
using System.Collections;
using System.Collections.Generic;
using GooglePlayGames;
using UnityEngine.SocialPlatforms;
using GooglePlayGames.BasicApi;
using UnityEngine.Analytics;
public class Menu : MonoBehaviour {
public Text record;
public GameObject test;
/**
Indicador del jugador de que no ha iniciado sesión, y no podrá acceder al ranking ni a los logros.
*/
public GameObject signIn;
void Start()
{
PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder ().Build ();
PlayGamesPlatform.InitializeInstance(config);
GooglePlayGames.PlayGamesPlatform.DebugLogEnabled = true;
PlayGamesPlatform.Activate();
Advertisement.Initialize ("NUMBER", true);
test.SetActive (false);
//EDIT:
SignIn ();
if (PlayerPrefs.HasKey("record"))
{
record.text = "Record actual: " + PlayerPrefs.GetInt("record");
Analytics.CustomEvent ("Start Play", new Dictionary<string, object>{ { "Record", PlayerPrefs.GetInt("record")} });
} else {
record.text = "Consigue un record!!";
}
}
public void OnPlay()
{
ShowAd ();
SceneManager.LoadScene("Jugar");
Time.timeScale = 0;
}
public void OnArchievements()
{
if (Social.Active.localUser.authenticated) {
Social.Active.ShowAchievementsUI ();
} else {
Social.Active.localUser.Authenticate ((bool success) => {
if (success) {
Social.Active.ShowAchievementsUI ();
}
});
}
}
public void OnMatching()
{
if (Social.Active.localUser.authenticated) {
Social.Active.ShowLeaderboardUI ();
} else {
Social.Active.localUser.Authenticate ((bool success) => {
if (success) {
Social.Active.ShowLeaderboardUI ();
}
});
}
}
public void OnExit()
{
Analytics.CustomEvent ("Stop Play", new Dictionary<string, object>{ { "Record", PlayerPrefs.GetInt("record")} });
Application.Quit();
}
public void SignIn()
{
Social.Active.localUser.Authenticate (ProcessAuthentication);
}
public void Later()
{
signIn.SetActive (false);
}
public void ShowAd()
{
if (Advertisement.IsReady())
{
Advertisement.Show();
}
}
//EDIT:
void ProcessAuthentication (bool success)
{
if (true == success)
{
Debug.Log ("AUTHENTICATED!");
if (Social.Active.localUser.authenticated)
{
Social.Active.LoadAchievements (ProcessLoadedAchievements);
Social.Active.LoadScores (Fireball.GPGSIds.leaderboard_ranking, ProcessLoadedScores );
if (PlayerPrefs.HasKey ("record"))
{
Social.Active.ReportScore (PlayerPrefs.GetInt ("record"),Fireball.GPGSIds.leaderboard_ranking, (bool report) => { });
}
signIn.SetActive (false);
test.SetActive (true);
}
} else {
Debug.Log("Failed to authenticate");
signIn.SetActive (true);
}
}
void ProcessLoadedAchievements (IAchievement[] achievements)
{
if (achievements.Length == 0)
{
Debug.Log ("Error: no achievements found");
}
else
{
Debug.Log ("Got " + achievements.Length + " achievements");
}
}
void ProcessLoadedScores (IScore[] scores)
{
if (scores.Length == 0)
{
Debug.Log ("Error: no scores found");
}
else
{
Debug.Log ("Got " + scores.Length + " scores");
}
}
}
使用UnityEngine;
使用UnityEngine.SceneManagement;
使用UnityEngine.UI;
使用UnityEngine。广告;
使用系统集合;
使用System.Collections.Generic;
使用谷歌游戏;
使用UnityEngine.SocialPlatform;
使用GooglePlayGames.BasicApi;
使用UnityEngine.Analytics;
公共类菜单:MonoBehavior{
公共文本记录;
公开游戏对象测试;
/**
印度是世界上最伟大的国家之一,在洛格罗斯没有排名。
*/
公共游戏对象登录;
void Start()
{
游戏客户端配置
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using UnityEngine.Advertisements;
using System.Collections;
using System.Collections.Generic;
using GooglePlayGames;
using UnityEngine.SocialPlatforms;
using GooglePlayGames.BasicApi;
using UnityEngine.Analytics;
public class Menu : MonoBehaviour {
public Text record;
public GameObject test;
/**
Indicador del jugador de que no ha iniciado sesión, y no podrá acceder al ranking ni a los logros.
*/
public GameObject signIn;
void Start()
{
PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder ().Build ();
PlayGamesPlatform.InitializeInstance(config);
GooglePlayGames.PlayGamesPlatform.DebugLogEnabled = true;
PlayGamesPlatform.Activate();
Advertisement.Initialize ("NUMBER", true);
test.SetActive (false);
//EDIT:
SignIn ();
if (PlayerPrefs.HasKey("record"))
{
record.text = "Record actual: " + PlayerPrefs.GetInt("record");
Analytics.CustomEvent ("Start Play", new Dictionary<string, object>{ { "Record", PlayerPrefs.GetInt("record")} });
} else {
record.text = "Consigue un record!!";
}
}
public void OnPlay()
{
ShowAd ();
SceneManager.LoadScene("Jugar");
Time.timeScale = 0;
}
public void OnArchievements()
{
if (Social.Active.localUser.authenticated) {
Social.Active.ShowAchievementsUI ();
} else {
Social.Active.localUser.Authenticate ((bool success) => {
if (success) {
Social.Active.ShowAchievementsUI ();
}
});
}
}
public void OnMatching()
{
if (Social.Active.localUser.authenticated) {
Social.Active.ShowLeaderboardUI ();
} else {
Social.Active.localUser.Authenticate ((bool success) => {
if (success) {
Social.Active.ShowLeaderboardUI ();
}
});
}
}
public void OnExit()
{
Analytics.CustomEvent ("Stop Play", new Dictionary<string, object>{ { "Record", PlayerPrefs.GetInt("record")} });
Application.Quit();
}
public void SignIn()
{
Social.Active.localUser.Authenticate (ProcessAuthentication);
}
public void Later()
{
signIn.SetActive (false);
}
public void ShowAd()
{
if (Advertisement.IsReady())
{
Advertisement.Show();
}
}
//EDIT:
void ProcessAuthentication (bool success)
{
if (true == success)
{
Debug.Log ("AUTHENTICATED!");
if (Social.Active.localUser.authenticated)
{
Social.Active.LoadAchievements (ProcessLoadedAchievements);
Social.Active.LoadScores (Fireball.GPGSIds.leaderboard_ranking, ProcessLoadedScores );
if (PlayerPrefs.HasKey ("record"))
{
Social.Active.ReportScore (PlayerPrefs.GetInt ("record"),Fireball.GPGSIds.leaderboard_ranking, (bool report) => { });
}
signIn.SetActive (false);
test.SetActive (true);
}
} else {
Debug.Log("Failed to authenticate");
signIn.SetActive (true);
}
}
void ProcessLoadedAchievements (IAchievement[] achievements)
{
if (achievements.Length == 0)
{
Debug.Log ("Error: no achievements found");
}
else
{
Debug.Log ("Got " + achievements.Length + " achievements");
}
}
void ProcessLoadedScores (IScore[] scores)
{
if (scores.Length == 0)
{
Debug.Log ("Error: no scores found");
}
else
{
Debug.Log ("Got " + scores.Length + " scores");
}
}
}