在加载场景之前下载 png
download png before loading scene
我开发网络播放器应用程序。
我需要下载 *.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);
}
这项工作很好,但加载场景后上传的图片会在一段时间后出现。
我该如何解决?
对不起我的英语不好 :)
谢谢!
这很自然。因为你从网上下载图片,有一些延迟。所以你添加加载屏幕或等待所有场景,直到你下载图片。但我认为这不是好的解决方案,因为你只加载图片。也许在开始下载之前禁用其他 buttons/interactive 元素,然后在下载完成后启用它们是一个很好的解决方案。
例如:
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();
}
我开发网络播放器应用程序。 我需要下载 *.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);
}
这项工作很好,但加载场景后上传的图片会在一段时间后出现。 我该如何解决? 对不起我的英语不好 :) 谢谢!
这很自然。因为你从网上下载图片,有一些延迟。所以你添加加载屏幕或等待所有场景,直到你下载图片。但我认为这不是好的解决方案,因为你只加载图片。也许在开始下载之前禁用其他 buttons/interactive 元素,然后在下载完成后启用它们是一个很好的解决方案。
例如:
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();
}