Unity3d 编译顺序及原理





Unity compiles all scripts to .NET dll files. The .dll files will be jit compiled at runtime.

 

This allows incredibly fast script execution. It is around 20 times  faster than traditional javascript and around 50% slower than native C++  code. Unity might take a second to compile all your scripts when you save it. You can see if Unity is still compiling with the small spinning progress  icon in the lower right corner of Unity's main window.

Script compilation is performed in 4 steps:

1. All scripts in "Standard Assets", "Pro Standard Assets" or "Plugins" are compiled first.

Scripts in one of these folders can't directly access scripts outside these folders.

It is not possible to reference the class or its variables directly, but it is possible to communicate with them using GameObject.SendMessage.

2. All scripts in "Standard Assets/Editor", "Pro Standard Assets/Editor" or "Plugins/Editor" are compiled first.

If you want to use the UnityEditor namespace you have to place your scripts in these folders. For example to add menu items or write custom wizards you have to place your scripts in those folders.

These scripts can access scripts from the previous group.

3. All scripts in "Editor" are compiled next.

If you want to use the UnityEditor namespace you have to place your scripts in these folders. For example to add menu items or write custom wizards you have to place your scripts in those folders.

These scripts can access all scripts in all previous groups. However they can not access scripts, in the last group.

This can be a problem when wirting editor code since you often want to edit scripts that are in the last group. There are two solutions: 1. Move the other script into the "Plugins" folder. 2. Take advantage of JavaScript's dynamic typing. In Javascript you don't need to know the type of a class to work with it. When using GetComponent you can just use a string instead of the type. You can also use SendMessage, which takes a string.

4. All other scripts are compiled last.

All scripts that are not in the folders above are compiled last.

All scripts that are compiled in this step have access to all scripts in  the first group ("Standard Assets", "Pro Standard Assets" or  "Plugins"). This allows you to let different scripting languages interoperate. For example, if you want to create a Javascript that uses a C# script:  place the C# script in the "Standard Assets" folder and the Javascript  outside of the "Standard Assets" folder. The Javascript can now reference the C# script directly.

Scripts that are placed in the first group, will take longer to compile,  since when they are compiled the third group needs to be recompiled  too. Thus if you want to reduce compile times, move scripts that seldomly  change into group 1 and scripts that change a lot into group 4.

Conditional compilation against the Unity version.

Starting with Unity version 2.6 a C# preprocessor define has been added.  The define identifies the version of Unity in use and is intended to allow conditional access to specific features.  For example:

 

// Specific version define including the minor revision

#if UNITY_2_6_0

// Use Unity 2.6.0 specific feature

#endif

 

// Specific version define not including the minor revision

#if UNITY_2_6

// Use Unity 2.6.x specific feature

#endif

 

This code can be used to enable game features that are only available with a specific version of Unity. Note that this define is present from version 2.6 only. Future Unity versions will provide the appropriate define to identify the version to your scripts.







