Unity_Addressable_Profile Variables(配置文件变量)
Profile variables are generic key/value combinations that you can use to quickly alter Addressables configurations for different development situations.
译:Profile变量是通用的键/值组合,可用于快速更改Addressables配置以适应不同的开发情况。
There are two types of Profile Variables - standard, and path pairs. Standard variables are standalone key/value pairs. Path pairs use a special naming convention to connect sets of variables together.
译:Profile变量有两种类型:标准变量和路径对。标准变量是独立的键/值对。路径对使用特殊的命名约定将一组变量连接在一起。
Path pairs are typically used to switch between different build and load paths for different development situations. For example, you could use path pairs to modify the build and load paths for your Addressable content for various platforms.
译:路径对通常用于在不同的开发情况下切换不同的构建和加载路径。例如,您可以使用路径对来修改Addressable内容的构建和加载路径以适应各种平台。
Adding a new standard variable
You can add two kinds of variables to your profiles:
译:您可以将两种类型的变量添加到您的profiles中:
A basic variable, which defines a single value译:基本变量,定义单个值
A path pair, which defines a set of two path values. One value is for the build path and one is for the load path译:路径对,定义一组两个路径值。一个值用于构建路径,另一个值用于加载路径
You can use basic variables as components of your path values (for example, BuildTarget) and you can use them in your own build scripts. Use path pair variables to set the Build & Local Paths setting of your Addressables [Groups] and [remote catalog].
译:您可以使用基本变量作为您路径值的组件(例如BuildTarget),并将它们用于自己的构建脚本。使用路径对变量来设置Addressables [Groups]和[remote catalog]的Build&Local Paths设置。
To add a new Profile variable, select either Variable or Build Load Path Variable from the Create menu. Assign the new variable a name and value, then select Save. Addressables then adds the new variable to all profiles.
译:要添加新的Profile变量,请从Create菜单中选择Variable或Build Load Path Variable。为新变量分配名称和值,然后选择Save。然后,Addressables将新变量添加到所有profiles中。
Right-click (macOS: cmd + click) on the variable name to rename or delete the variable.
译:右键单击(macOS:cmd +单击)变量名称以重命名或删除变量。
Path Pairs
Path pairs define a matched set of BuildPath
and LoadPath
variables. When you create a path pair, you can use the pair name to assign the [path setting] of an Addressable [Group] or remote catalog as a unit.
译:路径对定义匹配的BuildPath和LoadPath变量集。创建路径对时,您可以使用对名称将Addressable [Group]或远程目录的[path setting]分配为一个单位。
To create a path pair, go to Create and select Build Load Path Variables. Assign the path pair a prefix name and assign path strings to the individual fields.
译:要创建路径对,请转到Create并选择Build Load Path Variables。为路径对分配一个前缀名称,并将路径字符串分配给各个字段。

The new path pair uses the Custom setting for the Bundle Location property with your initial values. You can change to a different Bundle Location if needed.
译:新的路径对使用Custom设置为Bundle Location属性与您的初始值。如果需要,可以更改为其他Bundle Location。
TIP
You can convert two regular variables for the build and load paths into a path pair by renaming them in the Profile window. Set one to VariableName.BuildPath
and the other to VariableName.LoadPath
.
译:您可以通过在Profile窗口中重命名它们将两个常规变量转换为构建和加载路径的路径对。将一个设为VariableName.BuildPath,将另一个设为VariableName.LoadPath。

