Unity 保留了一些项目文件夹名称来指示内容具有特殊用途。其中一些文件夹会影响脚本编译的顺序。这些文件夹名称为:
请参阅特殊文件夹名称了解这些文件夹的用途。
脚本编译过程有四个独立的阶段。编译脚本的阶段由其父文件夹确定。
在脚本必须引用其他脚本中定义的类的情况下,这很重要。基本规则是无法引用在当前阶段之后的阶段编译的任何内容。在当前阶段或早期阶段编译的所有内容则是完全可用的。
当用一种语言编写的脚本必须引用另一种语言定义的类(例如,UnityScript 文件声明 C# 脚本中定义的类的变量)时,会出现另一种情况。这里的规则是被引用的类必须在早期阶段完成编译。
编译阶段如下:
体现此顺序非常重要的一个常见示例是 UnityScript 文件需要引用 C# 文件中定义的类时。要实现此引用,必须将 C# 文件放在 Plugins 文件夹中,并将 UnityScript 文件放在非特殊文件夹中。如果不这样做,则会抛出错误,指出无法找到 C# 类。
注意: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.