【问题标题】:Social.localUser.Image returns null in Unity3dSocial.localUser.Image 在 Unity3d 中返回 null
【发布时间】:2014-08-11 08:06:14
【问题描述】:

我想在 Android 和 IOS 中访问玩家头像,我可以使用 Social Class 获取用户 ID 和用户名,但图像总是返回 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;
}

任何想法。

【问题讨论】:

    标签: android ios unity3d google-play-services game-center


    【解决方案1】:

    Unity 中的Social API 仅适用于 iOS。

    对于 Google Play 服务,我真的建议以 75 美元的价格购买 prime31 Google Play Game Services Plugin

    另外还有一个来自 Google 的开源 Play Games Unity Plugin,但我不能推荐它,因为我无法在没有登录错误的情况下正确集成它。

    更新 1

    Play Games Unity PluginSocial.localUser.image 的实现始终返回 null。 see PlayGamesUserProfile.cs

    【讨论】:

    • 感谢您的回复。我在两个平台(Ios 和 android)上都使用了 Social 类,对于 Android,我包含了来自 google 的玩游戏插件,到目前为止,在任何一个平台上登录时我都没有遇到任何问题。唯一的问题是 Image 在两个平台上都返回 null!
    • 查看我关于 Play Games Unity 插件的更新 1。对于 iOS,我还没有测试过。
    • PlayGamesLocalUser.cs 这是正确的脚本,但它不包含图像的实现。您发送的那个脚本也不包含 id,但我得到了那个。
    • 是的。所以总结一下:google插件不完整,需要自己添加功能或者购买prime31插件。
    • 知道我们如何自己添加此功能,我的游戏已经上线,并且可以与 play Games Unity 插件一起正常工作,所以我现在有点犹豫是否要转向 Prime31 插件
    【解决方案2】:

    我暂时使用这个Google API 从谷歌获取头像。通过 google 插件,您可以在 AndroidClient 类中创建一个辅助函数,用于从 Android 获取图像,这将返回一个 URI。

    【讨论】:

      【解决方案3】:

      Tomov 在this 上回答的问题对我来说适用于插件版本 0.10.12。

      【讨论】:

      • 正如目前所写,您的答案尚不清楚。请edit 添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。你可以找到更多关于如何写好答案的信息in the help center
      【解决方案4】:
      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));
                          }
      

      【讨论】:

      • 请解释这如何解决提问者的问题。纯代码不足以作为答案!
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-30
      • 2016-11-07
      • 1970-01-01
      • 1970-01-01
      • 2020-01-11
      相关资源
      最近更新 更多