loading通用界面笔记

Private Action proCB = null;

public void AsyncLoadScene(string sceneName, Action loaded)

    {

        loadingWnd.SetWndState();

        AsyncOperation sceneAsync = SceneManager.LoadSceneAsync(sceneName);

        prgCB = () =>

        {

            float val = sceneAsync.progress;

            loadingWnd.SetProgress(val);

            if (val == 1)

            {

                if (loaded != null)

                {

                    loaded();

                }

                prgCB = null;

                sceneAsync = null;

                loadingWnd.SetWndState(false);

            }

        };

}

void Update()

    {

        if (prgCB != null)

        {

            prgCB();

        }

    }

String sceneName;

AsyncLoadScene(sceneName,()=>{

//新场景加载成功后执行,初始化新场景

});

posted @ 2021-06-23 10:31  T驱动  阅读(37)  评论(0编辑  收藏  举报