IEnumerator GenerateSpriteForImage(Image img, GenSprite genSprite) { while (genSprite.sprite == null) { yield return(null); } img.sprite = genSprite.sprite; }
//Note: Sprites in GeneratedSprites take time to generate... public GenSprite GenerateSprite(string url) { if (m_generatedSprites.ContainsKey(url)) { return(m_generatedSprites[url]); } else { GenSprite genSprite = new GenSprite(); m_generatedSprites.Add(url, genSprite); StartCoroutine(GenerateSprite(genSprite, url)); return(genSprite); } }
IEnumerator GenerateSprite(GenSprite genSprite, string url) { ++m_numSpritesLoading; WWW www = new WWW(url); yield return(www); Texture2D texture = www.texture; genSprite.sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f)); --m_numSpritesLoading; }
//Assignes a valid sprite once sprite in GeneratedSprite has been generated... public void GenerateSpriteForImage(Image img, string url) { GenSprite genSprite = GenerateSprite(url); StartCoroutine(GenerateSpriteForImage(img, genSprite)); }