{"id":12826,"date":"2025-04-18T19:55:42","date_gmt":"2025-04-18T11:55:42","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/12826.html"},"modified":"2025-04-18T19:55:42","modified_gmt":"2025-04-18T11:55:42","slug":"unity%e8%b7%a8%e5%b9%b3%e5%8f%b0%e8%be%93%e5%85%a5%e7%b3%bb%e7%bb%9f","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/12826.html","title":{"rendered":"Unity\u8de8\u5e73\u53f0\u8f93\u5165\u7cfb\u7edf"},"content":{"rendered":"<\/p>\n<h4>\u6587\u7ae0\u76ee\u5f55<\/h4>\n<ul>\n<li>Unity\u8de8\u5e73\u53f0\u65b0\u8f93\u5165\u7cfb\u7edf<\/li>\n<li>\n<ul>\n<li>\u524d\u8bed<\/li>\n<li>\u65b0\u65e7\u5bf9\u6bd4<\/li>\n<li>\u6a21\u5757\u7ed3\u6784<\/li>\n<li>\u6a21\u5757\u534f\u4f5c\u6d41\u7a0b<\/li>\n<li>\u8de8\u5e73\u53f0<\/li>\n<li>\n<ul>\n<li>\u4ee3\u7801\u793a\u4f8b<\/li>\n<\/ul>\n<\/li>\n<li>\u4ed3\u5e93\u5730\u5740<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h2>Unity\u8de8\u5e73\u53f0\u65b0\u8f93\u5165\u7cfb\u7edf<\/h2>\n<p>\u65b0\u8f93\u5165\u7cfb\u7edf\u6307\u7684\u662f\u533a\u522b\u4e8e\u65e7\u7684\u8f6e\u8be2\u5f0f\u7684Input\u7cfb\u7edf&#xff0c;\u57fa\u4e8e\u4e8b\u4ef6\u8ba2\u9605&#xff0c;\u4ec5\u5728\u8f93\u5165\u53d1\u751f\u65f6\u89e6\u53d1\u903b\u8f91\u7684\u7cfb\u7edf\u3002<\/p>\n<h3>\u524d\u8bed<\/h3>\n<p>Unity\u4e2d\u7684\u8f93\u5165&#xff0c;\u53ef\u4ee5\u5927\u81f4\u7684\u5206\u4e3a\u4e24\u79cd&#xff1a;\u5728UI\u4e0a\u7684\u8f93\u5165\u548c\u6765\u81ea\u5916\u6765\u8bbe\u5907\u7684\u8f93\u5165\u3002\u5176\u4e2dUI\u4e0a\u7684\u8f93\u5165&#xff0c;\u4e00\u822c\u6307\u7684\u662f\u4ee5UGUI\u4e3a\u6846\u67b6&#xff0c;\u4f7f\u7528\u5c04\u7ebf\u4ee5\u53ca\u76f8\u5173EventSystem\u7cfb\u7edf&#xff0c;BaseEventData\u548c\u76f8\u5173\u7c7bBaseInputModule\u3001PointerInputModule,StandalonbeInputModule,TouchInputModule\u7ec4\u6210\u7684\u90e8\u5206&#xff1b;\u53e6\u5916\u7684\u5c31\u662f\u6307\u4ee5\u9f20\u6807\u3001\u952e\u76d8\u3001\u89e6\u63a7\u3001\u4e3b\u673a\u63a7\u5236\u5668\u548cVR\u7b49\u8bbe\u5907\u3002<\/p>\n<h3>\u65b0\u65e7\u5bf9\u6bd4<\/h3>\n<p>\u76f8\u6bd4\u8f83\u4e8e\u65e7\u7684\u8f93\u5165\u7cfb\u7edf&#xff0c;\u5177\u6709\u4ee5\u4e0b\u4f18\u70b9&#xff1a;<\/p>\n<li>\n<p>\u4e8b\u4ef6\u9a71\u52a8\u6027\u8d28<\/p>\n<ul>\n<li>\u65e7\u7cfb\u7edf&#xff1a;\u4f9d\u8d56Input.GetKey\u8f6e\u8be2&#xff0c;\u6548\u7387\u4f4e\u3002<\/li>\n<li>\u65b0\u7cfb\u7edf&#xff1a;\u57fa\u4e8e\u4e8b\u4ef6\u8ba2\u9605&#xff0c;\u4ec5\u5728\u8f93\u5165\u53d1\u751f\u65f6\u89e6\u53d1\u903b\u8f91&#xff0c;\u51cf\u5c11CPU\u5f00\u9500\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u591a\u8bbe\u5907\u7edf\u4e00\u7ba1\u7406<\/p>\n<ul>\n<li>\u65e7\u7cfb\u7edf&#xff1a;\u9700\u8981\u624b\u52a8\u5904\u7406\u4e0d\u540c\u8bbe\u5907&#xff08;\u5982\u952e\u9f20\u3001\u89e6\u6478&#xff09;\u7684\u8f93\u5165\u5dee\u5f02\u3002<\/li>\n<li>\u65b0\u7cfb\u7edf&#xff1a;\u901a\u8fc7InputService\u96c6\u4e2d\u7ba1\u7406&#xff0c;\u652f\u6301\u52a8\u6001\u6dfb\u52a0\/\u79fb\u9664\u8bbe\u5907\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u590d\u6742\u624b\u52bf\u652f\u6301<\/p>\n<ul>\n<li>\u65e7\u7cfb\u7edf&#xff1a;\u9700\u624b\u52a8\u5b9e\u73b0\u7f29\u653e\u3001\u65cb\u8f6c\u7b49\u624b\u52bf\u3002<\/li>\n<li>\u65b0\u7cfb\u7edf&#xff1a;\u96c6\u6210DigitalRubyShared\u5e93&#xff0c;\u76f4\u63a5\u652f\u6301\u591a\u6307\u624b\u52bf&#xff08;\u5982\u53cc\u6307\u7f29\u653e\u3001\u53cc\u51fb&#xff09;\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u89e3\u8026\u4e0e\u6269\u5c55\u6027<\/p>\n<ul>\n<li>\u65e7\u7cfb\u7edf&#xff1a;\u4e1a\u52a1\u903b\u8f91\u4e0e\u8f93\u5165\u68c0\u6d4b\u5f3a\u8026\u5408\u3002<\/li>\n<li>\u65b0\u7cfb\u7edf&#xff1a;\u901a\u8fc7InputMessage\u4f20\u9012\u4e8b\u4ef6&#xff0c;\u65b0\u589e\u8f93\u5165\u7c7b\u578b\u53ea\u9700\u6269\u5c55\u6d88\u606f\u7c7b&#xff0c;\u65e0\u9700\u4fee\u6539\u73b0\u6709\u4ee3\u7801\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u8de8\u5e73\u53f0\u517c\u5bb9\u6027<\/p>\n<ul>\n<li>\u65e7\u7cfb\u7edf&#xff1a;\u9700\u4e3a\u4e0d\u540c\u5e73\u53f0\u7f16\u5199\u6761\u4ef6\u5206\u652f&#xff08;\u5982#if UNITY_ANDROID&#xff09;\u3002<\/li>\n<li>\u65b0\u7cfb\u7edf&#xff1a;\u62bd\u8c61\u5c42\u81ea\u52a8\u9002\u914d\u4e0d\u540c\u8f93\u5165\u6e90&#xff08;\u5982\u89e6\u6478\u5c4f\u6620\u5c04\u4e3a\u9f20\u6807\u4e8b\u4ef6&#xff09;\u3002<\/li>\n<\/ul>\n<\/li>\n<h3>\u6a21\u5757\u7ed3\u6784<\/h3>\n<li>\n<p>\u670d\u52a1\u5c42&#xff08;InputService&#xff09;<\/p>\n<ul>\n<li>\n<p>\u804c\u8d23&#xff1a;\u5168\u5c40\u5355\u4f8b\u7ba1\u7406\u6240\u6709\u8f93\u5165\u8bbe\u5907&#xff0c;\u7edf\u4e00\u5206\u53d1\u6d88\u606f\u3002<\/p>\n<\/li>\n<li>\n<p>\u5173\u952e\u63a5\u53e3&#xff1a;<\/p>\n<p> <span class=\"token keyword\">public<\/span> <span class=\"token return-type class-name\"><span class=\"token keyword\">void<\/span><\/span> <span class=\"token generic-method\"><span class=\"token function\">AddDevice<\/span><span class=\"token generic class-name\"><span class=\"token punctuation\">&lt;<\/span>TDevice<span class=\"token punctuation\">&gt;<\/span><\/span><\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">where<\/span> <span class=\"token class-name\">TDevice<\/span> <span class=\"token punctuation\">:<\/span> <span class=\"token type-list\"><span class=\"token class-name\">MonoBehaviour<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token class-name\">IInputDevice<\/span><\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token keyword\">public<\/span> <span class=\"token return-type class-name\"><span class=\"token keyword\">void<\/span><\/span> <span class=\"token function\">PushMessage<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">InputMessage<\/span> msg<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>  <span class=\"token comment\">\/\/ \u6d88\u606f\u63a8\u9001\u5165\u53e3<\/span>\n <\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u8bbe\u5907\u62bd\u8c61\u5c42&#xff08;InputDevice&#xff09;<\/p>\n<ul>\n<li>\n<p>\u804c\u8d23&#xff1a;\u6240\u6709\u8f93\u5165\u8bbe\u5907\u7684\u57fa\u7c7b&#xff0c;\u5b9e\u73b0\u8ba2\u9605\u673a\u5236\u4e0e\u6d88\u606f\u5904\u7406\u3002<\/p>\n<\/li>\n<li>\n<p>\u6838\u5fc3\u80fd\u529b&#xff1a;<\/p>\n<p> <span class=\"token keyword\">public<\/span> <span class=\"token keyword\">abstract<\/span> <span class=\"token return-type class-name\"><span class=\"token keyword\">bool<\/span><\/span> <span class=\"token function\">HandleMessage<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">InputMessage<\/span> msg<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>  <span class=\"token comment\">\/\/ \u6d88\u606f\u5904\u7406<\/span><br \/>\n<span class=\"token keyword\">public<\/span> <span class=\"token return-type class-name\"><span class=\"token keyword\">void<\/span><\/span> <span class=\"token generic-method\"><span class=\"token function\">SubscribeOn<\/span><span class=\"token generic class-name\"><span class=\"token punctuation\">&lt;<\/span>TMessage<span class=\"token punctuation\">&gt;<\/span><\/span><\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">Action<span class=\"token punctuation\">&lt;<\/span>TMessage<span class=\"token punctuation\">&gt;<\/span><\/span> callback<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>  <span class=\"token comment\">\/\/ \u4e8b\u4ef6\u8ba2\u9605<\/span>\n <\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u8bbe\u5907\u5b9e\u73b0\u5c42<\/p>\n<ul>\n<li>InputDevice_NewSystem&#xff1a;\u57fa\u4e8eUnity\u65b0\u8f93\u5165\u7cfb\u7edf&#xff08;InputSystem&#xff09;\u7684\u952e\u76d8\/\u9f20\u6807\/\u89e6\u6478\u5b9e\u73b0\u3002<\/li>\n<li>InputDevice_Legacy&#xff1a;\u517c\u5bb9\u4f20\u7edfInputManager\u7684\u8f93\u5165\u5904\u7406\u3002<\/li>\n<li>InputDevice_Virtual&#xff1a;\u865a\u62df\u63a7\u4ef6&#xff08;\u5982\u865a\u62df\u6447\u6746\u3001\u6309\u94ae&#xff09;\u7684\u4e8b\u4ef6\u8f6c\u53d1\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u6d88\u606f\u534f\u8bae&#xff08;InputMessage&#xff09;<\/p>\n<ul>\n<li>\n<p>\u6240\u6709\u8f93\u5165\u4e8b\u4ef6\u7684\u57fa\u7c7b&#xff0c;\u901a\u8fc7\u6d3e\u751f\u7c7b\u5b9a\u4e49\u5177\u4f53\u884c\u4e3a&#xff1a;<\/p>\n<p> <span class=\"token keyword\">public<\/span> <span class=\"token keyword\">class<\/span> <span class=\"token class-name\">KeyDown<\/span> <span class=\"token punctuation\">:<\/span> <span class=\"token type-list\"><span class=\"token class-name\">InputMessage<\/span><\/span> <span class=\"token punctuation\">{<\/span> <span class=\"token range operator\">..<\/span><span class=\"token punctuation\">.<\/span> <span class=\"token punctuation\">}<\/span>  <span class=\"token comment\">\/\/ \u6309\u952e\u6309\u4e0b<\/span><br \/>\n<span class=\"token keyword\">public<\/span> <span class=\"token keyword\">class<\/span> <span class=\"token class-name\">TouchMove<\/span> <span class=\"token punctuation\">:<\/span> <span class=\"token type-list\"><span class=\"token class-name\">InputMessage<\/span><\/span> <span class=\"token punctuation\">{<\/span> <span class=\"token range operator\">..<\/span><span class=\"token punctuation\">.<\/span> <span class=\"token punctuation\">}<\/span> <span class=\"token comment\">\/\/ \u89e6\u6478\u79fb\u52a8<\/span><br \/>\n<span class=\"token keyword\">public<\/span> <span class=\"token keyword\">class<\/span> <span class=\"token class-name\">AxisChange<\/span> <span class=\"token punctuation\">:<\/span> <span class=\"token type-list\"><span class=\"token class-name\">InputMessage<\/span><\/span> <span class=\"token punctuation\">{<\/span> <span class=\"token range operator\">..<\/span><span class=\"token punctuation\">.<\/span> <span class=\"token punctuation\">}<\/span> <span class=\"token comment\">\/\/ \u6447\u6746\u8f93\u5165<\/span>\n <\/li>\n<\/ul>\n<\/li>\n<h3>\u6a21\u5757\u534f\u4f5c\u6d41\u7a0b<\/h3>\n<p>\u4ee5\u4e0b\u4ee5\u865a\u62df\u6309\u94ae\u70b9\u51fb\u4e8b\u4ef6\u4e3a\u4f8b&#xff0c;\u5c55\u793a\u7cfb\u7edf\u5185\u90e8\u534f\u4f5c&#xff1a;<\/p>\n<li>\n<p>\u7528\u6237\u70b9\u51fb\u865a\u62df\u6309\u94ae<\/p>\n<p> <span class=\"token comment\">\/\/ VirtualButton.cs<\/span><br \/>\n<span class=\"token keyword\">public<\/span> <span class=\"token return-type class-name\"><span class=\"token keyword\">void<\/span><\/span> <span class=\"token function\">OnPointerDown<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">PointerEventData<\/span> eventData<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    InputService<span class=\"token punctuation\">.<\/span>Instance<span class=\"token punctuation\">.<\/span><span class=\"token function\">PushMessage<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">new<\/span> <span class=\"token constructor-invocation class-name\">ButtonDown<\/span><span class=\"token punctuation\">(<\/span>btnName<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span>\n <\/li>\n<li>\n<p>\u6d88\u606f\u8def\u7531\u81f3\u8bbe\u5907<\/p>\n<p> <span class=\"token comment\">\/\/ InputService.cs<\/span><br \/>\n<span class=\"token keyword\">public<\/span> <span class=\"token return-type class-name\"><span class=\"token keyword\">void<\/span><\/span> <span class=\"token function\">PushMessage<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">InputMessage<\/span> msg<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token keyword\">foreach<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token class-name\"><span class=\"token keyword\">var<\/span><\/span> device <span class=\"token keyword\">in<\/span> deviceList<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>device<span class=\"token punctuation\">.<\/span><span class=\"token function\">HandleMessage<\/span><span class=\"token punctuation\">(<\/span>msg<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">break<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span>\n <\/li>\n<li>\n<p>\u8bbe\u5907\u5904\u7406\u8ba2\u9605\u56de\u8c03<\/p>\n<p> <span class=\"token comment\">\/\/ \u4e1a\u52a1\u4ee3\u7801\u8ba2\u9605<\/span><br \/>\nInputService<span class=\"token punctuation\">.<\/span>Instance<span class=\"token punctuation\">.<\/span><span class=\"token generic-method\"><span class=\"token function\">SubscribeOn<\/span><span class=\"token generic class-name\"><span class=\"token punctuation\">&lt;<\/span>ButtonDown<span class=\"token punctuation\">&gt;<\/span><\/span><\/span><span class=\"token punctuation\">(<\/span>msg <span class=\"token operator\">&#061;&gt;<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>msg<span class=\"token punctuation\">.<\/span>ButtonName <span class=\"token operator\">&#061;&#061;<\/span> <span class=\"token string\">&#034;Jump&#034;<\/span><span class=\"token punctuation\">)<\/span> Player<span class=\"token punctuation\">.<\/span><span class=\"token function\">Jump<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span>\n <\/li>\n<h3>\u8de8\u5e73\u53f0<\/h3>\n<p>\u5148\u601d\u8003\u4e00\u4e2a\u95ee\u9898&#xff0c;\u5bf9\u4e8e\u6e38\u620f\u4e2d\u7684UI&#xff0c;\u4e0d\u7ba1\u5728PC\u7aef\u8fd8\u662f\u79fb\u52a8\u7aef&#xff0c;\u6211\u4eec\u90fd\u6ca1\u6709\u9884\u5148\u5bf9\u6b64\u8fdb\u884c\u9002\u914d&#xff0c;\u4f46\u662f\u4e3a\u4ec0\u4e48\u6211\u4eec\u5728\u70b9\u51fb\u6216\u8005\u89e6\u6478\u7684\u65f6\u5019&#xff0c;\u6e38\u620f\u597d\u50cf\u5df2\u7ecf\u77e5\u9053\u6211\u4eec\u8981\u5e72\u4ec0\u4e48\u4e86&#xff1f;\u8fd9\u662f\u56e0\u4e3aUnity\u5df2\u7ecf\u5728\u5e95\u5c42\u4e0a\u7ed9\u6211\u4eec\u505a\u4e86\u9002\u914d&#xff0c;UGUI\u7684\u6e90\u7801\u91cc\u9762\u6709TouchInputModule\u8fd9\u4e2a\u5c31\u662f\u89e6\u6478\u7684\u90e8\u5206\u903b\u8f91&#xff0c;\u8fd9\u91cc\u63a8\u8350\u53ef\u4ee5\u770b\u770b\u300aUnity3D \u9ad8\u7ea7\u7f16\u7a0b \u4e3b\u7a0b\u624b\u8bb0\u300b\u8fd9\u672c\u4e66&#xff0c;\u91cc\u9762\u6709\u5bf9UGUI\u8f83\u4e3a\u8be6\u7ec6\u7684\u89e3\u6790\u3002<\/p>\n<p>\u7136\u540e\u662f\u601d\u8003\u8f93\u5165\u8bbe\u5907\u7684\u8de8\u5e73\u53f0\u662f\u5982\u4f55\u505a\u5230\u7684&#xff0c;\u5176\u5b9eUnity\u4e00\u5f00\u59cb\u5bf9\u4e3b\u673a\u5c42\u9762\u7684\u8de8\u5e73\u53f0\u505a\u7684\u4e0d\u597d&#xff0c;\u9700\u8981\u4e00\u4e2a\u4e2a\u7279\u6b8a\u5904\u7406\u5199\u8fc7\u53bb&#xff0c;\u76f4\u5230\u4ece2019\u7248\u672c\u5f00\u59cb\u63a8\u65b0\u7684\u8f93\u5165\u7cfb\u7edf&#xff0c;\u624d\u5f00\u59cb\u6709\u6539\u5584\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418115541-68023dbd4211a.png\" alt=\"\u8f93\u5165\" \/><\/p>\n<p>\u56fe\u4e0a\u7684\u8f93\u5165\u5c31\u80fd\u517c\u5bb9\u89e6\u6478Touch\u548cMouseMove\u7684\u64cd\u4f5c&#xff0c;\u7136\u540e\u53ea\u8981\u5728\u4ee3\u7801\u4e2d\u53d1\u9001\u540c\u6837\u7684\u6d88\u606f\u4e8b\u4ef6\u5c31\u80fd\u5b9e\u73b0\u4e00\u6837\u7684\u64cd\u4f5c&#xff0c;\u8fd9\u4e00\u90e8\u5206\u5c5e\u4e8eUnity\u672c\u8eab\u7684\u65b0\u8f93\u5165\u7cfb\u7edf\u81ea\u5e26\u7684\u914d\u7f6e\u6587\u4ef6\u3002<img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418115541-68023dbd6e7b3.png\" alt=\"\u8f93\u5165\" \/> \u70b9\u51fb\u751f\u6210\u5bf9\u5e94\u7684C#\u6587\u4ef6\u540e&#xff0c;\u5c31\u80fd\u5728\u6846\u67b6\u4e2d\u4f7f\u7528&#xff0c;\u5177\u4f53\u4f7f\u7528\u53ef\u4ee5\u770b\u6846\u67b6\u4ee3\u7801\u3002\u672c\u6587\u4e0d\u8be6\u7ec6\u89e3\u91ca\u5173\u4e8eUnity\u4e2d\u81ea\u8eab\u8f93\u5165\u6846\u67b6\u7684\u5185\u5bb9\u3002<\/p>\n<ul>\n<li>GitHub \u6e90\u7801\u5e93&#xff1a;https:\/\/github.com\/Unity-Technologies\/InputSystem<\/li>\n<\/ul>\n<h4>\u4ee3\u7801\u793a\u4f8b<\/h4>\n<p>InputSystem<span class=\"token punctuation\">.<\/span>onDeviceChange <span class=\"token operator\">&#043;&#061;<\/span> OnDeviceChange<span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token keyword\">private<\/span> <span class=\"token return-type class-name\"><span class=\"token keyword\">void<\/span><\/span> <span class=\"token function\">OnDeviceChange<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">InputDevice<\/span> inputDevice<span class=\"token punctuation\">,<\/span> <span class=\"token class-name\">InputDeviceChange<\/span> inputDeviceChange<span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>inputDeviceChange <span class=\"token operator\">&#061;&#061;<\/span> InputDeviceChange<span class=\"token punctuation\">.<\/span>Added<span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token function\">SetupDevice<\/span><span class=\"token punctuation\">(<\/span>inputDevice<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        Debug<span class=\"token punctuation\">.<\/span><span class=\"token function\">Log<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\u8bbe\u5907\u63a5\u5165&#xff1a;&#034;<\/span> <span class=\"token operator\">&#043;<\/span> inputDevice<span class=\"token punctuation\">.<\/span>device<span class=\"token punctuation\">.<\/span>name<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n    <span class=\"token keyword\">else<\/span> <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>inputDeviceChange <span class=\"token operator\">&#061;&#061;<\/span> InputDeviceChange<span class=\"token punctuation\">.<\/span>Removed<span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token function\">RemoveDevice<\/span><span class=\"token punctuation\">(<\/span>inputDevice<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        Debug<span class=\"token punctuation\">.<\/span><span class=\"token function\">Log<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\u8bbe\u5907\u79fb\u9664&#xff1a;&#034;<\/span> <span class=\"token operator\">&#043;<\/span> inputDevice<span class=\"token punctuation\">.<\/span>device<span class=\"token punctuation\">.<\/span>name<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p><span class=\"token keyword\">private<\/span> <span class=\"token return-type class-name\"><span class=\"token keyword\">void<\/span><\/span> <span class=\"token function\">SetupDevice<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">InputDevice<\/span> inputDevice<span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token comment\">\/\/ \u6839\u636e\u8bbe\u5907\u7c7b\u578b\u8fdb\u884c\u76f8\u5e94\u7684\u8bbe\u7f6e<\/span><br \/>\n    <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>inputDevice <span class=\"token keyword\">is<\/span> <span class=\"token class-name\">Touchscreen<\/span> touchscreen<span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token punctuation\">{<\/span><br \/>\n        inputMap<span class=\"token punctuation\">.<\/span>Player<span class=\"token punctuation\">.<\/span>Touch<span class=\"token punctuation\">.<\/span>started <span class=\"token operator\">&#043;&#061;<\/span> OnTouchStarted<span class=\"token punctuation\">;<\/span><br \/>\n        inputMap<span class=\"token punctuation\">.<\/span>Player<span class=\"token punctuation\">.<\/span>Touch<span class=\"token punctuation\">.<\/span>performed <span class=\"token operator\">&#043;&#061;<\/span> OnTouchPerformed<span class=\"token punctuation\">;<\/span><br \/>\n        inputMap<span class=\"token punctuation\">.<\/span>Player<span class=\"token punctuation\">.<\/span>Touch<span class=\"token punctuation\">.<\/span>canceled <span class=\"token operator\">&#043;&#061;<\/span> OnTouchCanceled<span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n    <span class=\"token keyword\">else<\/span> <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>inputDevice <span class=\"token keyword\">is<\/span> <span class=\"token class-name\">Keyboard<\/span> keyboard<span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token punctuation\">{<\/span><br \/>\n        inputMap<span class=\"token punctuation\">.<\/span>Player<span class=\"token punctuation\">.<\/span>Move<span class=\"token punctuation\">.<\/span>performed <span class=\"token operator\">&#043;&#061;<\/span> OnMovePerformed<span class=\"token punctuation\">;<\/span><br \/>\n        inputMap<span class=\"token punctuation\">.<\/span>Player<span class=\"token punctuation\">.<\/span>Move<span class=\"token punctuation\">.<\/span>canceled <span class=\"token operator\">&#043;&#061;<\/span> OnMoveCancle<span class=\"token punctuation\">;<\/span><\/p>\n<p>        inputMap<span class=\"token punctuation\">.<\/span>Player<span class=\"token punctuation\">.<\/span>Jump<span class=\"token punctuation\">.<\/span>performed <span class=\"token operator\">&#043;&#061;<\/span> OnKeyboardPerformed<span class=\"token punctuation\">;<\/span><br \/>\n        inputMap<span class=\"token punctuation\">.<\/span>Player<span class=\"token punctuation\">.<\/span>Jump<span class=\"token punctuation\">.<\/span>canceled <span class=\"token operator\">&#043;&#061;<\/span> OnKeyboardCancle<span class=\"token punctuation\">;<\/span><\/p>\n<p>        inputMap<span class=\"token punctuation\">.<\/span>Player<span class=\"token punctuation\">.<\/span>MouseButton<span class=\"token punctuation\">.<\/span>started <span class=\"token operator\">&#043;&#061;<\/span> OnMouseButtonStarted<span class=\"token punctuation\">;<\/span><br \/>\n        inputMap<span class=\"token punctuation\">.<\/span>Player<span class=\"token punctuation\">.<\/span>MouseButton<span class=\"token punctuation\">.<\/span>performed <span class=\"token operator\">&#043;&#061;<\/span> OnMouseButtonPerformed<span class=\"token punctuation\">;<\/span><br \/>\n        inputMap<span class=\"token punctuation\">.<\/span>Player<span class=\"token punctuation\">.<\/span>MouseButton<span class=\"token punctuation\">.<\/span>canceled <span class=\"token operator\">&#043;&#061;<\/span> OnMouseButtonCanceled<span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n    <span class=\"token keyword\">else<\/span> <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>inputDevice <span class=\"token keyword\">is<\/span> <span class=\"token class-name\">Mouse<\/span> mouse<span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token punctuation\">{<\/span><br \/>\n        inputMap<span class=\"token punctuation\">.<\/span>Player<span class=\"token punctuation\">.<\/span>MouseMove<span class=\"token punctuation\">.<\/span>performed <span class=\"token operator\">&#043;&#061;<\/span> OnMouseMove<span class=\"token punctuation\">;<\/span><br \/>\n        inputMap<span class=\"token punctuation\">.<\/span>Player<span class=\"token punctuation\">.<\/span>MouseScroll<span class=\"token punctuation\">.<\/span>performed <span class=\"token operator\">&#043;&#061;<\/span> OnMouseScroll<span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<h3>\u4ed3\u5e93\u5730\u5740<\/h3>\n<ul>\n<li>\u6846\u67b6\u4ed3\u5e93<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1k\u6b21\uff0c\u70b9\u8d5e12\u6b21\uff0c\u6536\u85cf29\u6b21\u3002\u533a\u522b\u4e8e\u65e7\u7684\u8f6e\u8be2\u5f0f\u7684`Input`\u7cfb\u7edf\uff0c\u57fa\u4e8e\u4e8b\u4ef6\u8ba2\u9605\uff0c\u4ec5\u5728\u8f93\u5165\u53d1\u751f\u65f6\u89e6\u53d1\u903b\u8f91\u7684\u8f93\u5165\u7cfb\u7edf_unity android inputdevice<\/p>\n","protected":false},"author":2,"featured_media":12824,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[183,735,736],"topic":[],"class_list":["post-12826","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-unity","tag-735","tag-736"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Unity\u8de8\u5e73\u53f0\u8f93\u5165\u7cfb\u7edf - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/12826.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Unity\u8de8\u5e73\u53f0\u8f93\u5165\u7cfb\u7edf - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1k\u6b21\uff0c\u70b9\u8d5e12\u6b21\uff0c\u6536\u85cf29\u6b21\u3002\u533a\u522b\u4e8e\u65e7\u7684\u8f6e\u8be2\u5f0f\u7684`Input`\u7cfb\u7edf\uff0c\u57fa\u4e8e\u4e8b\u4ef6\u8ba2\u9605\uff0c\u4ec5\u5728\u8f93\u5165\u53d1\u751f\u65f6\u89e6\u53d1\u903b\u8f91\u7684\u8f93\u5165\u7cfb\u7edf_unity android inputdevice\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/12826.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-04-18T11:55:42+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418115541-68023dbd4211a.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/12826.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/12826.html\",\"name\":\"Unity\u8de8\u5e73\u53f0\u8f93\u5165\u7cfb\u7edf - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-04-18T11:55:42+00:00\",\"dateModified\":\"2025-04-18T11:55:42+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/12826.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/12826.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/12826.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Unity\u8de8\u5e73\u53f0\u8f93\u5165\u7cfb\u7edf\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Unity\u8de8\u5e73\u53f0\u8f93\u5165\u7cfb\u7edf - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/12826.html","og_locale":"zh_CN","og_type":"article","og_title":"Unity\u8de8\u5e73\u53f0\u8f93\u5165\u7cfb\u7edf - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1k\u6b21\uff0c\u70b9\u8d5e12\u6b21\uff0c\u6536\u85cf29\u6b21\u3002\u533a\u522b\u4e8e\u65e7\u7684\u8f6e\u8be2\u5f0f\u7684`Input`\u7cfb\u7edf\uff0c\u57fa\u4e8e\u4e8b\u4ef6\u8ba2\u9605\uff0c\u4ec5\u5728\u8f93\u5165\u53d1\u751f\u65f6\u89e6\u53d1\u903b\u8f91\u7684\u8f93\u5165\u7cfb\u7edf_unity android inputdevice","og_url":"https:\/\/www.wsisp.com\/helps\/12826.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-04-18T11:55:42+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/04\/20250418115541-68023dbd4211a.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"2 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/12826.html","url":"https:\/\/www.wsisp.com\/helps\/12826.html","name":"Unity\u8de8\u5e73\u53f0\u8f93\u5165\u7cfb\u7edf - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-04-18T11:55:42+00:00","dateModified":"2025-04-18T11:55:42+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/12826.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/12826.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/12826.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Unity\u8de8\u5e73\u53f0\u8f93\u5165\u7cfb\u7edf"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/12826","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=12826"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/12826\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/12824"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=12826"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=12826"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=12826"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=12826"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}