【发布时间】:2016-10-25 13:09:03
【问题描述】:
我的身份验证有问题。身份验证总是失败,我无法理解原因(不仅在编辑器中失败,在我的设备中也是如此)。这是代码:
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();
}
}
}
对象“测试”只是一个似乎知道身份验证失败的白框。控制台没有显示任何类型的错误,所以我不知道在哪里找到问题......知道问题出在哪里吗? PD:我使用版本 0.9.34 和 Unity 5.3.5f1
提前致谢!
【问题讨论】:
-
您好亚历杭德罗,我认为您在这里遇到了 2 个问题: 1:您忘记对用户进行身份验证-> Social.Active.localUser.Authenticate(ProcessAuthentication); GPGS 所做的是创建一个 ISocialPlatform 并将其设置为活动平台。 2-您应该在“Start()”中执行“Awake()”部分。告诉我。
-
对不起你的例子,这将是正确的方法:当她/他点击按钮时对用户进行身份验证-> Social.Active.localUser.Authenticate(SignIn);
-
对不起,我不明白你的意思(这是我第一次尝试使用google play服务)。我像你说的改变了清醒的部分,但我不知道你说的身份验证怎么做。我必须在 Authenticate 的“参数”中调用一个方法吗?对不起我的无知。
-
非常感谢您的时间和帮助。
标签: c# authentication google-play-services google-play-games unity5