private static string GetBindingDisplayString(InputAction action) { StringBuilder sb = new StringBuilder(); ReadOnlyArray <InputBinding> bindings = action.bindings; for (int i = 0; i < bindings.Count; ++i) { InputBinding binding = bindings[i]; // Only consider actions that make use of connected devices. // And only create info text for a composite but not for its parts. if (binding.isPartOfComposite || (!binding.isComposite && InputSystem.FindControl(binding.path) == null)) { continue; } string text = action.GetBindingDisplayString(i, InputBinding.DisplayStringOptions.DontOmitDevice); if (sb.Length > 0) { sb.Append($" | {text}"); } else { sb.Append(text); } } return(sb.ToString()); }
public void Controls_CanFindFirstMatchingControlByPath() { var gamepad = InputSystem.AddDevice <Gamepad>(); Assert.That(InputSystem.FindControl("*/leftStick/x"), Is.SameAs(gamepad.leftStick.x)); Assert.That(InputSystem.FindControl("<Gamepad>"), Is.SameAs(gamepad)); Assert.That(InputSystem.FindControl("<Mouse>/leftButton"), Is.Null); }
// f**k you unity for making input system paths inconsistent private static bool CheckEqualPaths(string pathA, string pathB) { return(InputSystem.FindControl(pathA).GetHashCode() == InputSystem.FindControl(pathB).GetHashCode()); }