How to know if I'm running UNITY_EDITOR on Windows or Mac?

I have a script that I like to run on Windows/Mac in Unity Editor,
which is truly platform dependent. I found that UNITY_EDITOR will be effective for both platforms, but there is no obvious way to tell if I’m running the editor on Windows or Mac.

Any ideas?
Thanks!

4 Answers

4

I see these options here: http://unity3d.com/support/documentation/ScriptReference/RuntimePlatform.html

That's for runtime but the original poster was asking about the editor platform, so that's the wrong answer.

Actually those should work even while in the editor (see my answer below)

UNITY_EDITOR_WIN and UNITY_EDITOR_OSX are available in the latest versions of Unity. Not sure which version this got introduced, though.

I needed to do this, but couldn’t find anything in Unity itself, so ended up using a .NET Framework API. Below is the code I use, which is based on the code in the answer to the “How to detect the execution platform?” question in the Mono technical FAQ. It returns false on Windows and true on Mac (and other Unix-like OSes):

    public static bool IsUnix()
    {
        var platform = (int)System.Environment.OSVersion.Platform;
        return (platform == 4) || (platform == 6) || (platform == 128);
    }

More details at FAQ: Technical | Mono and PlatformID Enum (System) | Microsoft Learn.

Application.platform should return the correct result while in the editor.

bool isWinEditor = Application.platform == RuntimePlatform.WindowsEditor;
bool isOSXEditor = Application.platform == RuntimePlatform.OSXEditor;