- Home /
UnityEditor Pre-compliler Defines for differentiating between Windows & Mac OSX
We are using Unity in an Windows & Mac OSX environment, with our primary development environment being Windows. This means that some of our plugins and tools are Windows Specific. I would like to be able to exclude and/or include Windows vs Mac OSX environment specific components (Assets, Scripts, Libraries, etc.).
Is there a pre-compiler define? Is there another way to determine this without using the RuntimePlatform API? Is there way to determine the environment from the Unity Executable?
Answer by iwaldrop · Jun 19, 2013 at 11:57 PM
Yes, there are defines for standalone platforms. See this page.
In short, you want either UNITY_STANDALONE_OSX or UNITY_STANDALONE_WIN.
In order to tell whether the Unity Editor is running on a particular platform, use these enum flags:
RuntimePlatform.OSXEditor and RuntimePlatform.WindowsEditor
Hi iwaldrop,
Yes, I am aware of the Pre-compiler defines, but they are Windows & $$anonymous$$ac OSX environment agnostic. They are used for the targeted UnityEditor Player and the Windows & $$anonymous$$ac Standalone Players.
ie. #if UNITY_EDITOR && UNITY_STANDALONE_WIN will still return true when running UnityEditor on $$anonymous$$ac.
One such scenario that I am dealing with is GamePad Input when using the UnityEditor on Windows vs $$anonymous$$ac has to be mapped uniquely for each environment. If I use the above #if UNITY_EDITOR && UNITY_STANDALONE_WIN, while developing on a $$anonymous$$ac, then the GamePad Input mappings will be incorrect.
I believe I can achieve the result I want via RuntimePlatform API. Unfortunately that does not solve issues with say Windows vs $$anonymous$$ac compatible .dlls that must be included/excluded from the environment via the AssetPostprocessor API.
First, I've converted your answer to a comment.
Second, I misunderstood that you were talking about running the Unity Editor. Use these enum flags to check for the editor.
RuntimePlatform.OSXEditor and RuntimePlatform.WindowsEditor
You'll probably want to wrap them, like so:
#if UNITY_EDITOR
if (Application.platform == RuntimePlatform.OSXEditor)
{
// do osx editor stuff
}
else if (Application.platform == RuntimePlatform.WindowsEditor)
{
// do windows editor stuff
}
#endif
Damn...I'm in a hurry today and didn't read the last part of your comment. Yeah, that kind of sucks. One way around it may be to use Actions and Funcs to encapsulate platform functionality. Another way might be to use an interface to instantiate particular classes based on the platform that you're using. Alas, I don't have any experience with running in multi-platform development environments. Sorry, and good luck!
Thanks iwaldrop for your responses and I will take your suggestions into consideration. I may just ping Unity Tech support for a feature request if I don't stumble upon a solution.
Your answer
![](https://koobas.hobune.stream/wayback/20220613104512im_/https://answers.unity.com/themes/thub/images/avi.jpg)