关卡Loading - daaoling/daaoling.github.io GitHub Wiki

Tags:Unity-项目实践

#制作平滑的关卡loading

原来把allowSceneActivation设置为false后,Unity就只会加载场景到90%, 剩下的10%要等到allowSceneActivation设置为true后才加载,这不得不说是一个坑。 所以代码改为如下。 当AsyncOperation.progress到达0.9后,就直接把进度条的数值更新为100%, 然后设置AsyncOperation.allowSceneActivation为ture,让Unity继续加载未完成的场景。

private IEnumerator StartLoading_4() {
    int displayProgress = 0;
    int toProgress = 0;
    AsyncOperation op = Application.LoadLevelAsync(1);
    op.allowSceneActivation = false;
    while(op.progress < 0.9f) {
        toProgress = (int)op.progress * 100;
        while(displayProgress < toProgress) {
            ++displayProgress;
            SetLoadingPercentage(displayProgress);
            yield return new WaitForEndOfFrame();
        }
    }

    toProgress = 100;
    while(displayProgress < toProgress){
        ++displayProgress;
        SetLoadingPercentage(displayProgress);
        yield return new WaitForEndOfFrame();
    }
    op.allowSceneActivation = true;
}

Unity3d中制作Loading场景进度条所遇到的问题

http://answers.unity3d.com/questions/934354/loadlevelasync-stops-at-90.html

http://answers.unity3d.com/questions/377666/how-do-you-use-asyncoperationallowsceneactivation.html

http://unity3d-book.blogspot.jp/2014/03/unity3d-preloading-scenes-with.html

svn export -r 33731 https://192.168.0.8/svn/lylc3d/program/client/abpack/window_x64 ./export

⚠️ **GitHub.com Fallback** ⚠️