No, Unity will not include code in #if UNITY_EDITOR
in builds.
You can test this out with the following example:
void Start ()
{
#if UNITY_EDITOR
Debug.Log("Unity Editor");
#else
// note that this block of code is not included while working in the Editor,
// but it will be included when building to Android
// (or any other build target outside the editor)
Debug.Log("Not Unity Editor");
#endif
#if UNITY_ANDROID
Debug.Log("Android");
#endif
#if UNITY_STANDALONE_WIN
Debug.Log("Stand Alone Windows");
// Including a garbage line of code below to show
// that code really isn't included with the build
// when the build target doesn't match, e.g. set to Android
fkldjsalfjdasfkldjsafsdk;
#endif
}
If your build target is set to Android, your application should build despite the compilation error because the UNITY_STANDALONE_WIN
code is completely removed (and your IDE will likely gray out the code block). Once you change your build target to Windows, the code will fail to compile.
(Personally, I prefer to use Application.isEditor
over #if UNITY_EDITOR
macro as a habit whenever possible because of this, as using #if UNITY_EDITOR
with #else
can cause you to break the build without realizing until later for any code that fails to compile in the #else block. I am usually more concerned about this than extra useless code being included in my build. Of course, when using UnityEditor
classes, using #if UNITY_EDITOR
is unavoidable.)