android - Social.localuser.image 总是返回 null

标签 android unity-game-engine google-play-services

我正在使用 Unity 以及在此处找到的适用于 Unity 的 Google Play 服务插件:https://github.com/playgameservices/play-games-plugin-for-unity

我正在尝试访问要包含在游戏中的个人资料图片中的玩家头像。问题是当我尝试访问 Texture2D Social.localuser.image 时,它​​总是返回 null。经过更多研究,代码似乎使用某种 AvatarURL 来查找图像,而这就是空的东西。我用 string.IsNullOrEmpty(AvatarURL) 来检查这个。有谁知道为什么 AvatarURL 为空,和/或我该如何修复它。如果不是那样,是否有其他方法可以访问玩家头像以在我的游戏中用作头像。

这是我用来测试的代码:

PlayGamesPlatform.Activate();

//Authenticate User
Social.localUser.Authenticate((bool success) => {
    if(success) {
        Debug.Log("Successfully Authenticated");
        Textures.profilePic = Sprite.Create(Social.localUser.image, new Rect(0, 0, Social.localUser.image.width, Social.localUser.image.height), new Vector2(0.5f, 0.5f));
        SceneManager.LoadScene("Main Menu");
    } else {
        Debug.Log("Failed to Authenticate User");
        SceneManager.LoadScene("ErrorCanNotSignIn");
    }
});

错误发生在设置Textures.profilePic时(Textures是我创建的另一个存储纹理的类,profilePic是其中的静态Sprite变量)。它说有一个 NullReferenceException:未将对象引用设置为对象的实例。

再次根据我所看到的,我认为错误的来源似乎是 AvatarURL 为空,因为它导致了这段代码,我很确定这是加载图像的原因,而不是运行:

if (!mImageLoading && mImage == null && !string.IsNullOrEmpty(AvatarURL))
{
    Debug.Log("Starting to load image: " + AvatarURL);
    mImageLoading = true;
    PlayGamesHelperObject.RunCoroutine(LoadImage());
}

此外,如果它很重要,我正在 Android 设备上对此进行测试。

最佳答案

JeanLuc 在 this 上回答的问题所以问题

The implementation for Social.localUser.image of the Play Games Unity Plugin returns always null.

关于android - Social.localuser.image 总是返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38838652/

相关文章:

android - 如何在android中以编程方式从通知栏中删除通知?

android - 应用内计费 v3 unity onActivityResult

android - 如何检查 Android Unity3d 的互联网连接类型

android - 空指针 Admob Adrequest

android - 如何从一个 JSONObject 获取值到另一个 JSONObject

android - 如何在android中获取浏览器历史记录?

android - 尝试将 fragment 添加到我的 fragment 容器 FrameLayout

c# - 是否可以在没有 GC 分配的情况下解析字符串?

android - 无法使用 null 启动服务 com.google.android.gms.analytics.AnalyticsService@3399b37

android - Google Play 服务 Activity 识别 - 电池使用情况?