Unity3d:场景加载 GameObejct上脚本执行顺序
场景1脚本
public class LoadScene1 : MonoBehaviour { // Start is called before the first frame update void Start() { StartCoroutine(StartScene()); } IEnumerator StartScene() { AsyncOperation aync = SceneManager.LoadSceneAsync("LoadScene2", LoadSceneMode.Additive); while (aync.isDone == false) { Debug.Log(aync.progress); yield return null; } Debug.Log("LoadOK"); yield return null; } }
场景2某个物体上挂载
public class LoadScene2 : MonoBehaviour { private void Awake() { Debug.Log("Awake"); } // Start is called before the first frame update void Start() { Debug.Log("Start"); } private void OnEnable() { Debug.Log("OnEnable"); } private void Update() { Debug.Log("Update"); } }
场景2截图
执行后输出
可以看到,加载LoadScene2完成,会执行LoadScene2里所有的GameObject的Awake,OnEnable,Start,和update会执行一次,再真正加载完场景
所以,在优化场景加载时,代码层面关注新场景里固有GameObject上脚本里执行逻辑复杂度
posted on 2022-05-10 22:31 luoyikun 阅读(30) 评论(0) 编辑 收藏 举报 来源
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?