Execute code when in editor in game in plugin

Is there any way to execute code only when in the editor that references UnityEditor in plugin code?

Maybe I’m unclear on what a plugin is. I’m assuming a plugin is 1 or more .DLLs which means #if UNITY_EDITOR isn’t going to work because that works at compile time and the code is compiled into a .DLL

If it was just a script in Assets I’d use

 #if UNITY_EDITOR
     ObjectThatIsOnlyDefinedInEditor.Init();
 #endif

But it’s not, it’s part of a plugin.

Since your “HappyFunTimeEditor” assembly is an editor assembly it’s only available from editor scripts. You can’t reference that assembly from runtime scripts since editor assemblies aren’t referenced when Unity compiles your runtime scripts. So your “HFTEditorHook.cs” should be in a an editor folder as well.

If you need some kind of interaction in your runtime scripts you should use an interface defined in a runtime script which can be implemented by your editor script. That way you can access the functionality in a generic way.

Since we don’t know the purpose of your editor plugin and what kind of interaction you need we can’t go more into detail at this point.