Unity_Addressable_Asset Hosting Services(资产托管服务)
Overview
Hosting Services is a development tool that provides an integrated facility for using Addressable Assets configuration data to serve packed content to local or network-connected application builds from within the Unity Editor. Hosting Services can improve iteration velocity when testing packed content and can also serve content to connected clients on local and remote networks.
译:Hosting Services是一种开发工具,提供了一个集成设施,可以使用Addressable Assets配置数据从Unity编辑器内部为本地或网络连接的应用程序构建提供打包内容。Hosting Services可以在测试打包内容时提高迭代速度,并且还可以向本地和远程网络上连接的客户端提供内容。
Packed mode testing and iteration(打包模式测试和迭代)
Moving from Editor Play mode testing to platform application build testing introduces complexities and time costs to the development process. Hosting Services provide extensible Editor-embedded content delivery services that map directly to your Addressables group configuration. Using a custom Addressables profile, you can configure your application to load all content from the Unity Editor itself. This includes builds deployed to mobile devices, or any other platform, that have network access to your development system.
译:从编辑器播放模式测试转移到平台应用程序构建测试引入了开发过程中的复杂性和时间成本。Hosting Services提供可扩展的嵌入式内容交付服务,直接映射到您的Addressables组配置,从而提高了迭代速度。使用自定义的Addressables配置文件,您可以配置应用程序从Unity编辑器本身加载所有内容。这包括部署到移动设备或任何其他平台的构建,这些平台可以访问您的开发系统。
Setup
This article details the initial setup of Asset Hosting Services for your project. While the setup guide focuses on Editor workflows, you can use the API to configure Hosting Services by setting the HostingServicesManager property of the AddressableAssetSettings class.
译:本文详细介绍了如何为项目设置Asset Hosting Services。虽然设置指南侧重于编辑器工作流程,但您也可以使用API通过设置AddressableAssetSettings类的HostingServicesManager属性来配置Hosting Services。
Configuring a new Hosting Service
Use the Hosting window to add, configure, and enable new Hosting Services. In the Editor, select Window > Asset Management > Addressables > Hosting, or click the Tools > Window > Hosting Services button from the Addressables Groups window menu to access the Addressables Hosting window.
译:使用Hosting窗口添加、配置和启用新的Hosting Services。在编辑器中,选择窗口>资产管理>Addressables>Hosting,或从Addressables组窗口菜单中单击工具>窗口>Hosting Services按钮以访问Addressables Hosting窗口。

To add a new Local Hosting Service, click the Create > Local Hosting button.
译:要添加新的本地Hosting Service,请单击Create > Local Hosting按钮。

Note: For more information on implementing custom hosting service types, see the section on custom services.
译:注意:有关实现自定义Hosting Service类型的更多信息,请参见自定义服务部分。
The newly added service appears in the Hosting Services section of the Addressables Hosting window. Use the Service Name field enter a name for the service.
译:新添加的服务将出现在Addressables Hosting窗口的Hosting Services部分。使用Service Name字段输入服务名称。
The new service defaults to the disabled state. To start the service, select the Enable check box.
译:新服务默认处于禁用状态。要启动服务,请选择Enable复选框。

