欢迎光临散文网 会员登陆 & 注册

Unity_Addressable_How Addressables Interact with other project a

2023-04-03 17:49 作者:unity_某某师_高锦锦  | 我要投稿

如何使用可寻址资产与其他项目资产交互?

When you include a scene in your Project Build Settings and build a player, Unity includes that scene and any assets used in the scene in your game or application's built-in data. Similarly, Unity includes any assets found in your project's Resources folders in a separate, built-in collection of assets. (The difference is that assets in a scene are only loaded as part of a scene, whereas assets in Resources can be loaded independently.)

译:当您将场景包含在项目构建设置中并构建播放器时,Unity会将该场景和在场景中使用的任何资产包含在您的游戏或应用程序的内置数据中。同样,Unity会将项目资源文件夹中发现的任何资产包含在一个单独的内置资产集合中。(不同之处在于场景中的资产仅作为场景的一部分加载,而资源中的资产可以独立加载。)

Addressable assets can either be built into your game or application as an additional set of "local" assets, or kept external to the game build as "remote" assets hosted on a server and downloaded when they are needed. You can update remote assets independently from the application itself (although remote assets cannot include code, so you can only change assets and serialized data).

译:可寻址资产可以作为一个额外的“本地”资产构建到您的游戏或应用程序中,或者作为外部资产保留到游戏构建中,并在需要时进行下载。您可以独立更新远程资产而不是应用程序本身(尽管远程资产不能包含代码,因此您只能更改资产和序列化数据。)

项目资产如何导出到播放器构建

However, if you use the same asset in more than one of these categories, then Unity makes copies of the asset when building rather than sharing a single instance. For example, if you used a Material in a built-in scene and also used it in a Prefab located in a Resources folder, you would end up with two copies of that Material in your build -- even if the Material asset itself is not located in Resources. If you then marked that same Material as Addressable, you would end up with three copies. (Files in the project StreamingAssets folder can never be referenced by assets outside that folder.)

译:然而,如果您在多个类别中使用相同的资产,则Unity在构建时制作该资产的副本而不是共享单个实例。例如,如果您在内置场景中使用材质,并在资源文件夹中的Prefab中也使用它,则在构建中会有两个该材质的副本,即使材质资产本身不在资源中。如果您然后将该材质标记为可寻址,则会有三个副本。(项目StreamingAssets文件夹中的文件永远不能被位于该文件夹外的资产引用。)

NOTE

Before building a player, you must make a content build of your Addressable assets. During the player build, Unity copies your local Addressables to the StreamingAssets folder so that they are included in the build along with any assets you placed in StreamingAssets. (These assets are removed at the end of the build process.) It is your responsibility to upload the remote Addressables files produced by the content build to your hosting service. See Builds for more information.

译:在构建播放器之前,您必须制作可寻址资产的内容构建。在播放器构建期间,Unity将本地可寻址资产复制到StreamingAssets文件夹中,以便与任何放置在StreamingAssets中的资产一起包含在构建中。(这些资产在构建过程结束时被删除。)您需要自己将由内容构建生成的远程可寻址文件上传到托管服务。有关更多信息,请查看构建。

When you use Addressables in a project, Unity recommends that you move your scenes and any data in Resources folders into Addressable groups and manage them as Addressables.

译:使用可寻址资产时,Unity建议将场景和任何在资源文件夹中的数据移动到可寻址组中,并将它们管理为可寻址资产。

The Build Settings scene list must contain at least one scene. You can create a minimal scene that initializes your application or game.

译:构建设置场景列表必须包含至少一个场景。您可以创建一个最小的场景,初始化您的应用程序或游戏。

A small amount of data in Resources folders typically doesn't cause performance issues. If you use 3rd party packages that place assets there, you don't need to move them unless they cause problems. (Addressable assets cannot be stored in Resources folders.)

译:在资源文件夹中的少量数据通常不会引起性能问题。如果您使用的第三方包将资产放在那里,除非它们引起问题,否则您不需要将它们移动。(可寻址资产不能存储在资源文件夹中。)

Referencing Subobjects

Unity partially determines what to include in a content build based on how your assets and scripts reference each other. Subobject references make the process more complicated.

译:Unity部分地根据您的资产和脚本引用彼此的方式来确定要包含在内容构建中的内容。子对象引用使这个过程变得更加复杂。

If an AssetReference points to a subobject of an Asset that is Addressable, Unity builds the entire object into the AssetBundle at build time. If the AssetReference points to an Addressable object (such as a GameObjectScriptableObject, or Scene) which directly references a subobject, Unity only builds the subobject into the AssetBundle as an implicit dependency.

译:如果AssetReference指向寻址资产的资产子对象,Unity会在构建时将整个对象构建到AssetBundle中。如果AssetReference指向直接引用子对象的寻址对象(如GameObject、ScriptableObject或Scene),Unity仅将子对象作为隐式依赖项构建到AssetBundle中。

