Unity特殊文件及脚本编译顺序(Special folders and script compilation order)

来源:互联网 发布:一直正在准备windows 编辑:程序博客网 时间:2024/06/07 15:05

官方文档:

Unity reserves some project folder names to indicate that the contents have a special purpose. Some of these folders have an effect on the order of script compilation.

Unity保留了一些项目文件夹名称,以表明内容具有特殊用途。 其中一些文件夹对脚本编译的顺序有影响。

These folder names are:

  • Assets
  • Editor
  • Editor default resources
  • Gizmos
  • Plugins
  • Resources
  • Standard Assets
  • StreamingAssets
There are four separate phases of script compilation. The phase where a script is compiled is determined by its parent folder.
脚本编译有四个不同的阶段。 编译脚本的阶段由其父文件夹决定。
This is significant in cases where a script must refer to classes defined in other scripts. The basic rule is that anything that is compiled in a phase after the current one cannot be referenced. Anything that is compiled in the current phase or an earlier phase is fully available.
在脚本必须引用其他脚本中定义的类的情况下,这是很重要的。 基本规则是在当前编译之后的任何内容都不能被引用。 在当前阶段或更早阶段编译的任何内容都是完全可用的。
Another situation for this occurs when a script written in one language must refer to a class defined in another language (for example, a UnityScript file that declares variables of a class defined in a C# script). The rule here is that the class being referenced must have been compiled in an earlier phase.
当用一种语言编写的脚本必须引用另一种语言定义的类(例如,声明C#脚本中定义的类的变量的UnityScript文件)时,会发生另一种情况。 这里的规则是被引用的类必须在较早的阶段被编译。
The phases of compilation are as follows:
  • Phase 1: Runtime scripts in folders called Standard AssetsPro Standard Assets and Plugins.
  •  阶段 1:名为Standard AssetsPro Standard Assets 和Plugins文件夹下的运行时脚本。
  • Phase 2: Editor scripts in folders called Editor that are anywhere inside top-level folders called Standard AssetsPro Standard Assets and Plugins.
  •  阶段 2:名为Editor 文件夹下名为Standard AssetsPro Standard Assets 和Plugins的顶级文件夹的任何位置的编辑器脚本。
  • Phase 3: All other scripts that are not inside a folder called Editor.
  • 阶段 3:名为Editor文件夹之外的所有脚本。
  • Phase 4: All remaining scripts (those that are inside a folder called Editor).
  • 阶段 4:剩余的所有脚本(名为Editor文件夹内的)
A common example of the significance of this order occurs when a UnityScript file needs to reference a class defined in a C# file. To achieve this, you need to place the C# file inside a Plugins folder, and the UnityScript file in a non-special folder. If you don’t do this, an error is thrown saying that the C# class cannot be found.
当UnityScript文件需要引用C#文件中定义的类时,会发生此顺序的重要性的常见示例。 要实现这一点,您需要将C#文件放在Plugins文件夹中,将UnityScript文件放在非特殊文件夹中。 如果你不这样做,会抛出一个错误,指出找不到C#类。
Note: Standard Assets work only in the Assets root folder.
Standard Assets只能在Assets根文件夹下工作。