智能交付功能和工作程序

本主题将介绍如何使用这些功能和工作程序来为你的游戏缩短用户的初始和后续安装时间。 功能和工作程序协同工作,以定义基础游戏中的内容组,用户可以在安装时添加和删除这些内容组,也可以在安装后从 shell 中对其进行添加和删除。 此外,还可使用运行时 API 动态查询功能的安装状态,并触发功能的添加和删除操作。

功能是一个 XML 元素,可指定面向开发人员的 ID 字符串属性。 它还指定面向用户的可本地化显示名称和图像,以在 Shell 中显示。 该功能指定一个或多个标记。 在进行安装和更新时,系统会查找和已安装功能引用的所有标记,并安装包含该标记的所有区块。

工作程序也是一个 XML 元素,指定应安装的功能的列表。 始终有一个默认工作程序,且总是安装此工作程序包含的功能。 可以定义其他工作程序。 如果用户或当前主机有权使用任何指定的 StoreIds,则会在安装时将其激活,如以下代码所示。

<Recipes>
    <!-- A recipe is always active if it has no child StoreId elements—the name "default" is a convention. -->
    <Recipe Id="default" IncludedFeatures="CampaignFeature;MultiPlayerFeature"/>

    <!-- This recipe is active by default, but only on Xbox Series X hardware.  -->
    <Recipe Id="default-anaconda" IncludedFeatures="HDFeature" Devices="Xbox-Anaconda"/>

    <!-- PremiumProduct recipe is active, which means PremiumFeature installs if user owns 9PXXXXXXXXXX. -->
    <Recipe Id="PremiumProduct" IncludedFeatures="PremiumFeature">
        <StoreId>9PXXXXXXXXXX</StoreId>
    </Recipe>
</Recipes>
<Features>
    <Feature Id="CampaignFeature" DisplayName="ms-resource:CampaignFeatureName" Image="campaignlogo.png" Tags="Campaign1;Campaign2"/>
    <Feature Id="MultiPlayerFeature" DisplayName="ms-resource:MultiPlayerFeatureName" Image="MPlogo.png" Tags="Multiplayer1;Multiplayer2" />
    <Feature Id="HDFeature" DisplayName="ms-resource:HDTexturesFeatureName" Image="HDlogo.png" Tags="hd"/>
    <Feature Id="PremiumFeature" DisplayName="ms-resource:PremiumFeatureName" Image="Premiumlogo.png" Tags="extras"/>
</Features>


<Chunk Id="8000" Tags="Campaign1">
<Chunk Id="8001" Tags="Campaign2">
<!-- This chunk uses the # character, so it's only installed if both the Campaign and HD features are active. -->
<Chunk Id="8001" Tags="Campaign1#hd"> 

<Chunk Id="9000" Tags="Multiplayer1">
<!-- This chunk uses the # character, so it's only installed if both the Multiplayer and HD features are active. -->
<Chunk Id="9001" Tags="Multiplayer1#hd"> 

<!-- This chunk is installed if either the Multiplayer or SinglePlayer features are active. -->
<Chunk Id="10000" Tags="Multiplayer1;Campaign1">
<!-- This chunk is installed if either the (Multiplayer feature and HD feature) or (SinglePlayer feature and HD feature) are active. -->
<Chunk Id="10001" Tags="Multiplayer1#hd;Campaign1#hd">

<Chunk Id="11000" Tags="extras">
<!-- This chunk uses the # character, so it's only installed if both the Premium and HD features are active. -->
<Chunk Id="11001" Tags="extras#hd"> 

注意

功能可以包含多个标记属性,以分号分隔。 如果区块中的任何标记包含在活动功能中,则安装将包含该区块。 如果 # 两边的标记处于活动状态,则 # 符号可用于安装标记。

本地化功能显示名称

DisplayNames 的本地化与 MicrosoftGame.config 文件中名称属性的本地化相同。 通过使用 ms-resource:name 格式、游戏字符串目录中的 .resw 文件以及正确命名的子目录中的按区域设置的字符串,可以完成此操作。 有关更多信息,请参阅 MicrosoftGame.config 本地化

注意

用于 MicrosoftGame.config 和智能交付的本地化字符串值和图像在发布的包中均未加密,无论是开发者沙盒版还是零售版中都是如此。 对你的游戏、图标和任何敏感内容使用占位符值。 敏感内容包括在开发过程中,在公开披露游戏前,智能交付引用的任何内容,或在游戏中发现的特定内容。

隐藏功能

功能标记为隐藏,以防止用户决定在安装时还是在安装游戏后管理 Shell 时将其显示为可选选项。 使用隐藏功能时请谨慎,因为添加或删除它们的唯一方法就是使用游戏中的 API。 在提供内容更新来修复这些 bug 之前,游戏中发现的任何 bug 可能会导致内容不可访问。 以下代码是标记为隐藏的功能示例。

  <Feature Id="HiddenFeature" Hidden="true" Tags="HiddenFeature1" />

检查功能安装状态

可使用功能检查是否存在具有该功能指定的标记的所有区块。 在执行这些运行时查询时,会考虑设备和语言说明符。 如果功能中包含特定于设备或语言的内容,则只要安装了一种语言以及适用于该功能中当前设备的所有区块,该内容仍将以 true 的形式返回。

例如,如果 Campaign Feature 的资产包含在区块 8000、8001 和 8002 中,则无需调用 XPackageFindChunkAvailability 方法来确定该区块是否已完全安装且可播放,而是可以使用自定义标签“campaign1”标记所有三个区块,并在 Campaign Feature 中引用“campaign1”。 然后,你可以通过使用带有 Campaign Feature ID 的 XPackageChunkSelector 调用 XPackageFindChunkAvailability 方法,来轻松获取该数据集的安装状态。

另请参阅

智能交付简介
XPackageChunkSelector
XPackageInstallChunks
MicrosoftGame.Config 本地化