Unity cutscene Loading interface code

using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;
using System;
using UnityEngine.UI;
public class Loading : MonoBehaviour
{

    AsyncOperation async;
    //自行决定
    //UGU
    public Slider m_pProgress;
    //NGUI
    public UISlider m_pProgress;
    private int progress = 0;
    // Use this for initialization
    void Start ()
    {
        StartCoroutine(LoadScenes());
    }
    IEnumerator LoadScenes()
    {
        int nDisPlayProgress = 0;
        async = SceneManager.LoadSceneAsync(GameDatas.Scenename);
        async.allowSceneActivation = false;
        while (async.progress < 0.9f)
        {
            progress = (int)async.progress * 100;
            while (nDisPlayProgress < progress)
            {
                ++nDisPlayProgress;
                m_pProgress.value = (float)nDisPlayProgress / 100;
                yield return new WaitForEndOfFrame();
            }
            yield return null;
        }
        progress = 100;
        while(nDisPlayProgress < progress)
        {
            ++nDisPlayProgress;
            m_pProgress.value = (float)nDisPlayProgress / 100;
            yield return new WaitForEndOfFrame();
       }
        async.allowSceneActivation = true;

    }
}

Scenes:
Write picture description here

Write picture description here

Just push, nothing to say

Guess you like

Origin blog.csdn.net/z502768095/article/details/81015296