我想在我的unity游戲中實作用戶登錄,但我無法從用戶的Facebook ID中獲得用戶的資料圖片。用戶名顯示出來了,但是沒有個人資料圖片。它顯示的是空白。我也沒有得到任何錯誤! 圖片的精靈在變化,但沒有顯示在螢屏上。 以下是代碼:
void DealWithFbMenus(bool isLoggedIn)
{
if (isLoggedIn)
{
FB.API("/me?fields=first_name", HttpMethod.GET, DisplayUsername)。)
FB.API("/me/picture?type=med", HttpMethod.GET, DisplayProfilePic) 。
}
}
void DisplayUsername(IResult result)。
{
if (result.Error == null)
{
string name = "" result.ResultDictionary["first_name"] 。
FB_userName.text = name;
Debug.Log("" name)。
}
else
{
Debug.Log(result.Error)。
}
}
void DisplayProfilePic(IGraphResult result)
{
if (result.Error == null)
{
Debug.Log("Profile Pic")。
FB_userDp.sprite = Sprite.Create(result.Texture, "Profile Pic") Texture, new Rect(0, 0, 128, 128), new Vector2())。)
}
else; }
{
Debug.Log(result.Error)。
}
uj5u.com熱心網友回復:
rect 用于精靈的紋理的矩形部分。
我懷疑你硬編碼的128 x 128像素只是一個部分,而不是整個紋理,這取決于圖片的實際影像尺寸。
而且它還需要
pivot Sprite的支點相對于它的圖形矩形而言。
你正在使用new Vector2(),這意味著左下角。一般來說,對于個人資料圖片,我寧愿假定支點應該是紋理的中心,并使用
Vector2.one * 0.5f。
或者
new Vector2(0.5f, 0.5f)。
因此,假設下載本身確實有效,并且如你所說,你沒有得到錯誤,你可能寧愿使用例如
。 Texture, new Rect(0, 0, result.Texture.width, result.Texture.height), Vector2.one * 0.5f) 。或者,如果你的目標是使用一個正方形的部分,不管是什么尺寸,你都可以使用
。var size = Mathf.Min(result.Texture.width, result.Texture.height)。
FB_userDp.sprite = Sprite.Create(result.Texture, new Rect(0, 0, size, size), Vector2.1 * 0.5f) 。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/312668.html
標籤:
