Search Unity

DownloadDependencies and GetDownloadSize for single group

Discussion in 'Addressables' started by androshchuk-vladyslav, Sep 13, 2019.

  1. androshchuk-vladyslav

    androshchuk-vladyslav

    Joined:
    Dec 13, 2015
    Posts:
    127
    As I see, group name is not a key. How I could preload all group without adding a tag with group name to all members?

    Will be nice to have possibility to preload all keys starting with some string.
     
    Last edited: Sep 13, 2019
    David_GameDev likes this.
  2. Favo-Yang

    Favo-Yang

    Joined:
    Apr 4, 2011
    Posts:
    464
  3. Dolzen

    Dolzen

    Joined:
    Mar 26, 2014
    Posts:
    90
  4. HugoClip

    HugoClip

    Joined:
    Feb 28, 2018
    Posts:
    52
    Not the most ideal code, but something like this could work to download a group asset bundle.
    I didn't test it.

    Code (CSharp):
    1. public AsyncOperationHandle DownloadGroupAssetBundleAsync(string groupName)
    2. {
    3.     if (!InitializationOperation.IsDone)
    4.         return ResourceManager.CreateChainOperation<IList<IAssetBundleResource>>(InitializationOperation, op => DownloadGroupAssetBundleAsync(groupName).Convert<IList<IAssetBundleResource>>());
    5.  
    6.     ResourceLocationMap map = m_ResourceLocators.First(locator => locator is ResourceLocationMap) as ResourceLocationMap;
    7.  
    8.     Dictionary<object, IList<IResourceLocation>> allLocations = map.Locations;
    9.  
    10.     IEnumerable<IResourceLocation> assetBundlesLocs = allLocations.Values.SelectMany(locations => locations).Where(loc => loc.PrimaryKey.StartsWith(groupName) && loc.ProviderId == typeof(AssetBundleProvider).FullName);
    11.     if (!assetBundlesLocs.Any())
    12.         return ResourceManager.CreateCompletedOperation<IList<IAssetBundleResource>>(null, new InvalidKeyException(groupName).Message);
    13.  
    14.     return LoadAssetsAsync<IAssetBundleResource>(assetBundlesLocs, null);
    15. }
    Probably won't work if you chose Bundle Naming "Only Hash"
     
    Last edited: Sep 16, 2019
  5. androshchuk-vladyslav

    androshchuk-vladyslav

    Joined:
    Dec 13, 2015
    Posts:
    127
    Yes, this is like I wanted to implement feature if no native logic will be provided. But little bit a lot of coupling to asset bundles.

    However that is important functionality and should be in core of Addressables, moreover that is simple to implement:

    During catalog composition, add one more catalog entry with key = "group name" and dependencies = "all group entries / bundles".