【问题标题】:GooglePlayGame services not working properly in UnityGooglePlayGame 服务在 Unity 中无法正常工作
【发布时间】:2019-01-22 22:04:21
【问题描述】:

我导入了 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) =>
                {

                });
            }

        }
    }
}

【问题讨论】:

  • 另一个了解成就和排行榜如何运作的好方法是关注official documentationType A Number github sample。通过在您的应用和 Google Play 商店中提供正确的应用程序 ID 和包名称,确保将 GPGS 集成到您的应用中。

标签: c# unity3d google-play-games


【解决方案1】:

添加成就后是否更新 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

希望对你有帮助:)

【讨论】:

  • 我刚接触谷歌播放服务,这是我的第一个代码。我会尝试更改并通知您
  • 当然。祝你好运
  • 我只找到另一个可能对您有帮助的链接。请查看this
  • 我的主要问题是我需要在激活之前进行初始化。不行。谢谢
  • 您应该将这些行添加到您的答案中 PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder ().Build (); PlayGamesPlatform.InitializeInstance(配置);
【解决方案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();

进行这些更改后,我的代码就可以正常工作了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-06
    • 1970-01-01
    • 2015-03-15
    • 2018-01-08
    • 1970-01-01
    相关资源
    最近更新 更多