课程总体目标:     本中级篇面向的学员不再是完全的编程“小白”,而是具备一定C#编程经验,需要进一步查漏补缺、或者需要进一步全面完善自己C#编程知识体系的广大Unity学员。相信通过本中级篇的学习,可以使得Unity初中级开发人员对于编程语言的掌握更进一步;对于开发中大型游戏项目,在编程语言这一层级进一步打下坚实的语言基础。 “中级篇”课程讲解特点:       本中级篇面向初中级游戏研发人员,以及Unity中高级学习者。为了更加深入的刨析各个语法的本质,我们采用反编译解读IL中间语言的方式,来解构语法难点,使得学员最短时间掌握语法本质。 本课程讲解内容:       C#(for Unity)中级篇 在“C#入门”、“基础篇”的基础之上,从以下四个方面着重研究我们游戏开发(包含软件开发)过程中,C#最重要、最实用的技能模块,使得广大游戏研发人员,对于C#这门Unity脚本有进一步更加完善的认识。一:.Net 框架讲解。    A) .Net 发展历史。    B)  IL  中间语言。 CLR  公共语言运行时。    C) 多维数据(常用二维数组)与交错数组。    D) 可变参数 Params    E) 进一步解释“实参”,“形参”。    F) 类的实例化内存分配机制。二:深入学习对象类型    A)  里氏替换原则(LSP)    B)  类的属性极其本质特性    C)  IS ,AS 关键字    D)  深入学习字符串理论        1] 字符串的“驻留性” 原理。        2] 字符串==与Equals() 的本质区别        3] 更多字符串常用方法学习。    E)  枚举类型以及适用场合。三:深入学习集合特性    A)  什么是索引器,以及索引器的适用范围。    B)  学习自定义集合类,以及深入了解Foreach 语句的原理。    C)  深入学习 ArrayList,了解内部存储机制以及原理。    D)  深入学习 HashTable,了解内部存储机制以及原理。    E)  为什么学习泛型集合?    F)  泛型集合与普通集合的性能测试对比实验。    G)  学习“泛型约束”,以及“泛型约束”的适用条件。四:委托与事件        A)  什么是委托,先从讲故事学习起:“老板来啦”!    B)  反编译掌握委托的本质。    C)  委托的四大开发步骤。    D)  什么是事件,以及委托与事件的区别。    E)  事件的常用使用方式。 温馨提示:       本C# for Unity 使用Virtual Studio2012,进行开发与讲解。(学员使用更高版本,对学习没有任何影响) 一、热更新系列(技术含量:中高级):A:《lua热更新技术中级篇》https://edu.csdn.net/course/detail/27087B:《热更新框架设计之Xlua基础视频课程》https://edu.csdn.net/course/detail/27110C:《热更新框架设计之热更流程与热补丁技术》https://edu.csdn.net/course/detail/27118D:《热更新框架设计之客户端热更框架(上)》https://edu.csdn.net/course/detail/27132E:《热更新框架设计之客户端热更框架(中)》https://edu.csdn.net/course/detail/27135F:《热更新框架设计之客户端热更框架(下)》https://edu.csdn.net/course/detail/27136二:框架设计系列(技术含量:中级): A:《游戏UI界面框架设计系列视频课程》https://edu.csdn.net/course/detail/27142B:《Unity客户端框架设计PureMVC篇视频课程(上)》https://edu.csdn.net/course/detail/27172C:《Unity客户端框架设计PureMVC篇视频课程(下)》https://edu.csdn.net/course/detail/27173D:《AssetBundle框架设计_框架篇视频课程》https://edu.csdn.net/course/detail/27169三、Unity脚本从入门到精通(技术含量:初级)A:《C# For Unity系列之入门篇》https://edu.csdn.net/course/detail/4560B:《C# For Unity系列之基础篇》https://edu.csdn.net/course/detail/4595C: 《C# For Unity系列之中级篇》https://edu.csdn.net/course/detail/24422D:《C# For Unity系列之进阶篇》https://edu.csdn.net/course/detail/24465四、虚拟现实(VR)与增强现实(AR):(技术含量:初级)A:《虚拟现实之汽车仿真模拟系统 》https://edu.csdn.net/course/detail/26618五、Unity基础课程系列(技术含量:初级) A:《台球游戏与FlappyBirds—Unity快速入门系列视频课程(第1部)》 https://edu.csdn.net/course/detail/24643B:《太空射击与移动端发布技术-Unity快速入门系列视频课程(第2部)》https://edu.csdn.net/course/detail/24645 C:《Unity ECS(二) 小试牛刀》https://edu.csdn.net/course/detail/27096六、Unity ARPG课程(技术含量:初中级):A:《MMOARPG地下守护神_单机版实战视频课程(上部)》https://edu.csdn.net/course/detail/24965B:《MMOARPG地下守护神_单机版实战视频课程(中部)》https://edu.csdn.net/course/detail/24968C:《MMOARPG地下守护神_单机版实战视频课程(下部)》https://edu.csdn.net/course/detail/24979
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值