//1,abstractooin at this level , for facebook dowloader api coroutine //2. abstraction for downloading through , www, or resourceload, or facebookdownloadapi IEnumerator CoroutineLoadFromUrl(Screen screen, string url, ImageDownloadDelegate callback) { Debug.Log("File being loaded: " + url); screen.SetLoading(); WWW www = new WWW(url); //todo : from cache;;;;; while (!www.isDone) { yield return(0); } // Wait for download to complete // yield www; Texture2D texTmp = new Texture2D(1024, 1024, TextureFormat.DXT5, false); //LoadImageIntoTexture compresses JPGs by DXT1 and PNGs by DXT5 if (texTmp != null) { try { www.LoadImageIntoTexture(texTmp); screen.SetLoading(false); callback(screen, www.texture); } catch (Exception e) { Debug.Log(e.ToString()); } } yield break; }
/// ///////// void LoadFbImageAPI(Screen screen, string url, ImageDownloadDelegate callback) { FB.API(url, Facebook.HttpMethod.GET, result => { if (result.Error != null) { Util.LogError(result.Error); return; } var imageUrl = Util.DeserializePictureURLString(result.Text); StartCoroutine(CoroutineLoadFromUrl(screen, imageUrl, callback)); }); }
void LoadPictureURL(Screen screen, string url, ImageDownloadDelegate callback) { StartCoroutine(CoroutineLoadFromUrl(screen, url, callback)); }