0

我开发 Web Player 应用程序。我需要下载 *.png 图像并在场景中使用此图像。下载代码:

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);
}

这工作正常,但加载场景上传图片后会出现一段时间。我该如何解决?对不起我的英语:) 谢谢!

4

1 回答 1

1

这是很自然的。因为你是从网上下载图片,有一些延迟。因此,您添加加载屏幕或等待所有场景,直到您下载图片。但我认为这不是一个好的解决方案,因为你只加载图片。也许在开始下载之前禁用其他按钮/交互元素,然后在下载完成后启用它们是很好的解决方案。

例如:

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();
}
于 2015-02-16T16:10:21.663 回答