Special Folders and Script Compilation Order [Unity]

For the most part, you can choose any names you like for thefolders in your project but Unity reserves some names to indicatethat the contents have a special purpose. Some of these foldershave an effect on the order of script compilation. Essentially,there are four separate phases of script compilation and the phasewhere a script will be compiled is determined by its parentfolder.

This is significant in caseswhere a script must refer to classes defined in other scripts. Thebasic rule is that anything that will be compiled in aphase after the currentone cannot be referenced. Anything that is compiled in the currentphase or an earlier phase is fully available

Another situation occurs when a script written in one language mustrefer to a class defined in another language (say, a UnityScriptfile that declares variables of a class defined in a C# script).The rule here is that the class being referenced must have beencompiled ina earlier phase.

The phases of compilation are as follows:-

Phase 1: Runtime scripts infolders called StandardAssetsPro StandardAssets and Plugins.

Phase 2: Editor scripts infolders called StandardAssets/EditorPro StandardAssets/Editor and Plugins/Editor.

Phase 3: All other scripts thatare not inside a foldercalled Editor.

Phase 4: All remaining scripts(ie, the onesthat are inside a foldercalled Editor).

Additionally, any script inside a foldercalled WebPlayerTemplates atthe top level of the Assets folder will not be compiled at all.This behaviour is slightly different from the other special foldernames which also work within sub-folders (eg, Scripts/Editor worksas an editor script folder but Scripts/WebPlayerTemplates does notprevent compilation).

A common example is where a UnityScript file needs to reference aclass defined in a C# file. You can achieve this by placing the C#file inside a Plugins folder and the UnityScript file in anon-special folder. If you don’t do this, you will get an errorsaying the C# class cannot be found.

已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页