0

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.....

user19983
  • 50
  • 5
  • Anyone have a fix?? I have been stuck on this for almost a day now... – user19983 Jan 23 '16 at 06:38
  • It's not realistically possible to use "ngui" these days; it has been deprecated for 4? years. Simply use the built-in Unity.UI. – Fattie Nov 24 '16 at 14:32

2 Answers2

2

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.

Fattie
  • 27,874
  • 70
  • 431
  • 719
  • this helped me out really well. I went ahead and used the Raw Image. However I am running into another issue once the user is logged in already a previous time. They sign back in automatically and the fb pic shows a red question mark. About to make a topic for this I think cant figure out why..... :( – user19983 Mar 02 '16 at 05:20
  • ok go ahead and ask a new question, try to be clear and good luck! – Fattie Mar 02 '16 at 12:20
-1

Add "Ngui Unity2d Sprite" component instead of UiTexture to your profile picture in editor and use below code in your Fb callback

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

}

there might be an another way to do this. but this worked for me

S.Waraich
  • 9
  • 2