so。我已经制作了Unity 5的游戏。然后我下载并配置了Google Play Services插件。我可以成功登录并解锁成就。但是由于某种原因 Social.ShowAchievementsUI();
和 Social.ShowLeaderboardUI();
行不通。或任何内容都不会弹出。
因此,我正在尝试显示成就列表,并显示可用的排行榜列表。我有5个成就和4个排行榜。我在Google Play Alpha测试中有此版本的游戏。有2个按钮用于打开成就的菜单和排行榜,但这些按钮无法正常工作。我的登录代码是:
void Start () {
if (PlayGamesPlatform.Instance.IsAuthenticated() == false)
{
PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder().Build();
PlayGamesPlatform.InitializeInstance(config);
PlayGamesPlatform.DebugLogEnabled = true;
PlayGamesPlatform.Activate();
SignIn();
}
void SignIn()
{
Social.localUser.Authenticate((bool success) =>
{});
}
显示achievementsUI
:
public void ShowAchievementsUI()
{
Social.ShowAchievementsUI();
}
显示Leaderboard ui
:
public void ShowLeaderboardsUI()
{
Social.ShowLeaderboardUI();
}
这2个是从按钮调用的。
我正在使用:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using GooglePlayGames;
using UnityEngine.SocialPlatforms;
using GooglePlayGames.BasicApi;
添加:
<activity android:name="com.google.games.bridge.NativeBridgeActivity"
android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen" />
to androidManifest.xml修复了问题
首先为游戏游戏命令创建脚本。脚本本身将是公开班。但是,所有命令都将是静态的,因此您可以从其他脚本调用它们。
using GooglePlayGames;
using GooglePlayGames.BasicApi;
using UnityEngine;
public class PlayGamesScript : MonoBehaviour {
// Use this for initialization
void Start () {
PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder().Build();
PlayGamesPlatform.InitializeInstance(config);
PlayGamesPlatform.Activate();
SignIn ();
}
// PRE: None
// POST: Logs player into Google Play Games
void SignIn()
{
Social.localUser.Authenticate (success => {});
}
#region Achievements
// PRE: Achievement created in Google Play Developer and the
// achievement has been achieved by the player
// POST: Unlocks the achievement for the player
public static void UnlockAchievement(string id)
{
Social.ReportProgress(id, 100, success => { });
}
// PRE: Achievement created in Google Play Developer and set to Incremental
// achievement
// POST: Increments the achievement by selected steps established by
// the stepsToIncrement variable
public static void IncrementAchievement(string id, int stepsToIncrement)
{
PlayGamesPlatform.Instance.IncrementAchievement(id, stepsToIncrement, success => { });
}
// PRE: Achievements created in Google Play Developer and player
// is logged in
// POST: Shows the Achievements UI
public static void ShowAchievementsUI()
{
if(PlayGamesPlatform.Instance.IsAuthenticated())
Social.ShowAchievementsUI();
else
Social.localUser.Authenticate((bool success)=>{
Social.ShowAchievementsUI();
});
}
#endregion /Achievements
#region Leaderboards
// PRE: Leaderboard created in Google Play Developer and player is logged in
// POST: Reports the score to the leaderboard id specified for Google Play
public static void AddScoreToLeaderboard(string leaderboardId, long score)
{
Social.ReportScore(score, leaderboardId, success => { });
}
// PRE: Leaderboard created in Google Play Developer and player is logged in
// POST: Accesses the PlayGamesScript to display the Leaderboard UI
public static void ShowLeaderboardsUI()
{
if(PlayGamesPlatform.Instance.IsAuthenticated())
Social.ShowLeaderboardUI();
else
Social.localUser.Authenticate((bool success)=>{
Social.ShowLeaderboardUI();
});
}
#endregion /Leaderboards
}
您从另一个脚本(调用要查看排行榜或成就UI的脚本)调用这些函数,例如:
public class GooglePlayUIController : MonoBehaviour {
// PRE: Leaderboard created in Google Play Developer
// POST: Accesses the PlayGamesScript to display the Leaderboard UI
public void ShowLeaderboards() {
PlayGamesScript.ShowLeaderboardsUI ();
}
// PRE: Achievements created in Google Play Developer
// POST: Accesses the PlayGamesScript to display the Achievement UI
public void ShowAchievements() {
PlayGamesScript.ShowAchievementsUI();
}
}
从那里您可以通过OnClick()函数上的Unity编辑器将这些功能添加到您的按钮上;这就是我设置我的方式。
当然,不要忘记在选项卡窗口 -> Google Play Games-> Android设置中添加您的资源数据,以便您调用每个成就的ID,或致电排行榜ID,通过GPGSID。例如,
// PRE: A game has been played until all lives equal zero
// POST: A score has been posted to the online leaderboards
private void PostScore() {
PlayGamesScript.AddScoreToLeaderboard (GPGSIds.high_score, player.score);
}