脚本的编译顺序


官方手册地址:Special Folders and Script Compilation Order


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 AssetsPro Standard Assets and Plugins.

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

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

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

4个编译阶段是:

1. 在Standard AssetsPro Standard Assets , Plugins 这三个文件夹中的运行时脚本。

2. 在Standard Assets/EditorPro Standard Assets/Editor and Plugins/Editor.文件夹中的的编辑器脚本。

3. 不在Editor文件夹的其他脚本。

4. 其他脚本(在Assets/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).

另外,在Assets/WebPlayerTemplates/ 下的任何脚本都不会被编译。在子文件夹中,规则有点细微区别( Scripts/Editor 会被作为Editor文件夹,但是Scripts/WebPlayerTemplates也会编译,就是说WebPlayerTemplates只有在最顶层会被作为特殊文件夹,Editor等在子文件夹内也会作为特殊文件夹对待)。

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放到普通文件夹里。如果不这样干,就会报错说c#的类找不到。



unityscript就是javascript。在unity里改变原javascript的一些特效改称为unityscript。


脚本编译顺序对于不同语言写的脚本的引用,或者引用插件(一般插件自己就放好了地方)有必要了解这个规则。

项目在编译后会生成4个项目文件,如果使用了2种脚本语言会生成2套项目文件。

vs结尾的是给Vistual Studio用,另外一种给MonoDevelop用。以下4个工程的执行顺序如排列。

Assembly-CSharp-firstpass.csproj 
Assembly-CSharp-Editor-firstpass.csproj 
Assembly-CSharp.csproj 
Assembly-CSharp-Editor.csproj

参考这篇文章: http://www.cnblogs.com/champ/p/execorder.html


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
毕设新项目-基于Java开发的智慧养老院信息管理系统源码+数据库(含vue前端源码).zip 【备注】 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用!有问题请及时沟通交流。 2、适用人群:计算机相关专业(如计科、信息安全、数据科学与大数据技术、人工智能、通信、物联网、自动化、电子信息等)在校学生、专业老师或者企业员工下载使用。 3、用途:项目具有较高的学习借鉴价值,不仅适用于小白学习入门进阶。也可作为毕设项目、课程设计、大作业、初期项目立项演示等。 4、如果基础还行,或热爱钻研,亦可在此项目代码基础上进行修改添加,实现其他不同功能。 欢迎下载!欢迎交流学习!不清楚的可以私信问我! 毕设新项目-基于Java开发的智慧养老院信息管理系统源码+数据库(含vue前端源码).zip毕设新项目-基于Java开发的智慧养老院信息管理系统源码+数据库(含vue前端源码).zip毕设新项目-基于Java开发的智慧养老院信息管理系统源码+数据库(含vue前端源码).zip毕设新项目-基于Java开发的智慧养老院信息管理系统源码+数据库(含vue前端源码).zip毕设新项目-基于Java开发的智慧养老院信息管理系统源码+数据库(含vue前端源码).zip毕设新项目-基于Java开发的智慧养老院信息管理系统源码+数据库(含vue前端源码).zip毕设新项目-基于Java开发的智慧养老院信息管理系统源码+数据库(含vue前端源码).zip毕设新项目-基于Java开发的智慧养老院信息管理系统源码+数据库(含vue前端源码).zip毕设新项目-基于Java开发的智慧养老院信息管理系统源码+数据库(含vue前端源码).zip
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值