> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# XGameStreamingUpdateTouchControlsState

> XGameStreamingUpdateTouchControlsState

# XGameStreamingUpdateTouchControlsState

更新所有流式处理客户端上的状态，触摸布局可用于改变其行为。对当前正在显示的触摸控件集的任何视觉更改都将在所有变量更新完成后进行。

## 语法

```cpp theme={null}
HRESULT XGameStreamingUpdateTouchControlsState(  
         size_t operationCount,  
         const XGameStreamingTouchControlsStateOperation* operations  
)  
```

### 参数

*operationCount*   \_In\_\
类型：size\_t

所传递的操作数组的大小。

*operations*   \_In\_reads\_opt\_(operationCount)\
类型：[XGameStreamingTouchControlsStateOperation\*](/reference/system/xgamestreaming/structs/xgamestreamingtouchcontrolsstateoperation)

所请求的所有状态变量更新的数组。

### 返回值

类型：HRESULT

如果成功，则返回 **S\_OK**；否则返回错误代码。

#### 潜在错误

| 错误代码                               | 错误值        | 错误原因                                                                                                                                                   |
| ---------------------------------- | ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ |
| E\_GAMESTREAMING\_NOT\_INITIALIZED | 0x89245400 | XGameStreaming 运行时尚未初始化。在调用其他 API 之前，请先调用 [XGameStreamingInitialize](/reference/system/xgamestreaming/functions/xgamestreaminginitialize)。             |
| E\_INVALIDARG                      | 0x80070057 | 指定的操作没有与操作 [XGameStreamingTouchControlsStateValueKind](/reference/system/xgamestreaming/enums/xgamestreamingtouchcontrolsstatevaluekind) 中指定的数据类型匹配的数据 |

## 备注

流式处理客户端使用的触摸布局可能依赖于状态，其初始值嵌入到触摸布局捆绑包中。游戏可以更新状态，这可能导致当前显示给玩家的布局发生变化。

游戏可以使用 `XGameStreamingUpdateTouchControlsState` 来更新所有已连接客户端的状态，或使用 [XGameStreamingUpdateTouchControlsStateOnClient](/reference/system/xgamestreaming/functions/xgamestreamingupdatetouchcontrolsstateonclient) 来更新特定的已连接客户端。

如果游戏需要同时更新状态并进行布局更改，则可以利用 [XGameStreamingShowTouchControlsWithStateUpdate](/reference/system/xgamestreaming/functions/xgamestreamingshowtouchcontrolswithstateupdate) 或 [XGameStreamingShowTouchControlsWithStateUpdateOnClient](/reference/system/xgamestreaming/functions/xgamestreamingshowtouchcontrolswithstateupdateonclient)。

## 示例

```C++ theme={null}
// In this example, after the player has switched their active weapon - update the image of the fire
// button to match the current weapon and set the enabled state of reload based on whether the player has
// extra magazines.  
// 
// Assumes passing in game structure that includes the active weapon with appropriate state.  
//
// Assumes a game speciic GetImageName function which returns a constant string for the specified weapoon


void GameStreamingClientManager::UpdateStateAfterWeaponChange(const playerWeapon& playerWeapon)
{
    // create an update for the active weapon's image
    XGameStreamingTouchControlsStateOperation weaponImage;
    weaponImage.operationKind = XGameStreamingTouchControlsStateOperationKind::Replace;
    weaponImage.path = "/ActiveWeaponImage";
    weaponImage.value.valueKind = XGameStreamingTouchControlsStateValueKind::String;
    weaponImage.value.stringValue = GetImageName(playerWeapon.activeWeapon.id);

    // create an update for whether the reload button should be enabled
    XGameStreamingTouchControlsStateOperation reloadEnabled;
    reloadEnabled.operationKind = XGameStreamingTouchControlsStateOperationKind::Replace;
    reloadEnabled.path = "/ReloadEnabled";
    reloadEnabled.valueKind = XGameStreamingTouchControlsStateValueKind::Bool;
    reloadEnabled.booleanValue = playerWeapon.activeWeapon.reloadClips > 0;

    // combine all the updates into the update state call and make the call
    XGameStreamingTouchControlsStateOperation[2] updateOperations = {weaponImage, reloadEnabled};
    
    XGameStreamingUpdateTouchControlsState(updateOperations, _countof(updateOperations));
}
```

