Unity_Addressable_概述
Addressables provides a system that can grow with your project. You can start with a simple setup and then reorganize as your project grows in complexity and your team grows in size, and you can do this all with minimal code changes.
译:Addressables提供了一个可以随项目一起成长的系统。您可以从一个简单的设置开始,然后随着项目的复杂性和团队规模的增长而重新组织,并且您可以通过最小的代码更改来完成这一切。
For example, you could start with a single group of Addressable assets, which Unity loads as a set. Then, as you add more content, you could split your assets into multiple groups so that you can load only the ones you need at a given time. As your team grows in size, you could make separate Unity Projects for developing different types of assets. These auxiliary Projects can produce their own Addressables content builds that you load from the main Project (again with minimal code changes).
译:例如,你可以从一组可寻址资产开始,Unity将其作为一个集合加载。然后,当您添加更多内容时,您可以将资产分成多个组,以便在给定时间只加载您需要的内容。随着团队规模的扩大,你可以创建独立的Unity项目来开发不同类型的资产。这些辅助项目可以生成自己的Addressables内容构建,您可以从主项目加载这些内容(同样需要进行最小的代码更改)。
This overview discusses the following concepts to help you understand how to manage and use your assets with the Addressables system:
译:本概述讨论以下概念,以帮助您了解如何管理和使用Addressables系统的资产:
Asset address: a string ID that identifies an Addressable asset. You can use an address as a key to load the asset.译:Asset address:标识可寻址资产的字符串ID。您可以使用地址作为键来加载资产
AssetReferences: a type you can use to support the assignment of Addressable assets to fields in an Inspector window. You can use an AssetReference instance as a key to load the asset. The AssetReference class also provides its own loading methods.译:AssetReferences:一种可以用来支持将可寻址资产分配到检查器窗口中的字段的类型。您可以使用一个AssetReference实例作为加载资产的键。AssetReference类还提供了自己的加载方法。
Label: a tag that you can assign to multiple assets and use to load related assets together as a group. You can use a label as a key to load the asset.译:Label:一个可以分配给多个资产并用于将相关资产作为一个组加载在一起的标记。您可以使用标签作为键来加载资产
Asset location: a runtime object that describes how to load an asset and its dependencies. You can use a location object as a key to load the asset.译:Asset location:描述如何加载资产及其依赖项的运行时对象。您可以使用本地对象作为加载资产的键
Key: an object that identifies one ore more Addressables. Keys include addresses, labels, AssetReference instances and location objects.译:Key:标识一个或多个Addressables的对象。键包括地址、标签、AssetReference实例和本地对象
Asset loading and unloading: the Addressables API provides its own functions to load and release Assets at runtime.译:Asset loading and unloading:Addressables API提供了它自己的函数来在运行时加载和释放资产
Dependencies: An asset dependency is one asset used by another, such as a Prefab used in a Scene asset or a Material used in a Prefab asset.译:Dependencies:资产依赖是一个资产被另一个资产使用,例如场景资产中使用的Prefab或Prefab资产中使用的Material
Dependency and resource management: the Addressables system uses reference counting to track which assets and AssetBundles are in use, including whether the system should load or unload dependencies (other referenced Assets).译:Dependency and resource management:Addressables系统使用引用计数来跟踪哪些资产和AssetBundles正在使用,包括系统是否应该加载或卸载依赖项(其他引用的资产)。
Group: you assign assets to groups in the Editor. The group settings determine how Addressables packages the group assets into AssetBundles and how it loads them at runtime.译:Group:在编辑器中将资产分配给组。组设置决定Addressables如何将组资产打包到AssetBundles中,以及如何在运行时加载它们。
Content catalogs: Addressables uses catalogs to map your assets to the resources that contain them.译:Content catalogs:Addressables使用目录将您的资产映射到包含它们的资源。
Content builds: when using Addressables, you make a content build to collate and package your assets as a separate step before you make a player build.译:Content builds:当使用Addressables时,在制作内容构建之前,你需要制作一个内容构建来整理和打包你的资产
Multiple platform support: the build system separates content built by platform and resolves the correct path at runtime.译:Multiple platform support:多平台支持,构建系统将根据平台构建的内容分离,并在运行时解析正确的路径。
Addressables tools: the Addressables package contains several windows and tools to organize, build, and optimize your content.译:Addressables tools::Addressables包包含几个窗口和工具来组织、构建和优化您的内容
By default, Addressables uses AssetBundles to package your assets. You can also implement your own IResourceProvider class to support other ways to access assets.
译:默认情况下,Addressables使用AssetBundles来打包您的资产。您还可以实现自己的IResourceProvider类,以支持以其他方式访问资产。
Asset addresses
A key feature of the Addressables system is that you assign addresses to your assets and use those addresses to load them at runtime. The Addressables resource manager looks up the address in the content catalog to find out where the asset is stored. (Assets can be built-in to your application, cached locally, or hosted remotely.) The resource manager loads the asset and any dependencies, downloading the content first, if necessary.
译:Addressables系统的一个关键特性是为资产分配地址,并在运行时使用这些地址来加载它们。Addressables资源管理器在内容目录中查找地址,以找出资产存储在何处。(资产可以内置到应用程序中,也可以在本地缓存,或者远程托管。)资源管理器加载资产和任何依赖项,如果需要,首先下载内容。

