Detect textmesh pro package from script

I have a localization asset on the asset store and parts of the code that deal with textmeshpro will not compile if textmeshpro package is not included in a project.

Is there a way to automatically detect whether textmeshpro is included in the project?

I can think of script defines for this. If textmeshpro DID include a script define like #TEXTMESHPRO then I could put that around the contents of those files which depend on TMPro namespace. That way anyone could use the asset out of the box without having to either fix compile errors or manually uncomment code from an asset they just downloaded. The experience in both cases is less than ideal IMO.

Here’s an idea: you could perhaps write a little “installer” script accessible from the menu, and perhaps have it trigger once upon first arrival in a project, that uses reflection to try and find if TMPro is present, and if so it would put a TEXTMESHPRO into the script predefines.

In your case I would probably deconflict that namespace a bit more, just to avoid future misworkings, something like use HKILLER_TEXTMESHPRO instead.

I was hoping I could avoid that. Such a installer script would ideally go into Unity’s package manager and become an API everyone could use.

As far as I’m aware, the define ‘TMP_PRESENT’ has been included since Unity 2018 so that 3rd party publishers could detect it.

6209768--682265--upload_2020-8-16_12-49-41.png

6209768--682256--upload_2020-8-16_12-49-4.png

1 Like