/// <summary> /// 检查gamepad方案 /// </summary> void CheckCurrentJoystickScheme() { /// 查找匹配当前手柄的方案 if (curJoystickScheme != null) { for (int i = 0, length = joysticksNameArray.Length; i < length; i++) { var joy = joysticksNameArray[i]; if (!string.IsNullOrEmpty(joy) && curJoystickScheme.IsJoystickMatch(joy) && curJoystickScheme.connectedJoystickIdx == i) { /// 当前使用的joystick没有变化 return; } } // 查找失败,更新 curJoystickScheme = null; } for (int i = 0, length = joysticksNameArray.Length; i < length; i++) { var joy = joysticksNameArray[i]; if (!string.IsNullOrEmpty(joy)) { foreach (var s in joystickControlSchemes) { if (s.IsJoystickMatch(joy)) { ChangeUsingJoystickSchemeInternal(s, i); return; } } } } /// 找了一轮都没有找到匹配的手柄,则默认使用第一个 if (joystickControlSchemes.Count > 0) { for (int i = 0, length = joysticksNameArray.Length; i < length; i++) { var joy = joysticksNameArray[i]; if (!string.IsNullOrEmpty(joy)) { ChangeUsingJoystickSchemeInternal(joystickControlSchemes[0], i); return; } } } }
void ChangeUsingJoystickSchemeInternal(JoystickControlScheme newScheme, int joystickIdx = -1) { if (curJoystickScheme != null && joystickIdx == -1) { int idx = curJoystickScheme.connectedJoystickIdx; curJoystickScheme = newScheme; curJoystickScheme.Initialize(idx); } else if (joystickIdx != -1) { curJoystickScheme = newScheme; curJoystickScheme.Initialize(joystickIdx); } }
public static void ChangeUsingJoystickScheme(JoystickControlScheme newScheme) { Instance.ChangeUsingJoystickSchemeInternal(newScheme); }