Asset and AssetBundle dependencies

When you add an asset to an Addressables group, that asset is packed into an AssetBundle when you make a content build. In this case the asset is explicitly included in the bundle, or in other words it is an explicit asset.

译:当您将资产添加到Addressables组中时,当您进行内容构建时,该资产将打包到AssetBundle中。在这种情况下,资产明确包含在包中,或者换句话说,它是一个明确的资产。

If an asset references other assets, then the referenced assets are dependencies of the original asset. This is known as an asset dependency. If the asset is packed into Assetbundle A and the referenced assets are packed into AssetBundle B, then bundle B is a dependency of bundle A. This is known as an AssetBundle dependency. See the AssetBundle dependencies manual page for more information.

译:如果资产引用其他资产,则所引用的资产是原始资产的依赖项。这被称为资产依赖项。如果资产被打包到AssetBundle A中,而所引用的资产被打包到AssetBundle B中,则Bundle B是Bundle A的依赖项。这被称为AssetBundle依赖项。有关更多信息,请参见AssetBundle依赖项手册页面。

Asset dependencies are treated depending on whether or not they are also Addressable. Dependencies that are Addressable are packed into AssetBundles according to the settings of the group they are in -- this could be the same bundle as the referencing asset or a different bundle. A dependency that is not Addressable is included in the bundle of its referencing asset. The referenced asset is implicitly included in the bundle, or in other words it is an implicit asset.

译:资产依赖项根据它们是否也是Addressable而进行处理。Addressable的依赖项会根据它们所在组的设置打包到AssetBundle中 - 这可能是与引用资产相同的包或不同的包。不是Addressable的依赖关系将包含在其引用资产的包中。引用的资产隐式包含在包中,或者换句话说,它是一个隐式资产。

TIP

Use the Bundle Layout Preview Analyze rule to view explicit and implicit assets that will be included in AssetBundles based on the contents of Addressables groups. This is useful when previewing assets before making an content build. Use the Build Layout Report tool to display more detailed information about AssetBundles produced by a content build.

译:使用Bundle Layout Preview Analyze规则查看基于Addressables组内容包含在AssetBundles中的明确和隐式资产。在进行内容构建之前预览资产时,这非常有用。使用Build Layout Report工具显示有关内容构建生成的AssetBundles的更详细信息。

If more than one Addressable references the same implicit asset, then copies of the implicit asset are included in each bundle containing a referencing Addressable.

译:如果多个Addressable引用相同的隐式资产,则包含隐式资产的副本将包含在包含引用Addressable的每个包中。

非Addressable资产被复制到具有引用Addressable的每个包中

Non-Addressable assets are copied to each bundle with a referencing Addressable

A subtle consequence that can occur when an implicit asset is included in more than one bundle, is that multiple instances of that asset can be instantiated at runtime rather than the single instance your game logic expects. If you change the instance state at runtime, only the object from the same bundle can see the change since all the other assets now have their own individual instance rather than sharing the common one.

译:当隐式资产包含在多个包中时可能发生的微妙后果是,可以在运行时实例化该资产的多个实例,而不是您的游戏逻辑所期望的单个实例。如果您在运行时更改实例状态,则只有来自相同包的对象才能看到更改,因为所有其他资产现在都有自己的独立实例,而不是共享公共实例。

To eliminate this duplication, you can make the implicit asset an Addressable asset and include it in one of the existing bundles or add it to a different bundle. The bundle the asset is added to is loaded whenever you load one of the Addressables that reference it. If the Addressables are packed into a different AssetBundle than the referenced asset, then the bundle containing the referenced asset is an AssetBundle dependency.

译:为消除此重复,您可以将隐式资产设置为Addressable资产,并将其包含在现有包中或将其添加到不同的包中。添加资产的包会在加载其中之一的Addressable时加载。如果Addressables被打包到与所引用资产不同的AssetBundle中,则包含所引用资产的包是AssetBundle依赖项。

Be aware that the dependent bundle must be loaded when you load ANY asset in the current bundle, not just the asset containing the reference. Although none of the assets in this other AssetBundle are loaded, loading a bundle has its own runtime cost. See Memory implications of loading AssetBundle dependencies for more information.

译:请注意,当您加载当前包中的任何资产时,都必须加载依赖的包,而不仅仅是包含引用的资产。尽管不会加载此其他AssetBundle中的任何资产,但加载包具有自己的运行时成本。有关更多信息,请参见加载AssetBundle依赖项的内存影响。

TIP

Use the Check Duplicate Bundle Dependencies Analyze rule to identify and resolve unwanted asset duplication resulting from your project content organization.

译:使用Check Duplicate Bundle Dependencies Analyze规则来识别和解决由项目内容组织导致的不必要资产重复。



Unity_Addressable_How Addressables Interact with other project a的评论 (共 条)

分享到微博请遵守国家法律