private static void ReceiveProfilPic(IGraphResult result, SpriteDelegate tmpSpriteDelegate, int tmpInt) { if (result.Error == null && result.Texture != null) { Sprite r = Sprite.Create(result.Texture, new Rect(0, 0, tmpInt, tmpInt), Vector2.zero); if (tmpSpriteDelegate != null) { tmpSpriteDelegate(r); } } else { Debug.Log(result.Error); if (tmpSpriteDelegate != null) { tmpSpriteDelegate(null); } } }
// TODO: Make it coroutine and handle getting resources from server. public IEnumerator GetSprite(string filename, SpriteDelegate OnGetSpriteDelegate) { string path = Path.Combine(Application.streamingAssetsPath, filename + ".png"); UnityWebRequest textureRequest = UnityWebRequestTexture.GetTexture(path); yield return(textureRequest.SendWebRequest()); if (textureRequest.result != UnityWebRequest.Result.Success) { Debug.LogError(textureRequest.error); throw new UnityException("Unable to get " + filename + " with web request to " + path); } else { Texture2D webTexture = ((DownloadHandlerTexture)textureRequest.downloadHandler).texture as Texture2D; Sprite webSprite = Sprite.Create(webTexture, new Rect(0.0f, 0.0f, webTexture.width, webTexture.height), new Vector2(0.5f, 0.5f), 100.0f); OnGetSpriteDelegate(webSprite); } yield break; }
public static void RequestFriendProfilPic(int height, SpriteDelegate sd, string userId) { FB.API("/" + userId + "/picture?type=square&height=" + height + "&width=" + height, HttpMethod.GET, (IGraphResult result) => ReceiveProfilPic(result, sd, height)); }