Symptoms:
- I have some scripts/assets for demos and internal tools.
- All those scripts are included in my project when I build.
Cause:
You are not using special folders or platform-dependent compilation to exclude scripts/assets.
Resolution:
Currently, there is no way to exclude directories from the build process, but there are some workarounds:
Suppose you have an internal tool that only adds functionality to the Editor itself. In that case, you can put all the scripts inside a folder called Editor anywhere inside the Assets folder. If you require assets for your tools, like images or models, create a resource inside your Editor folder to exclude the assets from any builds you make.
You can get a similar effect by using assembly definitions. To do that, create a folder with the scripts you want to exclude and create an assembly definition asset inside. On the inspector in the included platforms section, only select Editor. This way, builds won't include the scripts.
To exclude specific scripts, you can use the macro UNITY_EDITOR at the start of your code.
#if (UNITY_EDITOR) ... your class/code ... #endif
You can also use this to exclude parts of your code instead of the whole script, like extra debug code or methods only intended for use in the editor. One example could be a method that skips a level with a particular input.
To exclude directories, you can use symlinks (symbolic links). Try putting the scripts you want to exclude in a folder outside the Assets folder, and create a symlink into Resources that points to that folder. So when you want to exclude those assets, you need to remove the symlink and recreate it after you make a build.
OTestCode/ MyProject/Assets/TestCode >> OTestCode
More Information