0

Unity 和 NGUI 有小问题。NGUI 有 UITexture 作为它的主要纹理,例如 Unity 有 GUITexture。

我向 facebook 发送了一个请求,以获取用户的个人资料图片,该图片发回了一个完美的 url,如果我把它放在浏览器中就可以了。

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

这是我的代码片段。

 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 确实为空,则占位符图像只是已选择的图像。我不断得到......

4

2 回答 2

1

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

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

由于原始图像不需要精灵纹理,因此您可以使用它来显示 Unity 播放器可用的任何纹理。例如,您可能会显示使用 WWW 类从 URL 下载的图像或游戏中对象的纹理。

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

于 2016-01-23T13:35:40.440 回答
-1

在编辑器中将“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));

}

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

于 2016-02-15T08:30:13.067 回答