- Home /
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!
Answer by DaveA · Mar 20, 2012 at 06:51 PM
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)
Answer by solarisn · Nov 18, 2018 at 01:21 AM
UNITY_EDITOR_WIN and UNITY_EDITOR_OSX are available in the latest versions of Unity. Not sure which version this got introduced, though.
Answer by Demigiant · Jan 03, 2015 at 12:27 PM
Application.platform should return the correct result while in the editor.
bool isWinEditor = Application.platform == RuntimePlatform.WindowsEditor;
bool isOSXEditor = Application.platform == RuntimePlatform.OSXEditor;
Answer by mark_madatom · Nov 05, 2014 at 11:31 AM
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 http://www.mono-project.com/docs/faq/technical/ and http://msdn.microsoft.com/en-us/library/3a8hyw88(v=vs.110).aspx.