Is there some way for C# code to detect when it is running in the editor? For example, I want some debugging buttons to exist when running in the editor, but not when I build a web player version.
There isn't a define, but there is a property you can check for
if (Application.isEditor)
{
//do stuff
}
http://unity3d.com/support/documentation/ScriptReference/Application-isEditor.html
As of Unity 3 there is now a UNITY_EDITOR define you can use.
If you have code that you only want in the editor, you can now do things like (C#) ...
void OnGUI()
{
#if UNITY_EDITOR
if (GUILayout.Button("Edit"))
{
DoSpecialEditorStuff();
}
#endif
}
You can apply this to methods, variables, even whole classes. Just be careful not to use something defined inside the #if block from a location outside such a block or you will have compilation problems on platforms where the code is compiled out.
Check out MSDN for more info on the C# preprocessor.
For more details on Unity's preprocessor defines, see the docs. There are also defines for the Unity version.
Another one you can use for debugging is Debug.isDebugBuild. That is always true in the editor, but you can also see it in the runtime if you build with the "Development Build" option.