Unity开发微信小程序-避开新InputSystem有关坑

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();

纯属没事找事。

相关推荐
m0_462803887 小时前
从信息管理视角看「按桌顺序分桌」:云分组优先分组的实现逻辑
微信小程序
bug总结1 天前
uniapp 微信小程序分包规范
微信小程序·小程序·uni-app
谢斯1 天前
[unity]如何在unity中添加newtonsoft-json
unity·json·游戏引擎
天人合一peng1 天前
Unity标记固定颜色及投影标记
unity
云雨巫山1 天前
Unity 游戏开发性能优化全景手册
unity·智能手机·性能优化·游戏引擎
maybeyaluokenai1 天前
unity build in渲染管线概述
unity·图形渲染
凉红茶1 天前
用Cursor开发微信小程序的第一天
微信小程序·小程序·ai编程
云雨巫山1 天前
Unity 性能优化 · 图解全景手册
unity·性能优化·游戏引擎
小马过河R1 天前
微信小程序自定义登录态维护:从入门到生产级落地
后端·微信小程序·小程序·架构·登录态
andrsted2 天前
用练题簿小程序 - 让错题不再白错
学习·微信小程序·小程序·学习方法