首页 > 编程语言 > 详细

Unity 异步加载场景,进度条显示

时间:2020-01-15 17:38:48      阅读:102      评论:0      收藏:0      [点我收藏+]
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.SceneManagement;

public class Globe
{
    public static string nextSceneName;
}

public class AsyncLoadScene : MonoBehaviour
{
    public Text loadingText;
    public Image progressBar;

    private int curProgressValue = 0;

    private AsyncOperation operation;

    // Use this for initialization
    void Start()
    {
      //加载的场景名称 Globe.nextSceneName
= "Main_Day"; if (SceneManager.GetActiveScene().name == "Main") { //启动协程 StartCoroutine(AsyncLoading()); } } IEnumerator AsyncLoading() { operation = SceneManager.LoadSceneAsync(Globe.nextSceneName); Debug.Log(operation.progress); //阻止当加载完成自动切换 operation.allowSceneActivation = false; yield return operation; } void Update() { curProgressValue = (int)(operation.progress * 100); loadingText.text = curProgressValue + "%";//实时更新进度百分比的文本显示 progressBar.fillAmount = curProgressValue / 100f;//实时更新滑动进度图片的fillAmount值 //operation.progress 在这最大值为0.89(有的是0.9) if (operation.progress >=0.89) { operation.allowSceneActivation = true;//启用自动加载场景 } } }

Unity 异步加载场景,进度条显示

原文:https://www.cnblogs.com/DGJS/p/12197785.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!