当前位置:网站首页>Unity3d asynchronous loading of scenes and progress bar loading
Unity3d asynchronous loading of scenes and progress bar loading
2022-07-26 07:14:00 【MaNongSa】
AsyncOperation
Tips : The following is the main body of this article
AsyncOperation
describe
Asynchronous operation synergist .
You can yield Until the asynchronous operation continues , Or manually check that it is complete (isDone) Still in progress (progress).
See also :SceneManager.LoadSceneAsync、AssetBundle.LoadAssetAsync、Resources.LoadAsync.
Variable
| Variable name | effect |
|---|---|
| allowSceneActivation | Allows the scene to be activated immediately after it is ready . |
| isDone | Is the operation complete ?( read-only ) |
| priority | Priority Allows you to adjust the order in which asynchronous operation calls are performed . |
| progress | Get the operation progress .( read-only ) |
Events
| event | effect |
|---|---|
| completed | The event called when the operation is completed . Even if the operation can be completed synchronously , The event handler registered in the frame of the call that created it will also be called at the next frame . If the handler is registered after the operation is completed , And called complete event , The handler will be called synchronously . |
Code case :
using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class AsyncScene : MonoBehaviour
{
public Text textValue;
public Slider sliderImg;
public GameObject showObj;
AsyncOperation asyncOperation;
/// <summary>
/// Judge whether the asynchronous scene can be loaded
/// </summary>
private bool isLodaScene;
private bool isLodaScene1;
private void Update()
{
if (isLodaScene&& isLodaScene1)
{
if (Input.anyKeyDown)
{
asyncOperation.allowSceneActivation = true;
isLodaScene = false;
}
}
}
public void startToLoadScene()
{
// Start the coroutines
StartCoroutine(AsuncLoad());
}
private IEnumerator AsuncLoad()
{
yield return null;
isLodaScene = true;
// According to load UI
showObj.SetActive(true);
// Get the index of the currently active scene +1
asyncOperation = SceneManager.LoadSceneAsync(SceneManager.GetActiveScene().buildIndex+1);
// It is not allowed to activate the scene immediately after the scene is ready .
asyncOperation.allowSceneActivation = false;
// Is the operation complete ?( read-only )
while (!asyncOperation.isDone && isLodaScene)
{
// Such as 3d The scene needs to be loaded , There is nothing in the practice scene here, so we need to simulate licking and delay
yield return new WaitForSeconds(1f);
// Get the operation progress .( read-only ) assignment Slider On
sliderImg.value = asyncOperation.progress;
// Get the operation progress .( read-only ) assignment Text On the text
textValue.text = asyncOperation.progress * 100 + "%";
if (asyncOperation.progress >= 0.9f )
{
// Such as 3d The scene needs to be loaded , There is nothing in the practice scene here, so we need to simulate licking and delay
yield return new WaitForSeconds(1f);
sliderImg.value = 1;
textValue.text = " The scene is loaded , Press any key to jump to the scene .";
isLodaScene = false;
}
yield return null;
}
if (sliderImg.value == 1)
{
isLodaScene = true;
isLodaScene1 = true;
}
}
}
边栏推荐
- 解决 Chrome 浏览器被毒霸篡改问题
- Apache DolphinScheduler&TiDB联合Meetup | 聚焦开源生态发展下的应用开发能力
- 【一库】妙啊!这个库组织npm脚本简直爆炸!
- HCIP --- MPLS技术
- What are the ways to open the JDBC log of Youxuan database
- Deep learning learning notes -- solve the problem of slow download of CONDA and pip
- I don't understand the MySQL 57 version under centos7 when I encounter a problem. I was informed by big Shen who knows it
- 10 papers of ant security laboratory were included by ccf-a top meeting to explore the realization of AI credibility from the perspective of algorithm
- Docker modifying the MySQL configuration file attached to the host does not take effect?
- 常用的cmd指令
猜你喜欢

Heap parsing and heap sorting

What are the basics of getting started with spot silver

Opencv learning color detection

从XSS Playload 学习浏览器解码

IDEA——使用@Slf4j打印日志
![[749. Isolate virus]](/img/12/b8c3cdb664f4415d20c2fc5c697a41.png)
[749. Isolate virus]

MySQL安装教程-手把手教你安装

Rectification ideas for the previous article

Realization of LED water lamp based on C51

Drools (4): drools basic syntax (2)
随机推荐
成为 Apache 贡献者,So easy!
npm 命令
为什么extern使用const修饰的变量会编译不过?
WPS or office compression of ppt
又是一年开源之夏,1.2万项目奖金等你来拿!
Queue assistant | product update log in June 2022
Linux c SQLite database usage
"XXXX" is running, which may cause the system to jam, reduce the standby time, and click Close "
Pycharm的相关配置:改字体样式和大小、更改图片背景、更改控制台输出的字体颜色
How to delete a statement audit log?
Airiot IOT platform enables the container industry to build a welding station information monitoring system
MySQL安装教程-手把手教你安装
docker修改挂载到宿主机上的mysql配置文件不生效?
Overview of new features of es11, ES12 and es13
Precious metal knowledge: lethal short-term secret script
QT listens for socket events and uses qsocketnotifier class
MySQL read / write lock
Drools (3): drools basic syntax (1)
Hands on practice - teach you how to make an intelligent fish tank with STM32
20220725 自动控制原理中的补偿器