将图像下载并保存到Application.persistentDataPath会挂起该应用程序 [英] Download and save image into Application.persistentDataPath hangs the app

查看:96
本文介绍了将图像下载并保存到Application.persistentDataPath会挂起该应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个游戏,可以从服务器下载图像,然后将其存储在Application.persistentDataPath中.

I wrote a game that can download images from server and then store them inside Application.persistentDataPath.

我的问题是,当保存场景挂起的少量图像时,完成保存后,它将执行其余代码.

My problem is when saving few images the scene hangs and when it is done saving, it executes the rest of the code.

我该如何解决这个问题?

How can I solve this issue?

将图像保存到设备本地存储中:

Saving image into device local storage:

    if (File.Exists (Application.persistentDataPath + "/LayoutImages/")) {
        Debug.Log (imagesPathPrefix + " already exists.");
        return;
    }

    File.WriteAllBytes (Application.persistentDataPath + "/LayoutImages/abc.jpg", image);

推荐答案

--- 更新 (6月18日) ----

--- Updated (18th June)----

使用 AssetBundles 来管理服务器中的动态内容.

Use AssetBundles to manage my dynamic contents from server.

很抱歉,但以下提供的解决方案均无法正常工作,因为我已经尝试了所有解决方案,其中一些类似于我可以通过Internet找到的解决方案.

Sorry but none of the below provided solution are actually work as I have tried all of them and some of them are similar that I could find via Internet.

在研究中,这是我发现的:

During some research this is what I've found:

基本上,使用System.Threading创建的线程无法触摸UnityEngine提供给您的任何东西."

唯一不能做的就是在不同线程之间使用Unity API方法本身,因为它们不是线程安全的,但这不会阻止您执行后台处理任务."

我实际上已经解决"了这个问题.

该应用仅在计算机上运行时才会挂起,并从服务器下载图像并将其保存到Application.persistentDataPath中.

但是,当它在我的移动设备上以相同的代码构建并运行时,它不会挂起.

在没有Internet连接中断的情况下,我检查了那些大图像是否已完全下载并很好地存储在persistentDataPath中.

感到尴尬和不愉快,即使这对我来说不再是问题.

Feel awkward and unpleasant even though it is not an issue to me anymore.

我希望遇到此问题的人至少可以尝试使用我的方法,在构建并在您的设备上运行应用程序时检查它是否挂起",尤其是将大图像文件保存到设备本地存储中,而不是在您的计算机.

I wish those who encounter this issue can at least try my method, check if it is "hanged" when the app is built and run on your device, especially saving the large image files into the device local storage, instead running in your computer.

这篇关于将图像下载并保存到Application.persistentDataPath会挂起该应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