- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 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/
我是一名优秀的程序员,十分优秀!