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

纯属没事找事。

相关推荐
WarPigs13 小时前
Unity无法修改Assembly-CSharp.csproj错误
unity
IT研究室18 小时前
最新计算机毕业设计选题推荐-基于微信小程序的汉服交易系统-网站-文档指导-Java-springboot
java·微信小程序·课程设计
2301_322414280421 小时前
springboot学生课堂出勤统计系统15835-计算机毕设 原创(免费领源码+部署教程+开发环境)
java·mysql·随机森林·微信小程序·uni-app·微信开发者工具·推荐算法
FairGuard手游加固1 天前
手游加固怎么做?SO、IL2CPP、AssetBundle 与运行时保护详解
安全·游戏·unity
小蒜学长1 天前
微信小程序-高校自习室管理系统(代码+数据库+LW)
java·spring boot·后端·微信小程序·自习室管理
阿松爱学习2 天前
【Unity开发】监听Scene场景事件
unity·c#
微擎应用市场3 天前
多功能预约公众号管理系统介绍
微信小程序·小程序
xiaogai_gai3 天前
BOM 物料清单同步实战:金蝶云星空 → 四化智造 MES 修改场景深度拆解
unity·游戏引擎
小皮虾3 天前
小程序全局状态还能这么简单?只需初始化一次,页面自动同步
前端·javascript·微信小程序
andrsted3 天前
练题簿助学教学:在线刷题、随堂考试,让一门课拥有自己的题库
学习·微信小程序·小程序·学习方法·刷题