What's the difference between "#if UNITY_WP8" and "#if WINDOWS_PHONE"

what’s the difference between “#if UNITY_WP8” and “#if WINDOWS_PHONE”

1 Like

The former is defined when compiling your scripts and when Unity Editor is working in Windows Phone 8 mode. The second one is enabled when you’re compiling code with Visual Studio for Windows Phone.

Will WINDOWS_PHONE get stripped out when we Build?

I have the following but it seems to always hit the NotImplementedException (and I did double check that WINDOWS_PHONE is being declared in my Visual Studio Project):

public void Connect(string hostName, int port)
{
#if NETFX_CORE || WINDOWS_PHONE
var thread = EnsureSocket(hostName, port);
thread.Wait();
#else
throw new NotImplementedException();
#endif

I am concerned that when hitting Build in Unity3D to build the Visual Studio project that it is stripping out the NETFX_CORE and WINDOWS_PHONE area of code.

WINDOWS_PHONE is not defined when building scripts. Use UNITY_WP8 for that.

  • NETFX_CORE define depends on compiler used. This is controled via compilation overrides setting in player settings.

Thanks. I haven’t been able to get a clean compile yet in Windows Store so perhaps NETFX_CORE will work in my setup once I get everything ported correctly. We are using ‘Use Net Core’ so I believe it should be right.

I am still somewhat confused on the phone then. If I switch to UNITY_WP8 then in the example above ‘var’ throws an error and thread.wait throws an error. I was hoping that using WINDOWS_PHONE would be similar to NETFX_CORE in that the Editor would ignore it during playback but the code would remain when you hit build and thus Visual Studio would pick it up when you compiled for the device/store.

Is there a phone equivalent to NETFX_CORE? In which we can set certain areas of our code to only compile and run via Visual Studio?

Because when compiling Unity scripts Microsoft compiler is never used (Mono compiler is), for Unity scripts WINDOWS_PHONE is never defined, so the answer would be no - at least for Unity scripts.

You can easily workaround this, by making static delegates in Unity scripts, and set them from your Windows Phone Visual Studio solution, in VS solution WINDOWS_PHONE will be defined, and you’ll be able to use Windows Phone specific API’s, bonus points - it will be much easier to test Windows Phone specific code, because when changing something, it will be simply enough to recompile VS solution.