Unity场景预加载

async.allowSceneActivation = false;

private AsyncOperation async;

async = SceneManager.LoadSceneAsync("MainScene");

async.allowSceneActivation = false;

yield return StartCoroutine(Loading());


IEnumerator Loading()
{
    float curProgress = 0f;
    while (curProgress<=1f)
    {
         float toProgress = async.progress/0.9f;
         while (curProgress<toProgress)
         {
             curProgress += 0.01f;
             loadbarClass.SetProgress(curProgress);
             yield return new WaitForEndOfFrame();
          }
     }
}
//
async.allowSceneActivation = true;

 

posted @ 2024-05-20 10:34  weigang  阅读(64)  评论(0编辑  收藏  举报