C# 成就Tsui和排行榜Sui won#x27;t弹出窗口。登录作品和解锁的成果弹出作品
所以。我与unity 5进行了一场比赛。我已经下载并配置了google play服务插件。我可以登录并成功解锁成就。但是由于某种原因C# 成就Tsui和排行榜Sui won#x27;t弹出窗口。登录作品和解锁的成果弹出作品,c#,unity3d,google-play,google-play-services,unity5,C#,Unity3d,Google Play,Google Play Services,Unity5,所以。我与unity 5进行了一场比赛。我已经下载并配置了google play服务插件。我可以登录并成功解锁成就。但是由于某种原因 Social.showtacheementsui() 及 Social.ShowLeaderboardUI() 不行。否则任何东西都不会弹出 因此,我试图显示成就列表和可用排行榜列表。我有5项成就和4个排行榜。我在Google Play alpha测试上有这个版本的游戏。用两个按钮打开成就菜单和排行榜,但这些都不起作用。 我的登录代码是: void Start (
Social.showtacheementsui()代码>
及
Social.ShowLeaderboardUI()代码>
不行。否则任何东西都不会弹出
因此,我试图显示成就列表和可用排行榜列表。我有5项成就和4个排行榜。我在Google Play alpha测试上有这个版本的游戏。用两个按钮打开成就菜单和排行榜,但这些都不起作用。
我的登录代码是:
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) =>
{});
}
用于显示成就TSUI
:
public void ShowAchievementsUI()
{
Social.ShowAchievementsUI();
}
用于显示排行榜用户界面
:
public void ShowLeaderboardsUI()
{
Social.ShowLeaderboardUI();
}
这2个是从按钮调用的
我正在使用:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using GooglePlayGames;
using UnityEngine.SocialPlatforms;
using GooglePlayGames.BasicApi;
首先为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 Games-->Android设置中将您的资源数据添加到Unity中,以便您可以通过GPGSID调用每个成就的ID,或调用排行榜ID。比如说,
// 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);
}
添加:
<activity android:name="com.google.games.bridge.NativeBridgeActivity"
android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen" />
到AndroidManifest.xml修复了这个问题,因此如果我在本例中使用按钮上的ShowAchievementsUI()调用它们,它将无法工作?public void showagementsui(){Social.showagementsui();}我已正确配置了它。我有一些弹出窗口和所有的东西。但是Social.ShowAchievementsUI()和Social.ShowLeaderboardUIi()不起作用。您提供的代码不应更改任何内容,因为它与我的代码类似。我想你没有读过这个问题。实际上,它不同于你试图直接打开UI,因为我的是从静态函数访问函数。我遇到了和你同样的问题,这就是我的解决方案。如果您仍然没有找到问题的答案,请查看此youtube视频……您是否注意到对PlayGamesPlatform和PlayGamesScript的调用之间的差异?将尝试从静态函数访问该函数。让你随时了解最新情况