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

# 處理控制器遺失

> 處理控制器遺失

對大多數遊戲而言，讓控制器與使用者建立關聯至關重要。當
遊戲失去某位使用者的所有此類控制器時 (例如電池沒電)，
單人遊戲的標準做法是暫停遊戲並顯示對話方塊，
要求使用者開啟控制器。

使用 [XUserFindControllerForUserWithUiAsync](/zh-TW/reference/system/xuser/functions/xuserfindcontrollerforuserwithuiasync)
函式，遊戲可以改善此體驗。此函式接受 XUserHandle
作為輸入，並會顯示對話方塊：

\<\<Gamer>>，您需要控制器才能玩此遊戲。
按住 A 以確認您要使用的控制器

使用者確認其控制器後，遊戲可以呼叫
[XUserFindControllerForUserWithUiResult](/zh-TW/reference/system/xuser/functions/xuserfindcontrollerforuserwithuiresult)
以取得所選控制器的 APP\_LOCAL\_DEVICE\_ID。更重要的是，該
控制器現在已與該使用者建立關聯。如果該使用者接著按下 Nexus 按鈕，
XBOX 指南將會在指南中顯示該使用者的資訊。

請注意，玩家可以在不選取控制器的情況下取消此對話方塊，遊戲應適當處理此取消動作。例如，遊戲可以重複呼叫 [XUserFindControllerForUserWithUiAsync](/zh-TW/reference/system/xuser/functions/xuserfindcontrollerforuserwithuiasync) 以強制進行選取，或因為不再有使用者/控制器對應而返回標題畫面，或採取其他對該遊戲合理的行為。

另請注意，透過此程序，使用者可能會與先前和遊戲中其他使用者相關聯的控制器建立關聯。這是設計使然。

每當使用者與控制器之間的關聯變更時，就會觸發
[XUserDeviceAssociationChangedCallback](/zh-TW/reference/system/xuser/functions/xuserdeviceassociationchangedcallback)。
請注意，呼叫
[XUserFindControllerForUserWithUiAsync](/zh-TW/reference/system/xuser/functions/xuserfindcontrollerforuserwithuiasync)
而成功將使用者與控制器配對時，也會觸發此事件。

## 另請參閱

[XUserFindControllerForUserWithUiAsync](/zh-TW/reference/system/xuser/functions/xuserfindcontrollerforuserwithuiasync)


## Related topics

- [XR-115 遊戲過程中新增和移除使用者或控制器](/zh-TW/publishing/certification/xr/xr-115.md)
- [标准 XBOX 控制器触控控制布局](/zh-CN/build/core-features/common/game-streaming/building-touch-layouts/samples/game-streaming-touch-tak-sample-full-layout.md)
- [XR-112 在初始啟用和繼續時建立使用者與控制器](/zh-TW/publishing/certification/xr/xr-112.md)
- [XUserFindControllerForUserWithUiAsync](/zh-CN/reference/system/xuser/functions/xuserfindcontrollerforuserwithuiasync.md)
- [XUserFindControllerForUserWithUiResult](/zh-CN/reference/system/xuser/functions/xuserfindcontrollerforuserwithuiresult.md)
