纳金网

标题: 特殊的文件夹和脚本的编译顺序 [打印本页]

作者: 狂风大尉    时间: 2014-7-31 21:52
标题: 特殊的文件夹和脚本的编译顺序
原文来自官方文档,这是我自己的渣翻
Special Folders and Script Compilation Order
特殊的文件夹和脚本的编译顺序

For the most part, you can choose any names you like for the folders in your project but Unity reserves some names to indicate that the contents have a special purpose. Some of these folders have an effect on the order of script compilation. Essentially, there are four separate phases of script compilation and the phase where a script will be compiled is determined by its parent folder.

在很多情况下,你可以为你的文件夹取任意的名字。但是Unity为了一些特殊的目的,保留了一些文件夹名字。有一些文件夹对在其内脚本的编译顺序有影响。重要的是,这里有4个独立的代码编译阶段。而且每一个阶段的顺序取决于其父文件夹。

This is significant in cases where a script must refer to classes defined in other scripts. The basic rule is that anything that will be 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 occurs when a script written in one language must refer to a class defined in another language (say, 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 a earlier phase.

另一个情况是当脚本的语言引用语言不同的另一个脚本的时候(比如说,一个UnityScript的文件中有一个变量是来自于C#的),这个规则是,被引用的脚本的编译时期必须早于这个脚本。

The phases of compilation are as follows:-

编译的时期是:

Phase 1: Runtime scripts in folders called Standard Assets, Pro Standard Assets and Plugins.

1:在Standard Assets, Pro Standard Assets and Plugins.中的运行时脚本

Phase 2: Editor scripts in folders called Standard Assets/Editor, Pro Standard Assets/Editor and Plugins/Editor.

2:在Standard Assets/Editor, Pro Standard Assets/Editor and Plugins/Editor.中的编辑器脚本

Phase 3: All other scripts that are not inside a folder called Editor.

3: 所有不再Editor文件夹下的脚本

Phase 4: All remaining scripts (ie, the ones that are inside a folder called Editor).

4:剩下的脚本(比如说在Editor下的脚本)

Additionally, any script inside a folder called WebPlayerTemplates at the top level of the Assets folder will not be compiled at all. This behaviour is slightly different from the other special folder names which also work within sub-folders (eg, Scripts/Editor works as an editor script folder but Scripts/WebPlayerTemplates does not prevent compilation).

另外的,在WebPlayerTemplates 文件夹下的脚本,且在Assets文件夹下的时候,那他完全不会被编译。这个行为和其他特殊名字的文件夹下的子文件夹有一点小小的不一样(比如说 Script/Editor 和Editor下的脚本有一样的效果,但是Script/WebPlayerTemplates会被阻止编译)

A common example is where a UnityScript file needs to reference a class defined in a C# file. You can achieve this by placing the C# file inside a Plugins folder and the UnityScript file in a non-special folder. If you don't do this, you will get an error saying the C# class cannot be found.

一个通用的例子是,当一个UnityScript的文件引用一个C#的脚本。你可以实现,当你把C#脚本放在Plugins文件夹下而且同时UnityScript不再一个特殊文件夹下。如果你不这么做。你会被提示一个错误which说C#类没有被找到


作者: HIDEOKOJIMA    时间: 2014-7-31 22:01
Thanks for sharing this !
作者: hyui    时间: 2014-7-31 22:17
Thanks for sharing !
作者: 我不再年轻    时间: 2014-8-1 15:01
很好用, 多些分享




欢迎光临 纳金网 (http://c-www.narkii.com/club/) Powered by Discuz! X2.5