出错原因
Editor类库无法在build后运行时使用。
场景中存在挂载有编辑器工具脚本的物体,且没有做“编辑器处理”。
我遇到的报错
(仅有的)主要错误:
error CS0103: The name 'AssetDatabase' does not exist in the current context
error CS0103: The name 'EditorUtility' does not exist in the current context
解决方法
Unity已经准备好了“模式”宏定义:UNITY_EDITOR
使用以下语句包裹含有编辑器类库使用的代码段即可使Unity在Build时不处理此段代码
// 检查是否处于编辑模式
#if UNITY_EDITOR
// 含有编辑器类库使用的代码段
#endif
// 其他部分