简体   繁体   English

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

[英]Unity3d Issue NGUI UITexture/Facebook www Profile Pic

Having small issue here with Unity and NGUI. 这里有Unity和NGUI的小问题。 NGUI has UITexture as its main texture such as Unity has GUITexture. NGUI具有UITexture作为其主要纹理,例如Unity具有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. 我向Facebook发送了一个请求,以获取用户个人资料图片,该图片会发回一个完美的url,如果我将其放入浏览器中也可以正常工作。

My issue is taking that Texture2D (Facebook API does it as a Texture2D) and putting it on my UITexture. 我的问题是将Texture2D(Facebook API将其作为Texture2D进行处理)并将其放在我的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. 我也在资产商店中使用Mobile Social以及任何帮助。

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. 如果fbprofile图片为null,则占位符图像只是已使用的图像。 Which I keep getting..... 我不断得到.....

It's possible you're looking for RawImage which exist for this purpose 您可能正在寻找为此目的而存在的RawImage

http://docs.unity3d.com/Manual/script-RawImage.html 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. 由于原始图像不需要精灵纹理,因此可以使用它显示Unity播放器可用的任何纹理。 For example, you might show an image downloaded from a URL using the WWW class or a texture from an object in a game. 例如,您可能会显示使用WWW类从URL下载的图像或游戏对象的纹理。

Use Unity.UI and use that feature. 使用Unity.UI并使用该功能。

Add "Ngui Unity2d Sprite" component instead of UiTexture to your profile picture in editor and use below code in your Fb callback 在编辑器中的个人资料图片中添加“ Ngui Unity2d Sprite”组件而不是UiTexture,并在Fb回调中使用以下代码

 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 但这对我有用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM