docs.unity.cn
  • Manual
  • Scripting API
  • Changelog
  • License

Addressables 1.21.14

    Show / Hide Table of Contents
    • Addressables package
    • Get started
      • Addressables overview
      • Install Addressables
      • Configure your project to use Addressables
      • Make an asset Addressable
      • Use an Addressable asset
      • Manage Addressable assets
      • Build Addressable assets
      • Remote content distribution
      • Incremental content updates
      • Addressables samples
    • Manage Addressables
      • Manage Addressables introduction
      • Organize Addressable assets
      • Groups overview
        • Groups introduction
        • Manage and create groups
        • Labels overview
        • Create a group template
        • Pack groups into Asset​Bundles
        • Addressables Groups window reference
        • Group settings and schemas overview
          • Content Packing & Loading schema reference
          • Content Update Restriction schema reference
      • Profiles overview
        • Profiles introduction
        • Create a profile
        • Profile variables overview
        • Set a build and load path
        • Addressables Profiles window reference
      • Asset references overview
        • Asset references introduction
        • Create an Asset​Reference
        • Load an Asset​Reference
      • Addressables Asset Settings reference
      • Addressables Preferences reference
    • Build content overview
      • Build content introduction
      • Build Addressables content with Player builds
      • Asset dependencies overview
      • Create a build
        • Create a full build
        • Create an update build
      • Build scripting
        • Start a build from a script
        • Custom build scripting
        • Build while recompiling
      • Build sprite atlases
      • Build shaders
      • Build artifacts
        • Artifacts in the player
        • Content catalogs
        • Shared Asset​Bundles
      • Content update builds
        • Content update builds overview
        • Build a content update
        • Check for content updates at runtime
        • Content update examples
        • Content update build settings
      • Use continuous integration to build Addressables
    • Distribute remote content
      • Distribute remote content overview
      • Enable remote content
      • Remote content profiles
      • Remote content Asset​Bundle caching
      • Pre-download remote content
      • Use Addressables with Cloud Content Delivery
      • Editor asset hosting services
    • Use Addressables at runtime
      • Addressables initialization
      • Memory management overview
        • Asset​Bundle memory overhead
      • Manage catalogs at runtime
      • Get addresses at runtime
      • Modification events
    • Load Addressable assets
      • Load Addressable assets introduction
      • Asynchronous loading
        • Asynchronous operation handles
        • Synchronous loading
      • Load assets
      • Load assets by location
      • Load a scene
      • Load Asset​Bundles
      • Unload Addressable assets
      • Change resource URLs
      • Preload dependencies
      • Load content from multiple projects
    • Diagnostic tools
      • Addressables Profiler module
      • Build layout report
      • Build profile log
      • Addressables Report window reference
        • Addressables Report Inspector reference
    • Manual
    • Build content overview
    • Build scripting
    • Custom build scripting

    Custom build scripting

    To configure a new custom script, add it to the Build and Play Mode Scripts list.

    Custom scripts extend the BuildScriptBase class or implement the IDataBuilder interface. There are several methods that you can override, such as ClearCachedData and CanBuildData<T>. If extending the BuildScriptBase class, the most notable method to override is BuildDataImplementation<TResult>. This is the method that's used to setup or build content.

    A custom script is either a Build Script or a Play Mode Script. This is determined by how the CanBuildData<T> method is implemented. Build scripts can only build data of the type AddressablesPlayerBuildResult, so the method is implemented in this way:

    
    public override bool CanBuildData<T>()
    {
        return typeof(T).IsAssignableFrom(typeof(AddressablesPlayerBuildResult));
    }
    
    

    This allows the script to be listed in the Build menu.

    Play Mode Scripts can only build data of the type AddressablesPlayModeBuildResult, so the method is implemented in this way:

    
    public override bool CanBuildData<T>()
    {
        return typeof(T).IsAssignableFrom(typeof(AddressablesPlayModeBuildResult));
    }
    
    

    This allows the script to be listed in the Play Mode Scripts menu.

    See the Custom Build and Play Mode Scripts Sample for an example.

    Extend the default build script

    If you want to use the same basic build as the default build script BuildScriptPackedMode, but want to treat specific groups or types of assets differently, you can extend and override the default build script. If the group or asset the build script is processing is one that you want to treat differently, you can run your own code. Otherwise, you can call the base class version of the function to use the default algorithm.

    Refer to the Addressable variants project for an example.

    Save the content state

    If you support remote content distribution and update your content between player releases, you must record the state of your Addressables groups at the time of the build. Recording the state lets you perform a differential build using the Update a Previous Build script.

    Refer to the implementation of BuildScriptPackedMode and ContentUpdateScript for details.


    对文档有任何疑问,请移步至开发者社区提问,我们将尽快为您解答
    In This Article
    • Extend the default build script
    • Save the content state
    Back to top Copyright © 2023 Unity Technologies — Terms of use
    Generated by DocFX
    on Monday, June 26, 2023