```c++ theme={null}
// In this example, after the player has gone to their inventory screen and had the ability to apply items
// to two active slots. Update the state for layouts to have layouts match the player's current
// loaded items from inventory (may or may not be the current layout being displayed).
// 
// Assumes passing in game structure that includes the player's active inventory


void GameStreamingClientManager::AfterInventoryScreen(const PlayerInventory& playerInventory)
{
    std::vector<XGameStreamingTouchControlsStateOperation> updateOperations;
    
    // check the first inventory slots, if empty hide that button from the layout
    // if item is placed in that slot, update the image to match the inventory items
    
    XGameStreamingTouchControlsStateOperation slot1Visible;
    slot1Visible.operationKind = XGameStreamingTouchControlsStateOperationKind::Replace;
    slot1Visible.path = "/Slot1IsVisible";
    slot1Visible.valueKind = XGameStreamingTouchControlsStateValueKind::Boolean;
    slot1Visible.boolValue =  playerInventory.slot1 != nullptr;
    
    updateOperations.push_back(slot1Visible);

    if (playerInventory.slot1 != nullptr) 
    {
        // create an update for the active weapon's image
        XGameStreamingTouchControlsStateOperation slot1Image;
        slot1Image.operationKind = XGameStreamingTouchControlsStateOperationKind::Replace;
        slot1Image.path = "/Slot1Image";
        slot1Image.value.valueKind = XGameStreamingTouchControlsStateValueKind::String;
        slot1Image.value.stringValue = GetImageName(playerInventory.slot1.id);        
        updateOperations.pushBack(slot1Image);
    }
    

    // ... 
    // do the same for the second inventory spot
    // ...

    // Update the state so that layouts will be updated correctly
    XGameStreamingUpdateTouchControlsState(updateOperations.data(), updateOperations.size());
}

```

## 要求

**标头：** XGameStreaming.h

**库：** xgameruntime.lib\
**支持的平台**：Windows、XBOX One 系列主机和 XBOX Series 主机

## 另请参阅

[XGameStreaming](/reference/system/xgamestreaming/xgamestreaming_members#TouchAdaptation)\
[XGameStreamingTouchControlsStateOperationKind](/reference/system/xgamestreaming/enums/xgamestreamingtouchcontrolsstateoperationkind)\
[XGameStreamingTouchControlsStateOperation](/reference/system/xgamestreaming/structs/xgamestreamingtouchcontrolsstateoperation)\
[XGameStreamingTouchControlsStateValue](/reference/system/xgamestreaming/structs/xgamestreamingtouchcontrolsstatevalue)\
[XGameStreamingShowTouchControlsWithStateUpdate](/reference/system/xgamestreaming/functions/xgamestreamingshowtouchcontrolswithstateupdate)\
[XGameStreamingShowTouchControlsWithStateUpdateOnClient](/reference/system/xgamestreaming/functions/xgamestreamingshowtouchcontrolswithstateupdateonclient)\
[XGameStreamingUpdateTouchControlsStateOnClient](/reference/system/xgamestreaming/functions/xgamestreamingupdatetouchcontrolsstateonclient)


## Related topics

- [XGameStreamingUpdateTouchControlsStateOnClient](/zh-CN/reference/system/xgamestreaming/functions/xgamestreamingupdatetouchcontrolsstateonclient.md)
- [XGameStreamingShowTouchControlsWithStateUpdate](/zh-CN/reference/system/xgamestreaming/functions/xgamestreamingshowtouchcontrolswithstateupdate.md)
- [XGameStreamingTouchControlsStateOperation](/zh-CN/reference/system/xgamestreaming/structs/xgamestreamingtouchcontrolsstateoperation.md)
- [XGameStreamingTouchControlsStateValue](/zh-CN/reference/system/xgamestreaming/structs/xgamestreamingtouchcontrolsstatevalue.md)
- [XGameStreamingShowTouchControlsWithStateUpdateOnClient](/zh-CN/reference/system/xgamestreaming/functions/xgamestreamingshowtouchcontrolswithstateupdateonclient.md)
