Does code wrapped in ‘#if UNITY_EDITOR’ appear anywhere in builds in a way that could be reverse engineered and discovered by malicious users?
I know that the code itself would not be executed, but I’m wondering whether it would appear anywhere at all in the final build (as plain text, for example).
No, it’s not included in the build.
None of your C# or js code will appear in the build as plain text. Everything is compiled into Common Intermediate Language (IL for short). IL is a translation of your code that’s faster for the runtime to read and execute. It’s much less readable, but it can still be translated back into C#. There are tools that can make your code more difficult to read even if it is translated back. (read up on .NET obfuscators)
But regarding #if UNITY_EDITOR. The #if check happens at compile time and if the condition isn’t met, whatever is inside it won’t be included in the compilation. It won’t be turned into IL. It won’t be in the build.
So reason why “the code would not be executed” is because it won’t be there at all.
@BMayne poses a good question though. What are you doing in there that’s so dangerous?
This is called “conditional compilation”. That symbol isn’t defined when doing a build, so the code inside of it can’t appear in the build because it doesn’t exist.