2017-09-23 48 views
0

所以。我制作了一个统一的游戏5.我已经下载并配置了谷歌播放服务插件。我可以登录并成功解锁成就。但由于某种原因, Social.ShowAchievementsUI();Social.ShowLeaderboardUI(); 将无法​​正常工作。或者不会弹出任何内容。AchievementsUI和LeaderboardsUI不会弹出。登录作品并解锁成就弹出窗口工作

所以我试图展示成就列表并显示可用的排行榜列表。我有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; 

回答

1

添加:

<activity android:name="com.google.games.bridge.NativeBridgeActivity" 
     android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen" /> 

要AndroidManifest.xml中解决了该问题

0

首先为您PlayGames命令的脚本。剧本本身只是一个公开课;但是,所有命令都是静态的,以便您可以从其他脚本调用它们。

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游戏 - > Android设置中将您的资源数据添加到Unity中,以便您可以调用每个成就的ID或调用排行榜ID,通过GPGSIds。例如,

// 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); 
} 
+0

所以,如果我在一个按钮,它不会工作这种情况下ShowAchievementsUI()调用他们? public void ShowAchievementsUI() { Social.ShowAchievementsUI(); } 我已经配置好了。我有成就解锁弹出窗口工作和所有的东西。但Social.ShowAchievementsUI()和Social.ShowLeaderboardUIi()将不起作用 –

+0

您提供的此代码不应该更改任何内容,因为它与我的类似。我说你没有读过这个问题。 –

+0

其实它不同,因为你正试图直接打开用户界面,因为我正在从静态函数访问函数。我遇到了同样的问题,这是我的解决方案。看看这个youtube视频,如果你还没有找到你的问题的答案.... –