【发布时间】:2016-08-08 21:15:25
【问题描述】:
我正在使用 Unity 以及此处的 Google Play Services Plugin for Unity: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: Object reference not set to an instance of the object。
再次根据我所见,我认为错误的来源似乎是 AvatarURL 为空,因为它导致了这段代码,我很确定这是加载图像的原因,而不是运行:
if (!mImageLoading && mImage == null && !string.IsNullOrEmpty(AvatarURL))
{
Debug.Log("Starting to load image: " + AvatarURL);
mImageLoading = true;
PlayGamesHelperObject.RunCoroutine(LoadImage());
}
另外,如果它很重要,我正在安卓设备上进行测试。
【问题讨论】:
标签: android unity3d google-play-services