> ## 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.

# ゲーム状態に基づくタッチ コントロール レイアウトの変更

> ゲーム状態に基づくタッチ コントロール レイアウトの変更

ゲームは、プレイヤーに表示されるタッチ レイアウトを変更したり、現在表示されているレイアウトが使用している状態を変更したりできます。両方の方法を一緒に使用して、プレイヤーに最も自然な体験を作成できます。

**[レイアウトの変更](#change_layout)**

レイアウトの変更は次の場合に使用します。

* 異なるコントロール スキーム間の遷移 (たとえば、車両の運転とファーストパーソン シューティング)
* タッチ レイアウトを一時的に非表示にする (完全なタッチ体験を実現するため、シネマティック体験を有効にするためなど)

**[状態の変更](#change_state)**

タッチ適応バンドルのコンテキスト部分に含まれているゲーム状態の変更は、次の場合に使用します。

* プレイヤーの現在のゲーム状態に基づいて、コントロールの画像/アイコノグラフィを変更する。いくつかの例:
  * プレイヤーが選択した武器に基づいて、発射ボタンの画像を変更する。
  * プレイヤーが現在インベントリに持っているアイテムに基づいて、能力の画像を変更する。
* プレイヤーの現在のゲーム状態に基づいて、コントロールのビジュアル状態 (表示および有効) を変更する。いくつかの例:
  * プレイヤーに追加の弾薬がない場合、リロード ボタンを無効にする。
  * プレイヤーが対話可能なアイテムに近づいた場合、対話ボタンを表示する (離れると非表示にする)。

<a id="change_layout" />

## 実行時のレイアウト変更

**指定されたレイアウトを表示する**
ゲームは、新しいレイアウトを表示するために [`XGameStreamingShowTouchControlLayout`](/reference/system/xgamestreaming/functions/xgamestreamingshowtouchcontrollayout) API を使用する必要があります。

**現在のレイアウトを非表示にする**
ゲームは、現在表示されているレイアウトを非表示にするために [`XGameStreamingHideTouchControls`](/reference/system/xgamestreaming/functions/xgamestreaminghidetouchcontrols) API を使用する必要があります。

ゲームが現在のゲームの状態に基づいてレイアウトを設定する方法の例:

```C++ theme={null}
void OnGameStateChanged(GameState newState)
{
    // Toggle to the set of touch overlay controls which best match the new state of the game
    switch (newState)
    {
    case GameState::FirstPersonAction:
        XGameStreamingShowTouchControlLayout("FirstPersonAction");
        break;
    case GameState::Driving:
        XGameStreamingShowTouchControlLayout("Driving");
        break;
    case GameState::CutScene:
        // Don't show any touch overlay controls while the cut scene is rendering
        XGameStreamingHideTouchControls();
        break;
    }
}
```

<a id="change_state" />

## 実行時の状態変更

ゲームの起動時の初期状態は、タッチ適応バンドルに含まれる [既定の状態](/build/core-features/common/game-streaming/game-streaming-touch-touch-adaptation-bundle#context) によって定義されます。タッチ コントロール レイアウトでは、コントロールは実行時に変更される可能性のあるプロパティの状態を参照する必要があります。

ゲームは、実行時に状態を更新するために `XGameStreamingUpdateTouchControlsState` API を利用できます。

たとえば、無効の状態から始まって、その機能を持つべきときに有効になる「リロード」コントロールを持つには、以下を使用します。

```JSON theme={null}
//Example context file
{
  "$schema": "https://raw.githubusercontent.com/microsoft/xbox-game-streaming-tools/main/touch-adaptation-kit/schemas/context/v3.0/context.json",

  "state": {
    "enableReload": false
  }
}

//Example control in the layout:
{
    "type": "button",
    "action": "leftBumper",
    "enabled": {
        "$ref": "../../context.json#/state/enableReload"
    }
    ...
}
```

ゲームは、状態を更新するために API 呼び出しを行います。

```C++ theme={null}

// In this example, after the player has switched their active weapon - the game updates 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.
//

void GameStreamingClientManager::UpdateStateAfterItemsChange(const playerWeapon& playerWeapon)
{
    // create an update for whether the reload button should be enabled
    XGameStreamingTouchControlsStateOperation reloadEnabled;
    reloadEnabled.operationKind = XGameStreamingTouchControlsStateOperationKind::Replace;
    reloadEnabled.path = "/enableReload";
    reloadEnabled.valueKind = XGameStreamingTouchControlsStateValueKind::Bool;
    reloadEnabled.booleanValue = playerWeapon.activeWeapon.reloadClips > 0;

    // combine all the updates into the update state call and make the call
    XGameStreamingTouchControlsStateOperation[1] updateOperations = {reloadEnabled};

    XGameStreamingUpdateTouchControlsState(updateOperations, _countof(updateOperations));
}
```


## Related topics

- [タッチ コントロール レイアウトの構築](/ja-jp/build/core-features/common/game-streaming/building-touch-layouts/game-streaming-touch-building-touch-layout.md)
- [XBOX ゲーム ストリーミング向けのタッチ操作レイアウトを作成する](/ja-jp/build/core-features/common/game-streaming/building-touch-layouts/index.md)
- [タッチ コントロール構築のデザイナーズ ガイド](/ja-jp/build/core-features/common/game-streaming/building-touch-layouts/game-streaming-tak-designers-guide.md)
- [サンプル](/ja-jp/build/core-features/common/game-streaming/building-touch-layouts/samples/index.md)
- [標準 XBOX コントローラー用タッチ操作レイアウト](/ja-jp/build/core-features/common/game-streaming/building-touch-layouts/samples/game-streaming-touch-tak-sample-full-layout.md)
