How to build content catalog from code

Hello!

In my previous theme i asked about how to use addressable assets in bundle mode only. The solve of solution was content catalog that builded with bundles and loaded to Addressables in runtime.

Returning to the previous topic, we have to many files (content format specific) so we had to divide the assets into chunks. Chunk mount to project through simlink and we can set addresses for assets. Then Addressables build bundles for all chunk entries and paste content catalog near.

We almost got it set up Addressables for our custom situation and we have, i think, the last problem. Count of chunks about 200 - 300. Its mean client must do 200 - 300 requests, in WebGL its will webrequest.

Sounds crazy. To avoid this, obvious solution a came to mind - collect all catalogs into bundle or archive or custom format and then client will be able to load all catalogs through 1 request. Sounds crazy [2], but better anyway.

But what if we are build content catalog manually? (or ResourceLocator, or … internal impl is too hard to understand) We are know all addresses that want to build, and also know remote bundle path for all interesting platforms.

So, can i type something like this

public struct AssetEntry
{
    public string Address;
    public string AssetPath;
    public string BundlePath;
}

private Catalog BuildAssetsCatalog(IList<AssetEntry> entries)
{
    var catalog = new Catalog();
 
    foreach(var entry in entries)
    {
        catalog.Add(entry.Address, entry.BundlePath);
    }

    return catalog;
}

private void BuildTest()
{
    var entry_1 = new AssetEntry
    {
        Address = "Address_1",
        AssetPath = "Assets/Chunk/Inventory/Icon_1/root.prefab",
        BundlePath = "https://SERVER_NAME/PLATFORM/bundle_1.bundle"
    };

    var entry_2 = new AssetEntry
    {
        Address = "Address_2",
        AssetPath = "Assets/Chunk/Teleports/Teleport/root.prefab",
        BundlePath = "https://SERVER_NAME/PLATFORM/bundle_2.bundle"
    }

    var entries = new List<AssetEntry> { entry_1, entry_2 };
    var catalog = BuildAssetsCatalog(entries);
    DumpCatalog(catalog);
}

private void DumpCatalog(Catalog catalog) { ... }

and then load stored catalog data into Addressables, like this

async Task Initialize()
{
    var catalog = await LoadCatalog();
    Addressables.AddCatalog(catalog);
}

private async Task<?> LoadCatalog()
{
    var request = ...;
    await request.SendRequest();
    ...
    return request.Data;
}

And then use Addressables in default mode

 async void Start()
{
    var prefab = Addressables.LoadAssetAsync<GameObject>("Address_1");
    var inst = Instantiate(prefab);
    var comp = inst.GetComponent<...>();
    ....
}

It need only for chunks, other assets used in standard mode. If solution is exists, it can reduce our headache. =)

Best regards!

P.S. in single moment only one chunk can be mounted to project. If mount all chunks, Unity will be too long scan and importing or maybe crushed (not responding). So, method to mount all chunks and build content catalog for it all not works for us, unfortunately.