public static IEnumerator DownloadImage(string youtubeId, YoutubeImageType type, TextureResult texture) { WWW www = new WWW(GetImageUrlFromId(type, youtubeId)); yield return(www); texture.m_texture = www.texture; texture.m_hasBeenLoaded = true; }
protected override void ApplyTexture(TextureResult result) { var renderer = GetComponent <Renderer>(); if (renderer != null && renderer.sharedMaterial != null) { renderer.material.mainTexture = result.texture; // Optional: Support arbitrary texture orientation by flipping the texture if necessary var scale = renderer.material.mainTextureScale; scale.x = result.orientation.IsXFlipped() ? -1 : 1; scale.y = result.orientation.IsYFlipped() ? -1 : 1; renderer.material.mainTextureScale = scale; } }
void ApplyTexture(TextureResult result) { Profiler.BeginSample("ApplyTexture"); if (result == null) { return; } total_count++; Debug.LogFormat("Added image {0}", total_count); var b = Object.Instantiate <Renderer>(prefab); b.transform.position = new Vector3( (Random.value - .5f) * spread * aspectRatio, (Random.value - .5f) * spread, distance ); distance += step; var material = b.material; material.mainTexture = result.texture; var scale = material.mainTextureScale; scale.x = result.orientation.IsXFlipped() ? -1 : 1; scale.y = result.orientation.IsYFlipped() ? -1 : 1; b.material.mainTextureScale = scale; rendererQueue.Enqueue(b); while (rendererQueue.Count > MAX_ITEMS) { var r = rendererQueue.Dequeue(); if (r == null) { return; } r.enabled = false; } if (batch_count > 0) { batch_count--; if (batch_count == 0) { batch_time = Time.realtimeSinceStartup - start_time; Debug.LogFormat("Batch load time: {0}", batch_time); batch_count = -1; } } Profiler.EndSample(); }
private IEnumerator Start() { if (m_useDebugAtStart) { string id = ""; TextureResult text = new TextureResult(); foreach (string url in m_tdd) { id = GetYoutubeId(url); yield return(DownloadImage(id, YoutubeImageType._maxresdefault, text)); m_image.texture = text.m_texture; m_ratio.aspectRatio = (float)text.m_texture.width / (float)text.m_texture.height; Debug.Log("texture (" + id + "):" + text); yield return(new WaitForSeconds(2)); } } }
protected override void ApplyTexture(TextureResult result) { Vector2 pos = new Vector2(0, 0); Vector2 size = new Vector2(result.texture.width, result.texture.height); if (result.orientation.IsXFlipped()) { pos.x = size.x; size.x *= -1; } if (result.orientation.IsYFlipped()) { pos.y = size.y; size.y *= -1; } GetComponent <Image>().sprite = Sprite.Create(result.texture, new Rect(pos, size), Vector2.zero); var rt = GetComponent <RectTransform>(); rt.sizeDelta = new Vector2(result.texture.width * scale, result.texture.height * scale); }