Unity3D LoadingScene

来源:互联网 发布:java mvc框架下载 编辑:程序博客网 时间:2024/05/29 19:50

Unity3D LoadingScene

 

  大家都知道,在我们玩游戏的时候,在进入游戏的时候,都会看到会有一个进度条画面,这样做是因为场景加载的需要一定时间,尤其是场景资源很大的时候,都是通过引入一个过渡画面,显示游戏加载进度,这样提高了游戏的体验度。

 

 

using UnityEngine;

using System.Collections;

 

public class LoadingScene : MonoBehaviour

{

 

   public UISlider processBar;//进度条

   private AsyncOperation async;

   private uint _nowprocess;

   // Use this for initialization

   void Start()

    {

       _nowprocess = 0;

       StartCoroutine(loadScene());

    }

 

   IEnumerator loadScene()

    {

       //异步读取场景。

       async = Application.LoadLevelAsync("Scenename");

       async.allowSceneActivation = false;

       //读取完毕后返回,系统会自动进入目标场景

       yield return async;

 

    }

 

   void Update()

    {

       if (async == null)

       {

           return;

       }

 

       uint toProcess;

       Debug.Log(async.progress * 100);

       if (async.progress < 0.9f)

       {

           toProcess = (uint)(async.progress * 100);

       }

       else

       {

           toProcess = 100;

       }

 

       if (_nowprocess < toProcess)

       {

           _nowprocess++;

       }

 

       processBar.value = _nowprocess / 100f;

 

       if (_nowprocess == 100)

       {

           async.allowSceneActivation = true;

       }

    }

 

}

0 0
原创粉丝点击