我的身份验证问题。身份验证始终失败,我无法理解原因(不仅在编辑器中失败,在我的设备中也失败)。这是代码:
Illuminate\Support\Collection
对象"测试"只是一个看似知道身份验证失败的白盒子。控制台不会向我显示任何类型的错误,所以我不知道在哪里发现问题......任何想法是什么问题? PD:我使用版本0.9.34和Unity 5.3.5f1
提前致谢!
答案 0 :(得分:1)
不是问题。 我打算在这里写回复,因为它可能会很长。
Unity将默认的ISocialPlatform设置为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);
}
然后,您可以在场景内的检查器中创建一个按钮并调用它:
public void SignIn()
{
Social.localUser.Authenticate( ProcessAuthentication)
}
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");
}
}
让我知道。 (如果你愿意,我也可以用西班牙语向你解释) Saludos!
答案 1 :(得分:0)
我遵循本教程:google tutorial in GitHub (README)并且教程没有说我必须实现该方法,事实上,当我阅读它时,我理解这些方法是引擎的一部分。 这是我的新代码:
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");
}
}
}
编辑: 再次在编辑器中我无法进行身份验证(在我的设备中也失败了),我真的不明白原因......这里的调试日志(我激活它,可能会有帮助):
DEBUG:激活PlayGamesPlatform。
DEBUG:已激活PlayGamesPlatform:GooglePlayGames.PlayGamesPlatform。
DEBUG:创建特定于平台的Play游戏客户端。
DEBUG:使用DummyClient在编辑器中创建IPlayGamesClient。
DEBUG:在DummyClient上接收方法调用 - 使用存根实现。
最后一条消息是,当我尝试进行身份验证时,您可能知道调试日志的问题。
PD:我读过你发给我的文档,但面向GameCenter(iOS),但我现在更了解这一点,非常感谢。再次感谢你的时间。