Unity3d Issue NGUI UITexture/Facebook www 个人资料图片

Unity3d Issue NGUI UITexture/Facebook www Profile Pic

Unity 和 NGUI 存在小问题。 NGUI 以 UITexture 作为其主要纹理,例如 Unity 具有 GUITexture。

我向 facebook 发送了一个请求以获取用户个人资料图片,它发回了一个完美的 url 如果我将其放入浏览器则可以正常工作。

我的问题是采用 Texture2D(Facebook API 将其作为 Texture2D)并将其放在我的 UITexture 上。由于某种原因,它只是没有正确接受它。我不断得到它的空值。我也在使用 Mobile Social 以及来自资产商店的任何帮助,帮助。

这是我的代码片段。

 private void UserDataLoaded(FB_Result result)
{
    SPFacebook.OnUserDataRequestCompleteAction -= UserDataLoaded;
    if (result.IsSucceeded)
    {
        Debug.Log("User Data Loaded!");
        IsUserInfoLoaded = true;

        string FBNametxt = SPFacebook.Instance.userInfo.Name;
        UILabel Name = GameObject.Find("FBName").GetComponent<UILabel>();
        Name.text = FBNametxt;

        Texture2D FBLoadTex = SPFacebook.Instance.userInfo.GetProfileImage(FB_ProfileImageSize.normal);
        FBGetProfile.GetComponent<UITexture>().mainTexture = FBLoadTex != null ? FBLoadTex : PlaceHolderImg;
    }
    else {
        Debug.Log("User data load failed, something was wrong");
    }
}

如果 fbprofile pic 为 null,则占位符图像只是已选择的图像。我不断得到......

您可能正在寻找 RawImage 存在此目的

http://docs.unity3d.com/Manual/script-RawImage.html

Since the Raw Image does not require a sprite texture, you can use it to display any texture available to the Unity player. For example, you might show an image downloaded from a URL using the WWW class or a texture from an object in a game.

使用 Unity.UI 并使用该功能。

在编辑器中将 "Ngui Unity2d Sprite" 组件而不是 UiTexture 添加到您的头像,并在您的 Facebook 回调中使用以下代码

 private void ProfilePicCallBack (FBResult result)
    {
        if (result.Error != null) {
            Debug.Log ("Problem with getting Profile Picture");

            return;
        }

 ProfileImage.GetComponent<UI2DSprite> ().sprite2D = Sprite.Create(result.Texture, new Rect(0,0,128,128), new Vector2(0,0));

}

可能还有另一种方法可以做到这一点。但这对我有用