Hi,
How can I condition a chank of code to run only if a specific package is installed without causing an error to jump for not finding it?
For instance, If I wanna create a generic script that applies some cosmetic features if Odin is imported, but if not it simply runs with the default visuality without errors.
Another aim I’d wish to do is:
Example2 (pseudo code)
If(renderhead.avPro is imported to the project)
{
public MediaPlayer mp;
}
else
{
public VideoPlayer vp;
}
If the dependency is a UPM package, then you should use version defines on assembly definitions. They allow you to set up conditional compilation scripting defines for your assembly definition based on wether specific versions of a package are installed. This is the most seamless for your users, with the integration just automatically becoming (in-)active when the package is (un-)installed.
If your dependency is a traditional Unity package (its assets are in the Assets folder), then it’s a lot harder to make it work smoothly. My preferred way is to have some UI that offers the user to install additional integrations. Then include those integrations as additional packages inside your main package and import them using AssetDatabase.ImportPackage.