Unity 保留了一些项目文件夹名称来指示内容具有特殊用途。其中一些文件夹会影响脚本编译的顺序。这些文件夹名称为:
请参阅特殊文件夹名称了解有关这些文件夹的更多信息。
Unity 根据脚本文件在项目文件夹结构中的位置,以四个不同的阶段编译脚本。Unity 为每个阶段创建一个单独的 CSharp 项目文件 (.csproj) 和一个预定义的程序集。(如果没有符合编译阶段的脚本,Unity 不会创建相应的项目文件或程序集。)
当脚本引用在不同阶段编译的类(因此位于不同的程序集中)时,编译顺序很重要。基本规则是无法引用在当前阶段之后的阶段编译的任何内容。在当前阶段或早期阶段编译的所有内容则是完全可用的。
编译阶段如下:
阶段 | 程序集名称 | 脚本文件 |
---|---|---|
1 | Assembly-CSharp-firstpass | 名为 Standard Assets、Pro Standard Assets 和 Plugins 的文件夹中的运行时脚本。 |
2 | Assembly-CSharp-Editor-firstpass | 名为 Editor 的文件夹(位于名为 Standard Assets、Pro Standard Assets 和 Plugins 的顶级文件夹中的任意位置)中的 Editor 脚本。 |
3 | Assembly-CSharp | 不在名为 Editor 的文件夹中的所有其他脚本。 |
4 | Assembly-CSharp-Editor | 其余所有脚本(位于名为 Editor 的文件夹中的脚本)。 |
注意:Standard Assets 仅在 Assets 根文件夹中有效。
您可以创建程序集定义文件,从而使用自己的程序集来组织项目中的脚本。定义自己的程序集可以减少在进行不相关的代码更改时需要重新编译的代码量,并可提供对其他程序集的依赖性的更多控制。请参阅脚本编译 - 程序集定义文件以了解更多信息。
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.