Files
Cielonos/Packages/io.continis.subassets/Editor/Utilities/AddressableEntryMigrator.cs
SoulliesOfficial f26f9fd374 爆更
2026-03-20 12:07:44 -04:00

49 lines
2.0 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#if ADDRESSABLES_INSTALLED
using System.Collections.Generic;
using SubAssetsToolbox.Editor;
using UnityEditor.AddressableAssets;
using UnityEditor.AddressableAssets.Settings;
using UnityEngine;
namespace SubAssetsToolbox.Utilities
{
internal static class AddressableEntryMigrator
{
internal static void MigrateOrRemoveEntry(string oldGuid, string parentGuid, string parentName)
{
AddressableAssetSettings settings = AddressableAssetSettingsDefaultObject.Settings;
if (settings == null) return;
AddressableAssetEntry oldEntry = settings.FindAssetEntry(oldGuid);
if (oldEntry == null) return;
string oldName = oldEntry.MainAsset != null ? oldEntry.MainAsset.name : oldGuid;
string address = oldEntry.address;
AddressableAssetGroup group = oldEntry.parentGroup;
HashSet<string> labels = new(oldEntry.labels);
AddressableAssetEntry parentEntry = settings.FindAssetEntry(parentGuid);
if (parentEntry != null)
{
// New host asset was already an Addressable, so the new sub-asset
// is now addressable thanks to its parent and the old entry can be removed.
settings.RemoveAssetEntry(oldGuid);
Debug.Log(string.Format(Constants.AddressableEntryRemoved, oldName, address, parentName));
return;
}
// The new host asset wasn't an Addressable, so the new host needs to become one
settings.RemoveAssetEntry(oldGuid);
AddressableAssetEntry newEntry = settings.CreateOrMoveEntry(parentGuid, group, false, false);
newEntry.address = address;
foreach (string label in labels)
newEntry.SetLabel(label, true, true, false);
settings.SetDirty(AddressableAssetSettings.ModificationEvent.EntryMoved, newEntry, true);
Debug.Log(string.Format(Constants.AddressableEntryMigrated, oldName, address, parentName));
}
}
}
#endif