gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 01:06:30 25 4
gpt4 key购买 nike

我正在使用 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/

25 4 0
文章推荐: android - Android 上的 Ionic 应用程序文件夹在哪里?
文章推荐: android - 使用 RxJava/RxAndroid 的 Retrofit2 尾递归
文章推荐: java - 如何在 onPerformSync 中实现 Yelp Api
文章推荐: javascript - 按日期对两个表进行排序并在 html 中显示输出