Version: 2022.2

InitializeOnLoadAttribute

class in UnityEditor

切换到手册

描述

允许在 Unity 加载时和重新编译脚本时初始化 Editor 类。

重新编译项目中的脚本时,会调用带有此属性的静态构造函数(也称为域重新加载)。在 Unity 首次加载项目时、在 Unity 检测到脚本修改时(取决于自动刷新首选项),以及当进入运行模式时(取决于运行模式配置),会进行此调用。

Asset operations such as asset loading should be avoided in InitializeOnLoad methods. InitializeOnLoad methods are called before asset importing is completed and therefore the asset loading can fail resulting in a null object. To do initialization after a domain reload which requires asset operations use the AssetPostprocessor.OnPostProcessAllAssets callback. This callback supports all asset operations and has a parameter signaling if there was a domain reload.

另请参阅:启动时运行编辑器代码

Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961