资讯动态

Unity Lua实现 加载场景Loading进度

发布时间:2026/8/9 1:34:28 来源:尧图企业网站定制
废话不多说 直接上代码local async UnityEngine.SceneManagement.SceneManager.LoadSceneAsync(sceneName) ShowLoadingAsync(async)---异步显示loading进度 local function ShowLoadingAsync(async) local toProgress 0 local displayProgress 0 async.allowSceneActivation false while (async.progress 0.89) do toProgress async.progress * 100 while (displayProgress toProgress) do displayProgress displayProgress 1 this.LoadingProgress displayProgress / 100.0 LogicEventDispatcher.SendWithArgs(LogicEventType.LoadSceneProgress,this.LoadingProgress) coroutine.step() end coroutine.step() end toProgress 100 while (displayProgress toProgress) do displayProgress displayProgress 1 this.LoadingProgress displayProgress / 100.0 LogicEventDispatcher.SendWithArgs(LogicEventType.LoadSceneProgress,this.LoadingProgress) coroutine.step() end async.allowSceneActivation true this.LoadingProgress 1.0 end把async.allowSceneActivation设置为false后Unity就只会加载场景到0.9那0.1要等到async.allowSceneActivation设置为true后才加载。所以当async.progress到达0.9后我们手动设置进度条的数值1然后设置async.allowSceneActivation为ture让Unity继续加载那10%的场景,显示上做了一个平滑处理。lua代码为纯手打第一次写博客有不对的地方欢迎指正。

读完文章,也想定制专属网站?

尧图设计师 24 小时内与您沟通定制方案

免费获取报价