LegacyGipGameControllerProvider 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
公开一组属性和功能,用于管理使用 GIP (游戏输入协议的游戏配件(例如游戏板和头戴显示设备)) 协议。
重要
访问此类需要声明 xboxAccessoryManagement 功能
注意
这些 API 会影响系统上的所有游戏,如果误用,可能会导致配件出现问题。 Microsoft 建议仅使用这些 API 来管理你开发的硬件。
public ref class LegacyGipGameControllerProvider sealed
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Gaming.Input.GamingInputPreviewContract, 131072)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class LegacyGipGameControllerProvider final
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Gaming.Input.GamingInputPreviewContract), 131072)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public sealed class LegacyGipGameControllerProvider
Public NotInheritable Class LegacyGipGameControllerProvider
- 继承
- 属性
Windows 要求
设备系列 |
Windows Desktop Extension SDK (在 10.0.23665.0 中引入)
|
API contract |
Windows.Gaming.Input.GamingInputPreviewContract (在 v2.0 中引入)
|
示例
读取控制器的属性
public void EnumerateControllerProperties()
{
foreach (Gamepad gamepad in Gamepad.Gamepads)
{
// Create the provider
LegacyGipGameControllerProvider legacyGipGameControllerProvider =
LegacyGipGameControllerProvider.FromGameController(gamepad);
if (legacyGipGameControllerProvider == null)
{
// Not every gamepad is a legacy GIP game controller, continue enumerating
continue;
}
// Check properties
GameControllerBatteryChargingState chargeState =
legacyGipGameControllerProvider.BatteryChargingState;
GameControllerBatteryKind batteryKind =
legacyGipGameControllerProvider.BatteryKind;
GameControllerBatteryLevel batteryLevel =
legacyGipGameControllerProvider.BatteryLevel;
bool isOldFirmwareCorrupted =
legacyGipGameControllerProvider.IsFirmwareCorrupted;
bool isNewFirmwareCorrupted =
legacyGipGameControllerProvider.GetDeviceFirmwareCorruptionState()
!= GameControllerFirmwareCorruptReason.NotCorrupt;
bool isSynthetic = legacyGipGameControllerProvider.IsSyntheticDevice;
byte[] extendedDeviceInfo = legacyGipGameControllerProvider.GetExtendedDeviceInfo();
// Check for a particular GIP interface
bool supportsSomeCustomInterface =
legacyGipGameControllerProvider.IsInterfaceSupported(
new Guid(
0xaaaaaaaa, 0xbbbb, 0xcccc, 0xe, 0xf, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6));
IReadOnlyList<string> preferredTypes =
legacyGipGameControllerProvider.PreferredTypes;
bool isGamepad = preferredTypes.Contains("Windows.Xbox.Input.Gamepad");
bool isHeadset = preferredTypes.Contains("Windows.Xbox.Input.Headset");
// Change the LED to half brightness
legacyGipGameControllerProvider.SetHomeLedIntensity(50);
}
}
“重新映射”按钮
void RemapButtons(IGameController controller, IGameControllerProvider controllerProvider)
{
LegacyGipGameControllerProvider legacyGipGameControllerProvider =
LegacyGipGameControllerProvider.FromGameControllerProvider(controllerProvider);
// Retrieve all current remappings set for standard controllers
IReadOnlyDictionary<RemappingButtonCategory, object> currentMappings =
legacyGipGameControllerProvider.GetStandardControllerButtonRemapping(
controller.User, false);
// Swap two of the buttons
Dictionary<RemappingButtonCategory, object> remaps =
new Dictionary<RemappingButtonCategory, object>();
// Duplicates are not allowed. Swap two of the buttons
UInt64 currentButtonMappings =
(UInt64)currentMappings[RemappingButtonCategory.ButtonSettings];
// Isolate the buttons we want to remap
UInt64 lastButton = (currentButtonMappings & 0xf000000000000000);
UInt64 secondLastButton = currentButtonMappings & 0x0f00000000000000;
// Swap their positions
UInt64 newMapping = (lastButton >> 4) | (secondLastButton << 4);
// Recombine with the original mappings
UInt64 newButtonMappings = (currentButtonMappings & 0x00ffffffffffffff) | newMapping;
// Add the new button remappings to the mapping dictionary
remaps.Add(RemappingButtonCategory.ButtonSettings, newButtonMappings);
// Update controller mapping
legacyGipGameControllerProvider.SetStandardControllerButtonRemapping(
controller.User, false, newButtonMappings);
}
Copilot 设置
public void CopilotSample(GipGameControllerProvider pilotProvider,
GipGameControllerProvider copilotProvider)
{
// Establish a copilot pairing for the given pilot and copilot providers
string pilotId = GameControllerProviderInfo.GetProviderId(pilotProvider);
string copilotId = GameControllerProviderInfo.GetProviderId(copilotProvider);
User user = User.GetDefault();
LegacyGipGameControllerProvider.PairPilotToCopilot(user, pilotId,
copilotId);
// Read copilot properties
LegacyGipGameControllerProvider.IsPilot(user, pilotId); // Returns copilotId
LegacyGipGameControllerProvider.IsPilot(user, copilotId); // Returns null
LegacyGipGameControllerProvider.IsCopilot(user, pilotId); // Returns null
LegacyGipGameControllerProvider.IsCopilot(user, copilotId); // Returns pilotId
// Removes the pairing for both controllers
LegacyGipGameControllerProvider.ClearPairing(user, pilotId);
// Also removes the pairing for both controllers (unnecessary since the pairing was already removed)
LegacyGipGameControllerProvider.ClearPairing(user, copilotId);
}
头戴显示设备管理
public void SetupHeadset(IGameControllerProvider headsetProvider)
{
LegacyGipGameControllerProvider legacyGipGameControllerProvider =
LegacyGipGameControllerProvider.FromGameControllerProvider(headsetProvider);
// Reset the device
legacyGipGameControllerProvider.ExecuteCommand(DeviceCommand.Reset);
// Check the smart mute level
byte[] smartMuteBuffer =
legacyGipGameControllerProvider.GetHeadsetOperation(HeadsetOperation.SmartMute);
HeadsetLevel smartMuteValue = (HeadsetLevel)smartMuteBuffer[0];
// Set bass boost to 3db
byte[] bassBuffer = BitConverter.GetBytes((UInt32)3);
legacyGipGameControllerProvider.SetHeadsetOperation(HeadsetOperation.BassBoostGain,
bassBuffer);
}
属性
AppCompatVersion |
获取 GIP (游戏输入协议) 驱动程序报告的应用兼容性版本。 |
BatteryChargingState |
获取控制器的电池充电状态。 |
BatteryKind |
获取控制器的电池类型。 |
BatteryLevel |
获取控制器的电池充电级别。 |
IsFirmwareCorrupted |
返回控制器固件是否损坏。 |
IsSyntheticDevice |
返回控制器是合成设备还是物理设备。 |
PreferredTypes |
获取控制器报告的 GIP (游戏输入协议) 类型的集。 |
方法
ClearPairing(User, String) |
删除给定用户的 controllerId 的任何共配配对。 |
ExecuteCommand(DeviceCommand) |
在旧版 GIP (游戏输入协议) 头戴显示设备执行命令。 |
FromGameController(IGameController) |
为给定控制器构造 LegacyGipGameControllerProvider 。 |
FromGameControllerProvider(IGameControllerProvider) |
为给定的控制器提供程序构造 LegacyGipGameControllerProvider 。 |
GetDeviceFirmwareCorruptionState() |
检索设备固件是否损坏的状态,如果是,则以何种方式损坏。 |
GetExtendedDeviceInfo() |
检索设备的标识信息。 |
GetHeadsetOperation(HeadsetOperation) |
检索基于 |
GetStandardControllerButtonRemapping(User, Boolean) |
检索用户的标准游戏板的按钮和轴映射。 |
IsCopilot(User, String) |
如果此控制器是一个主控制器,则检索该控制器的 ID。 |
IsInterfaceSupported(Guid) |
查询控制器是否支持给定的 GIP (游戏输入协议) 接口 guid。 |
IsPilot(User, String) |
如果此控制器是试点,则检索 copilot 控制器的 ID。 |
PairPilotToCopilot(User, String, String) |
为给定用户配对给定的试点控制器和副驾驶控制器。 |
SetHeadsetOperation(HeadsetOperation, Byte[]) |
设置头戴显示设备操作。 |
SetHomeLedIntensity(Byte) |
在控制器的主按钮中设置 LED 的亮度。 |
SetStandardControllerButtonRemapping(User, Boolean, IMapView<RemappingButtonCategory,Object>) |
为用户更改标准游戏板的按钮和轴映射。 |