Unity 2019.4, is there any way to define compile constraints like this?

What I want to do is following:

  • When an asset package A (NOT FROM Package Manager) (with assembly define file) exists, “PACKAGEXY_ENABLED” is defined in code and #IF PACKAGEXY_ENABLED will be enabled.
  • When this package A doesn’t exist or is disabled or not compiled due to platform limitation, then “PACKAGEXY_ENABLED” is not defined and #IF PACKAGEXY_ENABLED will be commented out.

Is there anyway to do this?

Yes, in the PlayerSettings inspector panel, see “Scripting Define Symbols” under the Other Settings tab.

You can obviously also get at those with build-time scripting to tweak them for custom build types.