|
If I put the following in a game object script, both will appear in the console when previewing with the Play button in the Editor. Does anyone know why UNITY_WEBPLAYER would evaluate to true while running in the editor? Is there another way for the build to detect that it is or isn't a web player? Thanks!
(comments are locked)
|
|
What you are using are compiler switches. They are some kind of constants to tell the compiler at compile time which code it should use. This is "selected" by the target platform you're actually using. If you switch the platform to standalone for example it would ignore the UNITYWEBPLAYER stuff. UNITYEDITOR is a special switch which is only active when Unity creates the temp-build to run inside the editor. What you need is this: Application.isWebPlayer. Thanks for that. I understand they are compile time directives, which is why I would expect anything in the UNITY_WEBPLAYER block to NOT be compiled when previewing in the Unity Editor. I must be missinng something. The other directives such as UNITY_STANDALONE_WIN are ignored correctly, just UNITY_WEBPLAYER is not working as I thought it should. Using the run-time check for isWebPlayer will work just fine. I'll use that. Thanks again!
Dec 13 '11 at 02:31 AM
breadman
The code within your #if UNITY_STANDALONE_WIN block will execute in the editor if you switch your build platform to standalone. Whether or not it's technically correct, I find this feature to be very useful for development in the editor when targeting multiple platforms. I look at it like this: The preprocessor directives will cause the editor to allow you to simulate different platforms. Application.platform, on the other hand, will only evaluate to a single platform and will distinguish between the editor and actual runtime platforms. It will even distinguish between Mac and PC for editor and web mode: http://unity3d.com/support/documentation/ScriptReference/RuntimePlatform.html
Dec 13 '11 at 03:02 AM
jahroy
It does seem like a bug that UNITY_WEBPLAYER is defined as true when running the game inside the editor.
Jul 14 '12 at 10:29 PM
tayl0r
@tayl0r: No, why do you think it's a bug? UNITY_WEBPLAYER just specifies the target platform. UNITY_EDITOR is an additional define which tells you that you run in the editor. You can combine the defines as you wish. for example: For more information see
Jul 15 '12 at 12:32 AM
Bunny83
I guess what I am forgetting is that whatever platform you have selected is what the editor will simulate. Once you realize that then it makes sense that UNITY_WEBPLAYER can be true in the editor. If you do not know this, it definitely seems like a bug. Personally I just realized there was a little "switch platform" in the Build Settings. I thought you had to actually build for that platform in order to switch.
Jul 15 '12 at 09:44 AM
tayl0r
(comments are locked)
|

The preprocessor directives will reflect the currently selected build platform.
If you're using a Mac and you switch your platform to standalone, any code within a #if UNITY_STANDALONE_OSX block will execute.
According to Bunny's answer, it sounds like the evaluation of the UNITY_EDITOR directive has nothing to do with the current platform and will always be true in the editor.
If you change your syntax to use an #elif, you will get the desired result.
http://msdn.microsoft.com/en-us/library/ed8yd1ha%28v=vs.71%29.aspx
(I don't think all of those work ^^)
You could also test for either editor or webplayer mode like this: