0

I'm using Addressables to build assets. This process creates bunch of .bundle files (in UnityFS format).

I would like to create my own asset bundle format (e.g. IPFS's .car).

Is there any class that I can implement to override the default Unity's archive format which can be used for specific Addressables Group?

kenorb
  • 155,785
  • 88
  • 678
  • 743

1 Answers1

0

Addressables' scripts responsible for build process can be found in Packages/Addressables/Editor/Build/DataBuilders. Their references can be found in assets files at Assets/AddressableAssetsData/DataBuilders (settings created when setting up Addressables package for the first time).

A new asset can be created in DataBuilders/ via contextual menu: Create->Addressables->Content Builders->Default Build Script. This new asset has reference to build script (reference can be changed in Debug view in Inspector).

Overridden script (can be placed anywhere in Assets/) can look like:

using System.Collections.Generic;
using UnityEditor.AddressableAssets.Build.BuildPipelineTasks;
using UnityEditor.AddressableAssets.Settings;
using UnityEngine.Build.Pipeline; // For: BundleDetails.
using UnityEngine;

namespace UnityEditor.AddressableAssets.Build.DataBuilders
{
  using Debug = UnityEngine.Debug;
  public class BuildScriptCustomMode : BuildScriptPackedMode
  {

    /// <inheritdoc />
    public override string Name
    {
      get { return "Custom Build Script"; }
    }

    /// Creates a name for an asset bundle using the provided information.
    /// <inheritdoc />
    protected override string ConstructAssetBundleName(AddressableAssetGroup assetGroup, BundledAssetGroupSchema schema, BundleDetails info, string assetBundleName)
    {
      string bundleNameWithHashing = base.ConstructAssetBundleName(assetGroup, schema, info, assetBundleName);
      bundleNameWithHashing = bundleNameWithHashing.Replace(".bundle", ".custom.bundle");
      Debug.Log("bundleNameWithHashing: " + bundleNameWithHashing);
      return bundleNameWithHashing;
    }

    /// <inheritdoc />
    protected override TResult DoBuild<TResult>(AddressablesDataBuilderInput builderInput, AddressableAssetsBuildContext aaContext)
    {
      var genericResult = AddressableAssetBuildResult.CreateResult<TResult>();
      // genericResult = base.DoBuild<TResult>(builderInput, aaContext); // Original build script.
      // Override custom build here...
      // Location of current built files: aaContext.locations.
      return genericResult;
    }
  }
}

Other methods can be overridden as well when needed. Haven't tested the whole process yet, but that's the good start. The best is to look how BuildScriptPackedMode class script does that.

Read more: https://docs.unity3d.com/Packages/com.unity.addressables@1.21/manual/editor/building-content/BuildingContent.html.

kenorb
  • 155,785
  • 88
  • 678
  • 743