我导入了Google Play游戏服务插件
然后使用一些教程实现它
但是
仍然无法显示成就和排行榜未显示
正常登录
但是我不明白为什么这些都不起作用
using System.Collections;
using System.Collections.Generic;
using Google;
using GooglePlayGames;
using GooglePlayGames.BasicApi;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.SocialPlatforms;
public class LeaderBoardController : MonoBehaviour
{
public static LeaderBoardController instance;
public const string leaderBoardId = "CgkIlY-bvcoNEAIQAQ";
// Achievements ID
public const string score5 = "CgkIlY-bvcoNEAIQAg";
public const string passTheScore30 = "CgkIlY-bvcoNEAIQAw";
public const string unlockTheGreenBird = "CgkIlY-bvcoNEAIQBQ";
public const string unlockTheDawnLevel = "CgkIlY-bvcoNEAIQBg";
public const string becomeAcenturian = "CgkIlY-bvcoNEAIQBw";
public const string unlockTheRedBird = "CgkIlY-bvcoNEAIQCA";
public const string unlockTheMountainsLevel = "CgkIlY-bvcoNEAIQCQ";
public const string unlockTheLakeLevel = "CgkIlY-bvcoNEAIQCg";
public const string unlockTheSpringLevel = "CgkIlY-bvcoNEAIQCw";
public const string unlockTheFarmLevel = "CgkIlY-bvcoNEAIQDA";
public const string unlockTheWinterLevel = "CgkIlY-bvcoNEAIQDQ";
public const string unlockTheEveningLevel = "CgkIlY-bvcoNEAIQDg";
public const string unlockTheDarkLevel = "CgkIlY-bvcoNEAIQDw";
public const string unlockTheRainyLevel = "CgkIlY-bvcoNEAIQEA";
public const string becomeTheUltimateFlappy = "CgkIlY-bvcoNEAIQEQ";
void Awake ()
{
MakeSingleton ();
}
// Use this for initialization
void Start ()
{
PlayGamesPlatform.Activate ();
}
void OnEnable ()
{
SceneManager.sceneLoaded += this.OnLoadCallBack;
}
void OnLoadCallBack (Scene scene, LoadSceneMode sceneMode)
{
ReportScoreLocal (GameController.instance.GetHighScore ());
ReportProgressLocal (GameController.instance.GetHighScore ());
}
void OnDisable ()
{
SceneManager.sceneLoaded -= this.OnLoadCallBack;
}
// making C# script singleton
void MakeSingleton ()
{
if (instance != null)
{
Destroy (gameObject);
}
else
{
instance = this;
DontDestroyOnLoad (gameObject);
}
}
public void ConnectGooglePlayGames ()
{
if (Social.localUser.authenticated)
{
PlayGamesPlatform.Instance.ShowAchievementsUI ();
}
else
{
Social.localUser.Authenticate ((bool success) =>
{
});
}
}
public void OpenLeaderBoard ()
{
if (Social.localUser.authenticated)
{
PlayGamesPlatform.Instance.ShowLeaderboardUI (leaderBoardId);
}
}
void ReportScoreLocal (int score)
{
if (Social.localUser.authenticated)
{
Social.ReportScore (score, leaderBoardId, (bool success) =>
{
});
}
}
void ReportProgressLocal (int score)
{
if (Social.localUser.authenticated)
{
if (score >= 5 && score < 30)
{
Social.ReportProgress (score5, (double) score, (bool success) =>
{
});
}
}
}
}
答案 0 :(得分:4)
添加成就后,您是否会更新Android设置?还是在Google Play服务信息中心中重新发布更改?
还可以更改
PlayGamesPlatform.Instance.ShowAchievementsUI ();
到
Social.ShowAchievementsUI ();
并更改
PlayGamesPlatform.Instance.ShowLeaderboardUI (leaderBoardId);
到
Social.ShowLeaderboardUI();
有关更多信息,请参见以下链接:
Google Play Games Services Tutorial (Unity) #1 - ACHIEVEMENTS and LEADERBOARDS
Achievements & Leaderboard - Google Play Services - Subway Skater - 23
希望对您有所帮助:)
答案 1 :(得分:2)
要使我的代码正常工作,我必须更改一些代码以及 @Ehsan Mohammadi的建议。
首先更改启动方法
void Start ()
{
PlayGamesPlatform.Activate ();
}
到
void Start ()
{
PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder ().Build ();
PlayGamesPlatform.InitializeInstance (config);
PlayGamesPlatform.Activate ();
}
还有
更改以下语句
PlayGamesPlatform.Instance.ShowAchievementsUI ();
到
Social.ShowAchievementsUI ();
和
PlayGamesPlatform.Instance.ShowLeaderboardUI (leaderBoardId);
到
Social.ShowLeaderboardUI();
进行这些更改后,我的代码可以正常工作。