c# - GooglePlayGame 服务在 Unity 中无法正常工作

标签 c# unity3d google-play-games

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

                });
            }

        }
    }
}

最佳答案

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

希望对你有帮助:)

关于c# - GooglePlayGame 服务在 Unity 中无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51868677/

相关文章:

c# - 进行 WCF 服务调用的单元测试方法?

c# - 类不包含采用 0 个参数的构造函数

c# - 轻按几下如何修复?

android - 用户退出 Google Play 服务后保存游戏的最佳做法?

android - 使用 Google Play 游戏服务仅显示社交排行榜

c# - ReportViewer 错误 - 报告的定义“无效。无法加载文件或程序集 Microsoft.ReportViewer.ProcessingObjectMode

javascript - 保存动态创建的 jQuery 连接可排序列表的顺序

unity3d - Unity Video Player-Android上的音频滞后

c# - 脚本需要Derive from MonoBehaviour,不能带参数

java - Google Play 游戏成就 onClose 回调