Default path values
The default values for the build and load paths are:
译:构建和加载路径的默认值为:
Local build path:
[UnityEditor.EditorUserBuildSettings.activeBuildTarget]译:本地构建路径:[UnityEditor.EditorUserBuildSettings.activeBuildTarget]
Local load path:
[UnityEngine.AddressableAssets.Addressables.BuildPath]/[BuildTarget]译:本地加载路径:[UnityEngine.AddressableAssets.Addressables.BuildPath]/[BuildTarget]
Remote build path:
ServerData/[BuildTarget]译:远程构建路径:ServerData/[BuildTarget]
Remote load path:
http://localhost/[BuildTarget]译:远程加载路径:http://localhost/[BuildTarget]
In most cases, you should not change the local path values. The Unity build system expects the AssetBundles and other files to exist in the default location. If you change the local paths, you must copy the files from the build path to the load path before making your Player build. The load path must always be within the Unity StreamingAssets
folder.
译:在大多数情况下,您不应更改本地路径值。Unity构建系统期望AssetBundles和其他文件存在于默认位置。如果您更改了本地路径,则必须在创建Player构建之前将文件从构建路径复制到加载路径。加载路径必须始终在Unity StreamingAssets文件夹内。
If you distribute content remotely, you must modify the the remote load path to reflect the URL at which you host your remote content. You can set the remote build path to any convenient location; the build system does not rely on the default value.
译:如果您远程分发内容,则必须修改远程加载路径以反映您托管远程内容的URL。您可以将远程构建路径设置为任何方便的位置;构建系统不依赖于默认值。
Profile variable syntax
All Profile Variables are of type "string". You can assign them a fixed path or value. You can also use two syntax designations to derive all or part of a variable's value from static properties or other variables:
译:所有Profile变量都是“string”类型。您可以将它们分配为固定路径或值。您还可以使用两种语法指定从静态属性或其他变量派生变量值的全部或部分:
Brackets [ ]: Addressables evaluates entries surrounded by brackets at build time. The entries can be other profile variables (such as [BuildTarget]) or code variables (such as [UnityEditor.EditorUserBuildSettings.activeBuildTarget]). During a build, as it process your groups, Addressables evaluates the strings inside brackets and writes the result into the catalog.
译:方括号[ ]Addressables在构建时评估方括号包围的条目。条目可以是其他Profile变量(例如[BuildTarget])或代码变量(例如[UnityEditor.EditorUserBuildSettings.activeBuildTarget])。在构建过程中,Addressables评估方括号中的字符串并将结果写入目录。
Braces { }: Addressables evaluates entries surrounded by braces at runtime. You can use code variables of runtime classes (such as {UnityEngine.AddressableAssets.Addressables.RuntimePath}).译:花括号{ }:Addressables在运行时评估花括号包围的条目。您可以使用运行时类的代码变量(例如{UnityEngine.AddressableAssets.Addressables.RuntimePath})。
You can use static fields and properties inside either the brackets or braces. The names must be fully qualified and the types must be valid in context. For example, classes in the UnityEditor namespace can't be used at runtime. For more information about namespaces, see Microsoft's Namespaces documentation.
译:您可以在方括号或花括号中使用静态字段和属性。名称必须是完全限定的,类型必须在上下文中有效。例如,UnityEditor命名空间中的类不能在运行时使用。有关命名空间的更多信息,请参见Microsoft的命名空间文档。
The code variables used in the default Profile variable settings include:
译:默认Profile变量设置中使用的代码变量包括:
[UnityEditor.EditorUserBuildSettings.activeBuildTarget]译:
[UnityEngine.AddressableAssets.Addressables.BuildPath]译:
[UnityEngine.AddressableAssets.Addressables.RuntimePath]译:
For example: A load path of {MyNamespace.MyClass.MyURL}/content/[BuildTarget]
is set on a group that creates an AssetBundle called "trees.bundle". During the build, the catalog registers the load path for that bundle as {MyNamespace.MyClass.MyURL}/content/Android/trees.bundle
, evaluates [BuildTarget]
as "Android", and adds the AssetBundle name to the path. At runtime as the Addressables system processes the catalog it evaluates {MyNamespace.MyClass.MyURL}
to produce the final load path, http://example.com/content/Android/trees.bundle
.
译:例如:在创建名为“trees.bundle”的AssetBundle的组上设置了一个加载路径{MyNamespace.MyClass.MyURL}/content/[BuildTarget]。在构建过程中,目录将该Bundle的加载路径注册为{MyNamespace.MyClass.MyURL}/content/Android/trees.bundle,将[BuildTarget]评估为“Android”,并将AssetBundle名称添加到路径中。在运行时,当Addressables系统处理目录时,它评估{MyNamespace.MyClass.MyURL}以产生最终的加载路径http://example.com/content/Android/trees.bundle。
NOTE
Referencing a runtime variable in a Profile string doesn't prevent Unity from stripping that variable from your applications’ runtime libraries during the build optimization phase (if nothing else in your code references the same variable). See [Managed code stripping] for more information on how to prevent a class or member from being stripped.
译:注意:在Profile字符串中引用运行时变量不能防止Unity在构建优化阶段从您的应用程序运行时库中剥离该变量(如果您的代码中没有其他引用相同变量)。有关如何防止类或成员被剥离的更多信息,请参见[Managed code stripping]。