Hello,
I am developing a package which supports both non-addressables and addressables project. I wish for my users to easily add/remove support for addressables.
My package will require changing direct references (non-addressables project) to AssetReference (addressables project) and vice vera.
This party is easy, I can use asmdef version defines to change the types my package uses.
However, the process of doing this breaks the references. This will mean potentially thousands of scriptable objects need to be re-linked up. This is not a human friendly task, so I would like to automate it.
Ideally I would detect if the user has enabled the addressables package and re-fix up the broken references. I can do this, i’m just missing the “when” to call this code.
thanks in advance!
Hello,
You can use Events.registeredPackages, this event is called right after the editor is done compiling packages. It also includes the lists of added and removed packages.
1 Like
Hi David than you for getting back to me.
In the end I opted for PackageManagerExtensions.RegisterExtension(new RefactorUtility());
These callbacks happens before the compile, which is great for remove, as it means I can convert AssetReferences
to Direct References before the type AssetReferences
does not exist anymore (and hence the data)
For upgrading I had to wait using DidReloadScripts
callback. (LT_ADD is a define triggered by version defines in my asmdef)
public void OnPackageAddedOrUpdated(PackageInfo packageInfo)
{
if (packageInfo.assetPath == "Packages/com.unity.addressables")
{
Settings.GetOrCreateSettings().ShowNotification = true;
}
}
[UnityEditor.Callbacks.DidReloadScripts]
private static void OnScriptsReloaded() {
#if LT_ADD
if (Settings.GetOrCreateSettings().ShowNotification)
{
Settings.GetOrCreateSettings().ShowNotification = false;
ShowNotification();
}
#endif
}