Social.localUser.Image returns null in Unity3d

喜欢而已 提交于 2020-01-05 02:54:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!