cs
_clickAction = new InputAction("Click", InputActionType.Button);
_clickAction.AddBinding("<Mouse>/leftButton").WithInteraction("press(behavior=1)");
_clickAction.AddBinding("<Touchscreen>/primaryTouch/press").WithInteraction("press(behavior=1)");
_clickAction.AddBinding("<Touchscreen>/press").WithInteraction("press(behavior=1)");
_clickAction.AddBinding("<Pen>/tip").WithInteraction("press(behavior=1)");
_clickAction.AddBinding("<Pointer>/press").WithInteraction("press(behavior=1)");
_clickAction.AddBinding("<Touchscreen>/primaryTouch/press").WithInteraction("tap");
_clickAction.performed += OnClickPerformed;
_clickAction.Enable();
问题
我一开始想着要覆盖各种平台的各种点击情况,建立了这一套创建新InputSystem的代码。
结果在导出微信小游戏,在屏幕上暴力快速多次点击后,OnClickPerformed不再执行了。
原因
当其中任意一个 binding 的 interaction 卡在 started/inProgress,整个 action 的 performed 都可能被你"等 release"给锁死。
解决办法
删除多余的press判断:
cs
_clickAction = new InputAction("Click", InputActionType.Button);
// 一个就够:<Pointer>/press 本身就覆盖 mouse/pen/touch(大多数平台)
_clickAction.AddBinding("<Pointer>/press").WithInteraction("press");
// 或者显式 behavior=0
// .WithInteraction("press(behavior=0)");
_clickAction.performed += OnClickPerformed;
_clickAction.Enable();
纯属没事找事。