如何在Unity3D执行异步任务吗? [英] How to execute async task in Unity3D?

查看:214
本文介绍了如何在Unity3D执行异步任务吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何身体知道团结做异步任务的任何方式。我期待为一段时间,但找不到任何办法的事,还没有。
我试图做一个填色游戏,有一个洪水填充算法,需要一些时间来处理。
感谢您的帮助。

Does any body know any way of doing async task in unity. I am looking for that for a while but couldn't find any way to do, yet. I am trying to do a coloring game, there is a flood fill algorithm that takes some time to process. Thanks for any help.

推荐答案

您可以使用线程在Unity以执行异步TAKS。通常你运行的线程分离(从Unity UI)做长时间运行的进程,并检查结果(你可以用统一的工作线程不交互)。
常见的方法是使用一类重presents将由统一主线程进行初始化穿线作业。然后,你开始对这个类的功能的工作线程,让它做的工作(协同程序统一主线程上运行,因此并不是真正的线程在协程最佳文章的这里

You can use threads in Unity to execute your async taks. Usually you run detached threads (from the Unity UI) to do long running processes and check on results (you can't interact with Unity from the working thread). The common approach is to use a class which represents a threading job which will be initialized by the Unity main thread. Then you start a worker thread on a function of that class and let it do it's job (Coroutines run on the Unity main thread so are not real threads. Best article on Coroutines is here)

下面是上述方法的一个例子(见接受的答案):

Here's an example of the approach described above (see accepted answer):

<一个href=\"http://answers.unity3d.com/questions/357033/unity3d-and-c-coroutines-vs-threading.html\">http://answers.unity3d.com/questions/357033/unity3d-and-c-coroutines-vs-threading.html

您可能也想尝试UnityGems包,达到同样的效果,但提供了便利(如封支持):

You might also want to try a UnityGems package that achieves the same effect but provides convenience (such as closure support):

http://unitygems.com/threads/

心连心。
最好的!

HTH. Best!

这篇关于如何在Unity3D执行异步任务吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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