The HTTP Hosting Service automatically assigns a port number when it starts. The service saves the port number and reuses it between Unity sessions. To choose a different port, either assign a specific port number in the Port field, or click the Reset button to assign a different, random port number.
译:HTTP Hosting Service在启动时会自动分配端口号。该服务保存端口号并在Unity会话之间重复使用。要选择不同的端口,请在端口字段中分配特定的端口号,或单击Reset按钮分配不同的随机端口号
In Editor versions 2022.1 and above, HTTP downloads are disallowed by default. In order for the default HTTPHostingService
to work correctly, you need to set the Allow downloads over HTTP setting in Edit > Project Settings... > Player > Other Settings > Allow downloads over HTTP to something other than Not allowed.
译:在2022.1及以上版本的编辑器中,默认情况下禁止使用HTTP下载。为了让默认的HTTPHostingService正常工作,您需要在Edit > Project Settings… > Player > Other Settings > Allow downloads over HTTP设置中设置允许HTTP下载
WARNING
If you reset the port number, you must execute a full application build to generate and embed the correct URL.
译:如果重置端口号,您必须执行完整的应用程序构建以生成和嵌入正确的URL
NOTE
You may need to disable your local firewall or add exceptions to allow connections from mobile or other devices.
译:您可能需要禁用本地防火墙或添加例外以允许来自移动设备或其他设备的连接
The HTTP Hosting Service is now enabled and ready to serve content from the directory specified in the remote BuildPath of each asset group.
译:HTTP Hosting Service现在已启用,并准备从每个资产组的远程BuildPath指定的目录中提供内容
Hosting Service profile setup
When working with Hosting Services during development, consider creating a profile that configures your asset groups to load from the Hosting Service. For more about profiles, see Addressable Assets Profiles.
译:在开发过程中使用Hosting Services时,考虑创建一个配置资产组从Hosting Service加载的配置文件。有关配置文件的更多信息,请参见Addressable Assets Profiles
Once in the Addressables Profiles window, create a new profile via Create > Profile. In the following example, the new profile is called "Editor Hosted".
译:一旦进入Addressables Profiles窗口,通过Create > Profile创建一个新的配置文件。在下面的示例中,新配置文件称为“Editor Hosted”
Modify the remote loading URL to load from the Hosting Service. From the Addressables Hosting window, you can use the fields named [PrivateIpAddress]
and [HostingServicePort]
in the remote LoadPath variable to construct the path URL (for example, http://[PrivateIpAddress]:[HostingServicePort]
).
译:修改远程加载URL以从Hosting Service加载。从Addressables Hosting窗口,您可以使用名为[PrivateIpAddress]和[HostingServicePort]的字段在远程LoadPath变量中构建路径URL(例如,http://[PrivateIpAddress]:[HostingServicePort])。

Verify that each group is configured correctly. Ensure that you set the BuildPath and LoadPath paths to their respective profile keys that you modified for use with Hosting Services. In this example, you can see how the profile variables in the LoadPath should be expanded to build a correct base URL for loading assets from Hosted Services.
译:确认每个组都正确配置。确保将BuildPath和LoadPath路径设置为用于Hosting Services的各自配置文件键。在此示例中,您可以看到LoadPath中的配置文件变量应扩展为构建从Hosted Services加载资产的正确基本URL

TIP
Use the Path Preview to verify that the profile variables resolve to the correct variables. The load path URL IP address and port must match those shown for the service on the Addressables Hosting window.
译:使用路径预览验证配置文件变量是否解析为正确的变量。加载路径URL的IP地址和端口必须与Addressables Hosting窗口中显示的服务相匹配
Finally, select the new profile from the Addressables Groups window, create a build, and deploy to the target device. The Unity Editor now serves all load requests from the application through the HttpHostingService service. You can now make additions and changes to content without redeployment. Rebuild the Addressable content, and relaunch the already deployed application to refresh the content.
译:最后,从Addressables Groups窗口中选择新配置文件,创建构建并将其部署到目标设备。Unity Editor现在通过HttpHostingService服务为应用程序服务所有加载请求。现在可以添加和更改内容而无需重新部署。重新构建Addressable内容,并重新启动已经部署的应用程序以刷新内容

Batch mode
You can also use Hosting Services to serve content from the Unity Editor running in batch mode. To do so, launch Unity from the command line with the following options:
译:您还可以使用Hosting Services从批处理模式下运行的Unity Editor中提供内容。为此,请使用以下选项从命令行启动Unity:
-batchMode -executeMethod UnityEditor.AddressableAssets.HostingServicesManager.BatchMode
This loads the Hosting Services configuration from the default AddressableAssetSettings object, and starts all configured services.
译:这将从默认的AddressableAssetSettings对象中加载Hosting Services配置,并启动所有配置的服务。
To use an alternative AddressableAssetSettings configuration, create your own static method entry point, to call through the HostingServicesManager.BatchMode(AddressableAssetSettings settings) overload.
译:要使用替代的AddressableAssetSettings配置,请创建自己的静态方法入口点,通过HostingServicesManager.BatchMode(AddressableAssetSettings settings)重载调用。
Custom services
You can create a custom service to implement your own logic for serving content-loading requests from the Addressable assets system. For example:
译:您可以创建自定义服务来实现自己的逻辑,以便从Addressable assets系统中提供内容加载请求。例如:
Support a custom IResourceProvider that uses a non-HTTP protocol for downloading content.译:支持使用非HTTP协议下载内容的自定义IResourceProvider。
Manage an external process for serving content that matches your production CDN solution (such as an Apache HTTP server).译:管理用于提供与生产CDN解决方案(如Apache HTTP服务器)匹配的内容的外部进程。
Implementing a custom service
The HostingServicesManager can manage any class that implements an IHostingService interface (for more details on method parameters and return values, see the API documentation.
译:HostingServicesManager可以管理任何实现IHostingService接口的类(有关方法参数和返回值的更多详细信息,请参阅API文档。
To create a new custom service:
译:要创建一个新的自定义服务:
Follow the steps outlined in the configuring a new Hosting Service section above, but instead of selecting Create > Local Hosting button, select Create > Custom Service button instead.译:按照上面配置新的Hosting Service部分中概述的步骤,但是不要选择Create > Local Hosting按钮,而是选择Create > Custom Service按钮
Drag the applicable script into its field, or select it from the object picker. The dialog validates that the selected script implements the IHostingService interface.译:将适用的脚本拖到其字段中,或者从对象选择器中选择它。对话框验证所选脚本实现IHostingService接口。
To finish adding the service, click the Add button.译:要完成添加服务,请单击Add按钮
Moving forward, your custom service will appear in the Service Type drop-down options.
译:在未来,您的自定义服务将显示在Service Type下拉选项中
