Unity 编译顺序及原理
来源:互联网 发布:淘宝 买药 编辑:程序博客网 时间:2024/05/21 09:02
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.
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.
- Unity 编译顺序及原理
- Unity3d 编译顺序及原理
- Unity 特殊文件夹及脚本编译顺序
- unity 脚本编译顺序
- Unity脚本编译顺序
- Unity Editor编译顺序
- Unity脚本编译顺序
- Unity的特殊文件夹及脚本编译顺序
- Unity特殊文件及脚本编译顺序(Special folders and script compilation order)
- Unity特殊文件夹和脚本编译顺序
- unity 工程编译顺序(转)
- 编译原理及交叉编译
- unity 事件(顺序及功能说明)
- unity 事件顺序及功能的整理
- unity 事件顺序及功能的整理
- unity 事件(顺序及功能说明)
- unity 事件(顺序及功能说明)
- [Unity 热更新]tolua原理及实践
- hdu4982 暴搜+剪枝(k个数和是n,k-1个数的和是平方数)
- 【线性代数】方程组的几何解释
- 深入分析STL标准模板List的使用及事项
- 数据结构-【链表】单向链表的逆置和双向循环链表
- javascript原生移动云编程3 - 比web还简单的页面UI布局
- Unity 编译顺序及原理
- UVA10714
- Shell常识--校验和、核实以及加密--总结自《Linux Shell 脚本攻略》
- Spiral Matrix
- [Android View] QuickReturn (自动隐藏header/footer view)
- poj 2726 Holiday Hotel (排序&&单调栈)
- Openstack中创建虚拟机不能够ping通虚拟路由端口
- poj 3268 Silver Cow Party
- N的阶乘 有多少个末尾0