- I have some scripts/assets for demos and internal tools.
- All those scripts are included in my project when I build.
You are not using special folders or platform-dependent compilation to exclude scripts/assets.
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
i have purchased VReasy asset ,,,when i importing it to unity its tool menu is not appeared in the upper bar ,,how can i fix that ??
There is already an official way to do this, and it's by putting the scripts and resources in any folder called "Editor". If you make a tool that is only ever used in the editor, you oughta put all of its assets inside a folder called "Editor" and it will not be included in the build at all. Symlinks are overkill and #if statements are ugly.
While it's noted that you can surround your editor-only code inside #if UNITY_EDITOR blocks, Unity will still throw errors in builds like "A scripted object [...] has a different serialization layout when loading. Did you #ifdef UNITY_EDITOR a section of your serialized properties in any of your scripts?" or even crash.
This means Unity is unable to strip the editor-only serialized data from builds, and so the solution only works in some specific cases.
There's no [SerializeFieldEditorOnly] equivalent, if that's what you need, you may want to look at the EditorOnly tag and the HideFlags.DontSaveInBuild (this flags don't apply to individual scripts on prefabs, idk about scenes).
Please sign in to leave a comment.