运行模式是 Unity 的核心功能之一。借助运行模式,可通过工具栏 中的 Play 按钮直接在 Editor 中运行项目。进入运行模式时,项目将像构建后一样启动并运行。退出运行模式时,运行模式期间在 Editor 中所做的任何更改都会重置。
在 Editor 中进入运行模式时,Unity 将执行两项重要操作,以确保项目在 Editor 中的启动方式与在构建后的启动方式相同:
执行这两个操作需要花费一些时间,并且随着脚本和场景变得越来越复杂,时间也会随之增加。
在开发游戏或应用程序时,快速进入和退出运行模式的能力是一个重要考虑因素。进入和退出运行模式的速度越快,进行更改和测试更改的速度就越快。
由于开发过程中快速的迭代速度很重要,并且由于重置场景和脚本状态的时间可能会成为障碍,因此 Unity 允许配置进入运行模式时执行的操作,从而可以选择禁用“域重新加载”和/或“场景重新加载”操作。这两个选项由可配置的进入运行模式 (Configurable Enter Play Mode) 功能提供。
下图显示了禁用“重新加载域”(Reload Domain) 和“重新加载场景” (Reload Scene) 设置的效果。
To configure the Enter Play Mode settings, go to Edit > Project Settings > Editor and enable Enter Play Mode Options. When you enable this, the options to reload domain and reload scene become available.
启用 Reload Domain 选项可启用域重新加载。启用 Reload Scene 选项可启用场景重新加载。
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.