问题
I want to access player avatar in Android and IOS, I could get userid and username using Social Class but image always returns null!!
if ( Social.localUser.authenticated && Social.localUser.image != null )
{
Material m = new Material(Shader.Find("Unlit/Transparent Colored"));
m.mainTexture = Social.localUser.image;
AvatarImage.material = m;
}
Any idea.
回答1:
The Social API in Unity is only implemented for iOS.
For the Google Play Services i really recommend buying the prime31 Google Play Game Services Plugin for 75$.
Alternatively there is also a Open Source Play Games Unity Plugin from Google, but I can't recommend it, because I was not able to integrated it properly without sign in bugs.
UPDATE 1
The implementation for Social.localUser.image
of the Play Games Unity Plugin returns always null. see PlayGamesUserProfile.cs
回答2:
I am using this Google API to get avatar from google for time being. From google plugin, you can create a helper function inside AndroidClient class for getting image from Android which would return you a URI.
回答3:
if (Social.localUser.authenticated && Social.localUser.image != null)
{
GameObject UserAvatar = GameObject.FindGameObjectWithTag("UserAvatar");
if (UserAvatar != null)
UserAvatar.GetComponent<Image>().sprite = Sprite.Create(Social.localUser.image, new Rect(0, 0, 50, 50), new Vector2(0, 0));
}
来源:https://stackoverflow.com/questions/25238474/social-localuser-image-returns-null-in-unity3d