0

I develop Web Player application. I need to download *.png image and use this image in scene. Download code:

public Material mat;
string fullFilename;
Texture2D texTmp;
Sprite spr;

void Awake()
{
    fullFilename = "http://585649.workwork.web.hostingtest.net/Images/Logo.png";
    StartCoroutine(Download());
    texTmp = new Texture2D(50, 50);
    spr = Sprite.Create(texTmp, new Rect(0, 0, texTmp.width, texTmp.height), Vector2.zero, 100);
    spr.texture.wrapMode = TextureWrapMode.Clamp;
    mat.mainTexture = spr.texture;
}

IEnumerator Download()
{
    WWW www = new WWW(fullFilename);
    yield return www;
    www.LoadImageIntoTexture(texTmp);
}

This work fine,but after loading scene uploaded picture appears after a while. How i can fix it ? Sorry for my English :) Thanks!

CodeSmile
  • 64,284
  • 20
  • 132
  • 217
OleksandrYa
  • 103
  • 1
  • 11

1 Answers1

1

This is natural. Because you download picture from internet, and there are some delays. So you add loading screen or wait all scene until picture is downloaded by you. But i think it is not good solution because you only load picture. Maybe disabling other buttons/interactive elements before starting download and then enable them after download is finished is good solution.

For example:

void Awake()
{
    fullFilename = "http://585649.workwork.web.hostingtest.net/Images/Logo.png";
    disableButtons();
    StartCoroutine(Download());
    texTmp = new Texture2D(50, 50);
    spr = Sprite.Create(texTmp, new Rect(0, 0, texTmp.width, texTmp.height), Vector2.zero, 100);
    spr.texture.wrapMode = TextureWrapMode.Clamp;
    mat.mainTexture = spr.texture;
}

IEnumerator Download()
{
    WWW www = new WWW(fullFilename);
    yield return www;
    www.LoadImageIntoTexture(texTmp);
    enableButtons();
}
Barış Çırıka
  • 1,570
  • 1
  • 15
  • 24