当前位置:网站首页>Unity sub thread calls UI of main thread

Unity sub thread calls UI of main thread

2022-06-22 14:28:00 Cangwolf King unity College

Unity The child thread calls the main thread's UI

1. stay Unity in , A child thread cannot call Unity Main thread API Of , because unity It's not allowed .

The function to be called in the sub thread , Pass to by delegation Loom Delegate list in , stay Loom To call the delegate . because Loom It's inheritance MonoBehavior Of , Mounted on an empty object , So it is up to him to carry out the Commission , Self heating is no problem !

2. Detailed ideas : At the beginning Unity Create a new object in obj, Hang up Loom Script .

Loom There is List listActions;

Jiangzi Functions in threads , In the form of Commission , Pass to listActions,Loom stay Updata Inside , Polling to invoke delegates .

Subtly make the sub thread unable to call the main thread API Turn into The sub thread passes to the... Above the empty object Loom, stay Loom Inside, call the delegate to call the main thread API.

using UnityEngine;
using System.Collections.Generic;
using System;
using System.Threading;
using Sy

原网站

版权声明
本文为[Cangwolf King unity College]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/173/202206221304023391.html