【问题标题】:download png before loading scene在加载场景之前下载png
【发布时间】:2015-04-17 04:53:57
【问题描述】:

我开发 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);
}

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

【问题讨论】:

    标签: c# unity3d unity-web-player


    【解决方案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();
    }
    

    【讨论】:

    • 请告诉我如何等待所有场景直到图片被你下载?
    • 您可以禁用按钮等所有交互元素。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多