我需要在Unity中下载很多图像,但我的应用程序在生成Sprite时冻结

时间:2019-02-21 10:55:11

标签: c# android ios performance unity3d

这是我的代码: https://pastebin.com/n4dQf7WW

基本上,我的问题是我一次下载了类似10/15的图片来填充我的主页。但是生成所有这些图像将冻结iOS和Android上的应用程序。

更多事实: -在iOS上,下载不会立即开始,而在Android上,下载会立即开始。 -我使用UnityWebRequest函数,但在iOS上无法同时工作。 -在Android上可以正常使用,但是在创建Sprite / Texture时,它会冻结直到完成。

所以我要问的是,是否有一种方法可以更好地处理这种情况(即使使用付费和免费的第三方库)。

我认为问题出在WebClient_DownloadDataCompleted函数上:

 var texture = new Texture2D(2, 2);
        texture.LoadImage(imageBytes);
        Rect rec = new Rect(0, 0, texture.width, texture.height);
        var spriteToUse = Sprite.Create(texture, rec, new Vector2(0.5f, 0.5f), 100);

0 个答案:

没有答案