Overview: Script compilation (Advanced) Manual     Reference     Scripting  
Overview: スクリプトのコンパイル(Script compilation (Advanced))


こ れは、非常に速いスクリプト実行を可能にします。古典的なJavascriptに比べて20倍速く、ネイティブのC++コードに比べて50%遅い程度で す。Unityは保存した際に2度目のコンパイルを行ないます。Unityがコンパイル中であるかどうかは、メインウィンドウの右下に表示される小さな回 転しているアイコンで確認できます。


1. "Standard Assets", "Pro Standard Assets", "Plugins"の全てのスクリプトがはじめにコンパイルされます



2. Standard Assets/Editor", "Pro Standard Assets/Editor", "Plugins/Editor"が先にコンパイルされます。



3. 次に"Editor"中の全てのスクリプトがコンパイルされます。



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

// Specific version define not including the minor revision
#if UNITY_2_6
// Use Unity 2.6.x specific feature

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.