Search code examples
facebookunity-game-enginenguiguitexture

Unity3d Issue NGUI UITexture/Facebook www Profile Pic


Having small issue here with Unity and NGUI. NGUI has UITexture as its main texture such as Unity has GUITexture.

I sent a request to facebook to get the users profile image which sends back a perfect url which if I put in the browser works fine.

My issue is taking that Texture2D (Facebook API does it as a Texture2D) and putting it on my UITexture. For some reason it just does not take it correctly. I keep getting a null value for it. I am also using Mobile Social as well from the asset store any help, helps.

Here is my snippet of code.

 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");
    }
}

The placeholder image is just a already selected image used if the fbprofile pic does is null. Which I keep getting.....


Solution

  • It's possible you're looking for RawImage which exist for this purpose

    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.

    Use Unity.UI and use that feature.