distinguish between Editor versions. Minimum required version

Hi all

I have an asset on the asset store for which I added in-editor tooltips, which is a feature of Unity 4.5. In the script, I handle this by having a section that goes:

#if UNITY_4_5
//some code with tooltips
#endif

#if UNITY_4_3
//some other code
#endif

How can I write this instead, so I don’t have to update this bit every time a new version of unity comes out? I’m looking for a way to say “if editor version is older than 4.5, do x, else do y”

I can see there’s an “#else” command, but I don’t know how to properly close the region it opens… :frowning:

Any advice is much appreciated, thanks!

looks like you can compare if version is newer than x, using: UNITY_X_Y_OR_NEWER

Unity - Manual: Conditional compilation in Unity

Starting from Unity 5.3.4, you can
compile code selectively based on the
earliest version of Unity required to
compile or execute a given portion of
code. Given the same version format as
above (X.Y.Z), Unity exposes one
global #define in the format
UNITY_X_Y_OR_NEWER, that can be used
for this purpose.

Your problem, I think, is that you are using #endif after each if. I’m pretty sure you are supposed to not use it until after the entire ifelse chain.

#if UNITY_4_3 || UNITY_4_4
//do pre-4.5 code
 
#else
//code for all versions 4.5 and later
#endif

If you check for the compatible you will always have to keep adding updates as the version goes up. The following code will break as soon as 5.1 comes out. You could try guessing the next series of numbers, the compiler allows you to write in defines that do not exist.

#if UNITY_4_3 || UNITY_4_4 || UNITY_4_5 || UNITY_4_6 || UNITY_5_0
    // Do new stuff
#else
    // Do old stuff
#endif

If you check for the old versions you will have a much longer line of code, but it will not need updating as new versions come out.

#if UNITY_2_6 || UNITY_2_6_1 ... UNITY_4_2
    // Do old stuff
#else
    //Do new stuff    
#endif

As of yet there is no < equivalency for defines.