当前位置:网站首页>Unit asynchronous jump progress
Unit asynchronous jump progress
2022-06-30 05:07:00 【zjh_ three hundred and sixty-eight】
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class Loading : MonoBehaviour {
AsyncOperation async;
int progress = 0;
public Image fill;
void Start () {
StartCoroutine(loadScene());
}
public Text txt_test;
void Update()
{
//progress = (int)(async.progress * 100);
//txt_test.text = " Current progress :" + progress;
}
//void OnGUI()
//{
// if (GUILayout.Button(" Jump to plant ", GUILayout.Width(100)))
// {
// //SceneManager.LoadSceneAsync("Loading");
// Global.loadSceneName = "ELE";
// //isOn = true;
// StartCoroutine(loadScene());
// }
//}
IEnumerator LoadScene()
{
float toProgress = 0.9f;// In order to solve progress Value only to 0.9 The problem of ,90% Show this value later
yield return new WaitForEndOfFrame();
AsyncOperation asyncOper = SceneManager.LoadSceneAsync("DH");// Jump scene
asyncOper.allowSceneActivation = false;// Whether to allow scene activation , Set to true Activate the loaded scene
while (!asyncOper.isDone)
{
txt_test.text = Mathf.FloorToInt(asyncOper.progress * 100) + "%";
fill.fillAmount = asyncOper.progress;
if (asyncOper.progress >= 0.9f)
{
toProgress+=0.001f;
// Prevent the display from exceeding 99%
if (toProgress >= 0.99)
toProgress = 0.99f;
txt_test.text = Mathf.FloorToInt(toProgress * 100) + "%";
fill.fillAmount = toProgress;
// According to the 99% Jump to the scene , There is a delay in the jump , It depends on the scene , Or change the ratio
//if (toProgress >= 0.99)
asyncOper.allowSceneActivation = true;
}
yield return new WaitForEndOfFrame();
}
// if (asyncOper.isDone){
// Scene loading completed
// }
}
//============= Here is another version =========================
public Text loadingText;
public Image progressBar;
private int curProgressValue = 0;
private AsyncOperation operation;
// Use this for initialization
void Start()
{
//if (SceneManager.GetActiveScene().name == "Loading")
{
// Start the coroutines
StartCoroutine(AsyncLoading());
}
}
IEnumerator AsyncLoading()
{
operation = SceneManager.LoadSceneAsync(" Jump scene name ");
// Prevent automatic switching when loading is complete
operation.allowSceneActivation = false;
yield return operation;
}
// Update is called once per frame
void Update()
{
int progressValue = 100;
if (curProgressValue < progressValue)
{
curProgressValue++;
}
loadingText.text = curProgressValue + "%";// Text display of real-time update progress percentage
progressBar.fillAmount = curProgressValue / 100f;// Update the sliding progress picture in real time fillAmount value
if (curProgressValue == 100)
{
operation.allowSceneActivation = true;// Enable automatic loading of scenes
loadingText.text = "OK";// Text display complete OK
}
}
}

边栏推荐
- 力扣589:N 叉树的前序遍历
- MySQL query gadget (I) replace a property value of the object in the JSON array in the JSON format string field
- Pit of smoothstep node in shadergraph
- Unity ontriggerenter does not call
- How does unity use mapbox to implement real maps in games?
- Autowired注解警告的解决办法
- 003-JS-DOM-Attr-innerText
- 力扣59. 螺旋矩阵 II
- 0 basic unity course. Bricklaying
- UE4 method of embedding web pages
猜你喜欢

Some problems encountered in unity steamvr

Ugui uses its own function to realize reverse mask

Photon pun refresh hall room list

Force buckle 704 Binary search

Pycharm database tool

Unity script life cycle and execution sequence

Easyrecovery data recovery software recovers my photo and video data two years ago

A collection of errors encountered in machine learning with unity

Generate a slice of mesh Foundation

Unreal 4 learning notes - data storage using blueprints
随机推荐
Unity Logitech steering wheel access
Generate a slice of mesh Foundation
Easyrecovery data recovery software recovers my photo and video data two years ago
一条命令运行rancher
Database base (Study & review for self use)
Ugui uses its own function to realize reverse mask
Connect() and disconnect() of socket in C #
C # three ways to obtain web page content
redis集群概念
Unity realizes rotation and Revolution
PBR material: basic principle and simple fabrication
Pytorchcnn image recognition and classification model training framework
【 VCS + Verdi joint simulation】 ~ Taking Counter as an Example
Nestjs配置静态资源,模板引擎以及Post示例
How can the international trading platform for frying US crude oil guarantee capital security?
Harbor API 2.0 query
Force buckle 349 Intersection of two arrays
Unreal 4 learning notes - set player birth point
炒美原油的国际交易平台如何能保障资金安全呢?
Nestjs中控制器和路由的配置使用