Search Unity

How to properly work with plateform dependend code in editor

Discussion in 'Editor & General Support' started by Ms_42, Jan 23, 2020.

  1. Ms_42

    Ms_42

    Joined:
    Aug 13, 2019
    Posts:
    3
    Hi guys !

    Actually I'm trying to build some udp socket for hololens, however to get them to work I need to use the Windows.Networking dependency which does not work under editor.
    I can build and run them for hololens however it's a hassle to debug since I have to wait 10 min to build so I can debug my code.

    Don't you guys have a workaround for an healthier development workflow ?

    To anyone taking the time to read this , Thanks !
     
  2. fffMalzbier

    fffMalzbier

    Joined:
    Jun 14, 2011
    Posts:
    3,276
    You could use platform dependent compilation to run only supported code in the editor.

    Code (CSharp):
    1. #if UNITY_EDITOR
    2. //unity editor workarround code
    3. #elif  UNITY_WSA
    4. //Hololense code / wsa
    5. #endif
     
  3. Ms_42

    Ms_42

    Joined:
    Aug 13, 2019
    Posts:
    3
    Thanks for the reply ,
    The library Windows.Networking is not part of the WSA plateform , but a deeper subset (NETFX_CORE). If you try to import this lib even when Unity is in UWP plateform it'll cause an error. You can only build it and launch it inside the headset.
     
  4. Ms_42

    Ms_42

    Joined:
    Aug 13, 2019
    Posts:
    3
    Additionally I found this inside the documentation :

    UNITY_WSA #define directive for Universal Windows Platform
    . Additionally, NETFX_CORE is defined when compiling C# files against .NET Core and using .NET scripting backend