Addressables loads Assets by address no matter where they're located
译:Addressables通过地址加载资产,无论它们位于何处
Because an address isn't tied to the physical location of the Asset, you have much more flexibility when managing and optimizing your Assets, both in the Unity Editor and at runtime. Catalogs map Addresses to physical locations.
译:因为地址并不绑定到资产的物理位置,所以你在管理和优化资产时拥有更大的灵活性,无论是在Unity Editor中还是在运行时。目录将地址映射到物理位置。
Although, you should typically assign unique addresses to your assets, an asset address is not required to be unique. You can assign the same address string to more than one asset when useful. For example, if you have variants of an asset, you could assign the same address to all the variants and use labels to distinguish between the variants:
译:尽管您通常应该为您的资产分配唯一的地址,但资产地址不需要是唯一的。如果有用,可以将相同的地址字符串分配给多个资产。例如,如果你有一个资产的变体,你可以给所有的变体分配相同的地址,并使用标签来区分这些变体:
Asset 1: address: "plate_armor_rusty", label: "hd"
Asset 2: address: "plate_armor_rusty", label: "sd"
Addressables API functions that only load a single asset, such as LoadAssetAsync, load the first instance found if you call them with an address assigned to multiple assets. Other functions, like LoadAssetsAsync, load multiple assets in one operation and load all the assets with the specified address.
译:只加载单个资产的可寻址API函数,如LoadAssetAsync,如果您使用分配给多个资产的地址调用它们,则加载找到的第一个实例。其他函数,如LoadAssetsAsync,在一个操作中加载多个资产,并使用指定的地址加载所有资产。
TIP
You can use the MergeMode parameter of LoadAssetsAsync to load the intersection of two keys.
译:您可以使用LoadAssetsAsync的MergeMode参数来加载两个键的交集。
In the example above, you could specify the address, "plate_armor_rusty", and the label, "hd", as keys and intersection as the merge mode to load "Asset 1". You could change the label value to "sd" to load "Asset 2".
译:在上面的例子中,你可以指定地址“plate_armor_rusty”和标签“hd”作为键,交集作为合并模式来加载“Asset 1”。您可以将标签值更改为“sd”以加载“Asset 2”。
See Making an asset Addressable for how to assign addresses to assets.
译:有关如何为资产分配地址,请参见使资产可寻址。
See Loading assets for how to load assets by keys, including addresses.
译:有关如何按键(包括地址)加载资产,请参见加载资产。
AssetReference
An AssetReference is a type that you can set to any kind of Addressable asset. Unity does not automatically load the asset assigned to the reference, so you have more control over when to load and unload it.
译:AssetReference是一种可以设置为任何类型的可寻址资产的类型。Unity不会自动加载分配给引用的资产,所以你可以更好地控制何时加载和卸载它。
Use fields of type AssetReference in your MonoBehaviours and ScriptableObjects to help you specify which Addressable asset to use for that field (instead of using the string that specifies the address). AssetReferences support drag-and-drop and object picker assignment, which can make them more convenient to use in an Editor Inspector.
译:在monobehaviour和ScriptableObjects中使用AssetReference类型的字段来帮助您指定该字段使用哪个Addressable资产(而不是使用指定地址的字符串)。AssetReferences支持拖放和对象选择器赋值,这可以使它们在编辑器检查器中使用更方便。
In addition to the base AssetReference type, Addressables provides a few more specialized types, such as AssetReferenceGameObject and AssetReferenceTexture. You can use these specialized subclasses to eliminate the possiblity of assigning the wrong type of asset to an AssetReference field. In addition, you can use the AssetReferenceUILabelRestriction attribute to limit assignment to Assets with specific labels.
译:除了基本的AssetReference类型之外,Addressables还提供了一些更专门化的类型,比如AssetReferenceGameObject和AssetReferenceTexture。您可以使用这些专门化的子类来消除将错误类型的资产分配给AssetReference字段的可能性。此外,您可以使用AssetReferenceUILabelRestriction属性来限制具有特定标签的资产的分配。
See Using AssetReferences for more information.
译:有关更多信息,请参见使用资产引用。
Loading and releasing assets
To load an Addressable asset, you can use its address or other key such as a label or AssetReference. See Loading Addressable Assets for more information. You only need to load the main asset; Addressables loads any dependent assets automatically.
译:要加载可寻址资产,您可以使用它的地址或其他键,如标签或资产引用。有关更多信息,请参见加载可寻址资产。你只需要加载主资产;Addressables自动加载任何依赖的资产。
When your application no longer needs access to an Addressable asset at runtime, you must release it so that Addressables can free the associated memory. The Addressables system keeps a reference count of loaded assets. It doesn't unload an asset until the reference count returns to zero. Thus, you don't need to keep track of whether an asset or its dependencies are still in use; you only need to make sure that anytime you explicitly load an asset, you release it when your application no longer needs that instance. See Releasing Addressable assets for more information.
译:当应用程序在运行时不再需要访问Addressable资产时,必须释放它,以便Addressables可以释放相关的内存。Addressables系统保持已加载资产的引用计数。直到引用计数返回零,它才卸载资产。因此,您不需要跟踪资产或其依赖项是否仍在使用;您只需要确保在任何时候显式加载资产时,当应用程序不再需要该实例时释放它。有关更多信息,请参见释放可寻址资产。
Dependency and resource management
One asset in Unity can depend on another. A Scene might reference one or more Prefabs; a Prefab might use one or more Materials. The same Material can be used by more than one Prefab and those Prefabs can exist in different AssetBundles. When you load an Addressable asset, the system automatically finds and loads any dependent assets that it references. When the system unloads an asset, it also unloads its dependencies -- unless they're still being used by a different asset.
译:Unity中的一个资产可以依赖于另一个资产。一个场景可以引用一个或多个预制件;预制构件可以使用一种或多种材料。相同的材质可以被多个预制件使用,并且这些预制件可以存在于不同的资产包中。当你加载一个Addressable资产时,系统会自动找到并加载它引用的任何依赖资产。当系统卸载一个资产时,它也卸载了它的依赖项——除非它们仍然被不同的资产使用。
As you load and release assets, the Addressables system keeps a reference count for each item. When an asset is no longer referenced, Addressables unloads it. If the asset was in a bundle that no longer contains any assets that are in use, Addressables also unloads the bundle.
译:当你加载和释放资产时,Addressables系统会为每个项目保留一个引用计数。当一个资产不再被引用时,Addressables会卸载它。如果资产在一个不再包含任何正在使用的资产的包中,Addressables也会卸载这个包。
See Memory management for more information.
译:有关更多信息,请参阅内存管理。
Addressables groups and labels
Use Addressables groups to organize your content. All Addressable Assets belong to a group. If you don't explicitly assign an asset to a group, Addressables adds it to the default group.
译:使用Addressables组来组织您的内容。所有可寻址资产属于一个组。如果没有显式地将资产分配给组,Addressables会将其添加到默认组。
You can set the group settings to specify how the Addressables build system should package the assets in a group into bundles. For example, you can choose whether or not all the assets in a group should be packed together in a single AssetBundle file.
译:您可以设置组设置,以指定Addressables构建系统应该如何将组中的资产打包到包中。例如,您可以选择是否将组中的所有资产打包到单个AssetBundle文件中。
Use labels to tag content that you want to treat together in some way. For example, if you had labels defined for "red", "hat", and "feather", you could load all red hats with feathers in a single operation, whether or not they are part of the same AssetBundle. In addition, you can use labels to determine how assets in a group are packed into bundles.
译:使用标签来标记您希望以某种方式一起处理的内容。例如,如果您定义了“red”、“hat”和“feather”标签,那么您可以在一个操作中加载所有带有羽毛的红帽子,无论它们是否是同一个AssetBundle的一部分。此外,您可以使用标签来确定如何将组中的资产打包到包中。
Add an asset to a group and move assets between groups using the Addressables Groups window. You can also assign labels to your assets in the Groups window.
译:向组中添加资产,并使用“可寻址组”窗口在组之间移动资产。您还可以在“组”窗口中为资产分配标签。
Group schemas
The schemas assigned to a group define the settings used to build the assets in a group. Different schemas can define different groups of settings. For example, one standard schema defines the settings for how to pack and compress your assets into AssetBundles (among other options). Another standard schema defines which of the categories, "Can Change Post Release" and "Cannot Change Post Release" the assets in the group belong to.
译:分配给组的模式定义用于在组中构建资产的设置。不同的模式可以定义不同的设置组。例如,一个标准模式定义了如何将资产打包并压缩到AssetBundles(以及其他选项)的设置。另一个标准模式定义了组中的资产属于哪些类别,“可以更改发布”和“不能更改发布”。
You can define your own schemas to use with custom build scripts.
译:您可以定义自己的模式,以便与自定义构建脚本一起使用。
See Schemas for more information about group schemas.
译:有关组模式的更多信息,请参见模式。
Content catalogs
The Addressables system produces a content catalog file that maps the addresses of your assets to their physical locations. It can also create a hash file containing the hash (a mathematical fingerprint) of the catalog. If you are hosting your Addressable assets remotely, the system uses this hash file to determine if the content catalog has changed and needs to be downloaded. See Content catalogs for more information.
译:Addressables系统生成一个内容目录文件,该文件将资产的地址映射到其物理位置。它还可以创建一个包含目录的哈希(数学指纹)的哈希文件。如果您远程托管可寻址资产,系统将使用此哈希文件来确定内容目录是否已更改并需要下载。有关更多信息,请参阅内容目录。
The Profile selected when you perform a content build determines how the addresses in the content catalog map to resource loading paths. See Profiles for more information.
译:执行内容构建时选择的概要文件决定内容目录中的地址如何映射到资源加载路径。有关更多信息,请参阅概要文件。
See Distributing content remotely for information about hosting content remotely.
译:有关远程托管内容的信息,请参阅远程分发内容。
Content builds
The Addressables system separates the building of Addressable content from the build of your player. A content build produces the content catalog, catalog hash, and the AssetBundles containing your assets.
译:可寻址系统将可寻址内容的构建与玩家的构建分离开来。内容构建生成内容目录、目录散列和包含您的资产的AssetBundles。
Because asset formats are platform-specific, you must make a content build for each platform before building a player.
译:因为资产格式是特定于平台的,所以在构建播放器之前,你必须为每个平台制作内容。
See Building Addressable content for more information.
译:有关更多信息,请参见构建可寻址内容。
Play mode scripts
When you run your game or application in the Editor Play mode, it can be inconvenient and slow to always perform a content build before pressing the Play button. At the same time, you do want to be able to run your game in a state as close to a built player as possible. For flexibility, Addressables provides three options that determine how the Addressables system locates and loads assets in Play mode:
译:当你在编辑器播放模式下运行游戏或应用时,总是在按下播放按钮之前执行内容构建可能会很不方便且缓慢。与此同时,你也希望游戏能够以一种尽可能接近玩家的状态运行。为了灵活性,Addressables提供了三个选项来确定Addressables系统在播放模式下如何定位和加载资产:
Use the Asset database: Addressables loads Assets directly from the Asset database. This option typically provides the fastest iteration speed if you are making both code and Asset changes, but also least resembles a production build.译:Use the Asset database:Addressables直接从资产数据库加载资产。如果您同时更改代码和资产,这个选项通常提供最快的迭代速度,但也最不像产品构建。
Simulate groups: Addressables loads Assets while simulating groups. This option is helpful if you are working on organizing and optimizing your Addressables groups themselves. It provides Addressables events without requiring a full content rebuild after every change.译:Simulate groups:Addressables在模拟组时加载资产。如果您正在组织和优化Addressables组本身,此选项是有用的。它提供Addressables事件,而不需要在每次更改后重新构建完整的内容。
Use existing build: Addressables loads content from your last content build. This option most resembles a production build and can provide fast iteration turnaround if you aren't changing Assets.译:Use existing build:Addressables从您的上一个内容构建加载内容。此选项最类似于产品构建,如果您不更改资产,则可以提供快速迭代周转
See Play mode Scripts for more information.
译:有关更多信息,请参阅播放模式脚本。
Support for multiple platforms
Addressables supports projects designed for multiple platforms by including the target platform name in the build path and by making sure that it copies the correct platform files to the StreamingAssets folder when you make a player build.
译:Addressables支持针对多个平台设计的项目,方法是在构建路径中包含目标平台名称,并确保在构建时将正确的平台文件复制到StreamingAssets文件夹中。
Addressables tools
The Addressables system provides a few tools and windows to help you manage your Addressable assets:
译:Addressables系统提供了一些工具和窗口来帮助您管理您的Addressable资产:
Addressable Groups window: The Groups window is the main interface for managing assets, group settings, and making builds..译:Groups窗口是管理资产、组设置和构建的主要界面
Profiles window: helps set up paths used by your builds.译:帮助设置构建使用的路径
Addressables Event Viewer: monitor and profile runtime events related to your Addressable assets.译:监视和配置与可寻址资产相关的运行时事件
Analyze tool: the Analyze tool runs analysis rules that check whether your Addressables content conforms to the set of rules you have defined. The Addressables system provides some basic rules, such as checking for duplicate assets; you can add your own rules using the AnalyzeRule class.译:Analyze工具运行分析规则,检查Addressables内容是否符合您定义的规则集。Addressables系统提供了一些基本规则,如检查重复资产;您可以使用AnalyzeRule类添加自己的规则
Hosting tool: the Hosting tool provides a simple asset hosting service that runs from the Unity Editor to aide development and testing of your project.译:虚拟主机工具提供了一个简单的资产托管服务,从Unity编辑器运行,以帮助开发和测试你的项目。
Build layout report: describes the AssetBundles produced by a content build.译:描述由内容构建生成的资产包