编辑器/功能拓展 Easy Threading 5.0 unity3d asset 多线程插件

本帖最后由 仓库小力巴 于 2022-5-26 15:17 编辑

QQ截图20180616142528.png









Work with multiple threads easily:
Standalone builds, Windows store (UWP), webplayer, iOS and Android
<
Documentation

Forum's thread (examples and support)

To build a truly responsive Unity game, you must keep long-running operations off of the main thread, and be careful to avoid blocking the main thread. This means you will need to execute various operations in the background.

Unity's coroutines are ALWAYS executed on the main Thread

Executing threads in the background implies carefully go back to the main thread when you have to manipulate Unity's objects.

Piece of cake with this package, just use this sentence:
Task.RunInMainThread(SomeFunction);
SomeFunction is guaranteed to be executed in the main thread

Of course i's possible to use lambda expressions:
Task.RunInMainThread(()=>
{
// This code will execute in the main thread
});


But this asset also makes working with threads a pleasant experience:

To create a thread just use the following syntax:
Task.Run (DoSomeWorkOnABackgroundThread);

Creating a thread that returns some value (an integer in this example):
Task<int>.Run (CalculateSomeIntegerInTheBackground),

Of course you will want to receive the integer:
Task<int>.Run (CalculateSomeIntegerInTheBackground).ContinueWith(ThisFunctionReceivesTheIntegerAsParameter);

Or, maybe, you need to show that integer to the player (the function receiving it must be executed in the main thread):
Task<int>.Run (CalculateSomeIntegerInTheBackground).ContinueInMainThreadWith(ThisFunctionReceivesTheIntegerAsParameter);


These are just the basic features included in this package.

This package reimplements and extends the .NET System.Threading.Tasks namespace.

This namespace makes thread management easier for you by adding a class named Task. A task represents an asynchronous operation. Typically, a Task is returned from an asynchronous function and gives the ability to continue processing the result of the task.
A task is not tied to a particular threading model: it represents the work being done, not where it is executing. Tasks have many advantages over other methods of asynchronous programming such as callbacks and the event model.

2022-4-14 11:24 上传
文件大小:
1 KB
下载次数:
0
附件售价:
9 钥匙  购买记录
本地下载 立即购买

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册