Keep Editor playing while in background

Is there a way to keep the Editor running it’s play mode while in the background? Currently as soon as I focus another window, the Editor will suspend itself until focus is returned.

See: How do you keep your game running even when you switch out of it? - Questions & Answers - Unity Discussions

It’s in Edit → Project Settings → Player

But… this comment from jashan seems important:

Some people aren’t finding this in
more recent versions of Unity. But
it’s still there: In Player settings,
under the section “Resolution and
Presentation”, you find “Resolution”
and below that, there’s “Run In
Background”.

This is only available for Web players
and standalones, though (you won’t
find it when you have the iOS, Android
or Flash tab selected.

If you want something for the editor, put the following in a script called RunEditorInBackground and put in a folder called Editor:

using UnityEngine;
using UnityEditor;

[InitializeOnLoad]
public class RunEditorInBackground  : EditorWindow
{
    // This constructor is called on load because of Initialise on Load tag
    static RunEditorInBackground()
    {
        // Need to delay this as cant call EditorPrefs in static constructor
        EditorApplication.playModeStateChanged += Running;
    }

    private static void Running(PlayModeStateChange obj)
    {
        if(EditorApplication.isPlaying)
            Application.runInBackground = true;
    }
}

Here; from the answers here I put a toggle for it in the editor menu; stick this in your Editor folder somewhere:

using UnityEditor;
using UnityEngine;

[InitializeOnLoad]
public class PlayInBackground : MonoBehaviour {

    const string ITEM = "Edit/Play In Background";

    static PlayInBackground () {
        EditorApplication.delayCall += InitMenu;
    }

    static void InitMenu () {
        Menu.SetChecked(ITEM, Application.runInBackground);
    }

    [MenuItem(ITEM, priority = 300)]
    public static void TogglePlayInBackground () {
        Menu.SetChecked(ITEM, !Menu.GetChecked(ITEM));
        Application.runInBackground = Menu.GetChecked(ITEM);
    }

}

The menu item will probably be down towards the bottom of the Edit menu.

That’s a setting that’s saved with the project already so it’ll persist.

IMPORTANT: This is the same setting as “Run in Background” in the Build Settings, so if that setting is important for your platform, make sure it’s set back to the correct value before a build!!

There’s some bugs here in that the check state won’t change if you change the Build Setting, and sometimes vice versa, but, I mean… I’m certainly not going to fix them. Seems to work well enough.