drgame-cc 1.0.45 → 1.0.46

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (121) hide show
  1. package/drres/focus/focus_1/gesture.atlas +34 -0
  2. package/drres/focus/focus_1/gesture.atlas.meta +6 -0
  3. package/drres/focus/focus_1/gesture.json +1 -0
  4. package/drres/focus/focus_1/gesture.json.meta +10 -0
  5. package/drres/focus/focus_1/gesture.png +0 -0
  6. package/drres/{icons/pointer-yellow-60.png.meta → focus/focus_1/gesture.png.meta} +14 -14
  7. package/drres/focus/focus_1.meta +13 -0
  8. package/drres/focus/focus_2/gesture.atlas +41 -0
  9. package/drres/focus/focus_2/gesture.atlas.meta +6 -0
  10. package/drres/focus/focus_2/gesture.json +1 -0
  11. package/drres/focus/focus_2/gesture.json.meta +10 -0
  12. package/drres/focus/focus_2/gesture.png +0 -0
  13. package/drres/{icons/pointer-blue-60.png.meta → focus/focus_2/gesture.png.meta} +13 -13
  14. package/drres/focus/focus_2.meta +13 -0
  15. package/drres/focus/focus_3/gesture.atlas +34 -0
  16. package/drres/focus/focus_3/gesture.atlas.meta +6 -0
  17. package/drres/focus/focus_3/gesture.json +1 -0
  18. package/drres/focus/focus_3/gesture.json.meta +10 -0
  19. package/drres/focus/focus_3/gesture.png +0 -0
  20. package/drres/{icons/pointer-pink-60.png.meta → focus/focus_3/gesture.png.meta} +12 -12
  21. package/drres/focus/focus_3.meta +13 -0
  22. package/drres/focus/focus_4/gesture.atlas +20 -0
  23. package/drres/focus/focus_4/gesture.atlas.meta +6 -0
  24. package/drres/focus/focus_4/gesture.json +1 -0
  25. package/drres/focus/focus_4/gesture.json.meta +10 -0
  26. package/drres/focus/focus_4/gesture.png +0 -0
  27. package/drres/focus/focus_4/gesture.png.meta +38 -0
  28. package/drres/focus/focus_4.meta +13 -0
  29. package/drres/focus.meta +13 -0
  30. package/drres/prefab/ExitWin.prefab +2 -2
  31. package/drres/prefab/Toast.prefab +378 -378
  32. package/drscript/{ad/AdManager.ts.meta → BtnExtra.ts.meta} +1 -1
  33. package/drscript/Define.ts +17 -2
  34. package/drscript/{ad/AdSlot.ts.meta → Define.ts.meta} +1 -1
  35. package/drscript/{ad/AggregateAdProvider.ts.meta → ExitWin.ts.meta} +1 -1
  36. package/drscript/GameAnalytics.ts +37 -118
  37. package/drscript/{ad/IAdProvider.ts.meta → GameAnalytics.ts.meta} +1 -1
  38. package/drscript/HelperWin.ts.meta +10 -0
  39. package/drscript/Info.ts.meta +10 -0
  40. package/drscript/InternalUitl.ts.meta +10 -0
  41. package/drscript/KeyAdapter.ts +133 -0
  42. package/drscript/KeyAdapter.ts.meta +10 -0
  43. package/drscript/Loader.ts.meta +10 -0
  44. package/drscript/PlatformAdapter.ts +178 -192
  45. package/drscript/PlatformAdapter.ts.meta +10 -0
  46. package/drscript/README.md +91 -805
  47. package/drscript/README.md.meta +6 -0
  48. package/drscript/UIAdapter.ts +324 -0
  49. package/drscript/UIAdapter.ts.meta +10 -0
  50. package/drscript/WebBridge.ts +1 -1
  51. package/drscript/WebBridge.ts.meta +10 -0
  52. package/drscript/ad-sdk/reporters/superset-lewo.js +6 -0
  53. package/drscript/ad-sdk/types/enums.d.ts +1 -0
  54. package/drscript/ad-sdk.meta +13 -0
  55. package/drscript/ad.meta +13 -0
  56. package/drscript/component/AlertTip.ts +25 -0
  57. package/drscript/component/AlertTip.ts.meta +10 -0
  58. package/drscript/component/BtnExtra.ts +17 -0
  59. package/drscript/component/BtnExtra.ts.meta +10 -0
  60. package/drscript/{ExitWin.ts → component/ExitWin.ts} +6 -8
  61. package/drscript/component/ExitWin.ts.meta +10 -0
  62. package/drscript/{HelperWin.ts → component/HelperWin.ts} +5 -19
  63. package/drscript/component/HelperWin.ts.meta +10 -0
  64. package/drscript/component.meta +13 -0
  65. package/drscript/config.meta +13 -0
  66. package/drscript/core.meta +13 -0
  67. package/drscript/focus/FocusItem.ts +1 -19
  68. package/drscript/focus/FocusManager.ts +132 -170
  69. package/drscript/focus/FocusVisualLayer.ts +74 -163
  70. package/drscript/focus.meta +13 -0
  71. package/drscript/input/KeyboardMove.ts +40 -11
  72. package/drscript/input/KeyboardMove.ts.meta +10 -0
  73. package/drscript/input.meta +13 -0
  74. package/drscript/interface.meta +13 -0
  75. package/drscript/pinyin.meta +13 -0
  76. package/drscript/toast.meta +13 -0
  77. package/drscript/virtualgamepad.meta +13 -0
  78. package/package.json +1 -1
  79. package/drres/config/default.json +0 -108
  80. package/drres/config/default.json.meta +0 -6
  81. package/drres/icons/pointer-blue-60.png +0 -0
  82. package/drres/icons/pointer-pink-60.png +0 -0
  83. package/drres/icons/pointer-white-60.png +0 -0
  84. package/drres/icons/pointer-yellow-60.png +0 -0
  85. package/drscript/Info.ts +0 -78
  86. package/drscript/InternalUitl.ts +0 -65
  87. package/drscript/ad/AdManager.ts +0 -174
  88. package/drscript/ad/AdSlot.ts +0 -44
  89. package/drscript/ad/AggregateAdProvider.ts +0 -149
  90. package/drscript/ad/IAdProvider.ts +0 -39
  91. package/drscript/ad/MockAdProvider.ts +0 -36
  92. package/drscript/ad/MockAdProvider.ts.meta +0 -10
  93. package/drscript/ad/SelfAdProvider.ts +0 -41
  94. package/drscript/ad/SelfAdProvider.ts.meta +0 -10
  95. package/drscript/config/TvUiConfig.ts +0 -155
  96. package/drscript/config/TvUiConfig.ts.meta +0 -10
  97. package/drscript/config/TvUiConfigManager.ts +0 -133
  98. package/drscript/config/TvUiConfigManager.ts.meta +0 -10
  99. package/drscript/core/BackManager.ts +0 -38
  100. package/drscript/core/BackManager.ts.meta +0 -10
  101. package/drscript/core/NativeBridge.ts +0 -137
  102. package/drscript/core/NativeBridge.ts.meta +0 -10
  103. package/drscript/core/TvUi.ts +0 -69
  104. package/drscript/core/TvUi.ts.meta +0 -10
  105. package/drscript/core/TvUiRoot.ts +0 -137
  106. package/drscript/core/TvUiRoot.ts.meta +0 -10
  107. package/drscript/icon/IconConfig.ts +0 -7
  108. package/drscript/icon/IconConfig.ts.meta +0 -10
  109. package/drscript/icon/IconManager.ts +0 -97
  110. package/drscript/icon/IconManager.ts.meta +0 -10
  111. package/drscript/input/KeyCodeAdapter.ts +0 -23
  112. package/drscript/input/RemoteInputManager.ts +0 -105
  113. package/drscript/interface/ILobbyBridge.ts +0 -5
  114. package/drscript/toast/ToastComponent.ts +0 -35
  115. package/drscript/toast/ToastComponent.ts.meta +0 -10
  116. package/drscript/toast/ToastManager.ts +0 -66
  117. package/drscript/toast/ToastManager.ts.meta +0 -10
  118. package/drscript/toast/TvExitConfirmDialog.ts +0 -334
  119. package/drscript/toast/TvExitConfirmDialog.ts.meta +0 -10
  120. package/drscript/toast/UIFunctions.ts +0 -150
  121. package/drscript/toast/UIFunctions.ts.meta +0 -10
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "ver": "1.1.0",
3
- "uuid": "6b1da664-0e06-4afe-bee8-14720c303a68",
3
+ "uuid": "cf51d4e3-02b9-4560-82d0-5cb61433e245",
4
4
  "importer": "typescript",
5
5
  "isPlugin": false,
6
6
  "loadPluginInWeb": true,
@@ -21,7 +21,22 @@ export enum EVideoScene {
21
21
  Boost = "boost"
22
22
  }
23
23
 
24
- export enum IconStyle {
24
+ export enum FingerStyle {
25
25
  Default = "default",
26
- White = "white"
26
+ White = "white",
27
+ Gold = "gold",
28
+ Blue = "blue"
29
+ }
30
+
31
+ export enum AnalyticsEvent {
32
+ GameLoading = "game_loading",
33
+ StartGameButton = "start_game_button",
34
+ WatchVideoContinueButton = "watch_video_continue_button",
35
+ ReplayButton = "replay_button",
36
+ RewardVideoAd = "reward_video_ad",
37
+ }
38
+
39
+ export enum AnalyticsAction {
40
+ Exposure = "exposure",
41
+ Click = "click",
27
42
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "ver": "1.1.0",
3
- "uuid": "4db774ef-5abf-4415-a468-dc2ef8fea47b",
3
+ "uuid": "d85d568d-95d5-41ba-8781-34962bc0197f",
4
4
  "importer": "typescript",
5
5
  "isPlugin": false,
6
6
  "loadPluginInWeb": true,
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "ver": "1.1.0",
3
- "uuid": "6bbf6f7e-4fe1-43e9-9de9-b3e5762628db",
3
+ "uuid": "624c44a1-c1da-408e-a890-edb9221fe19a",
4
4
  "importer": "typescript",
5
5
  "isPlugin": false,
6
6
  "loadPluginInWeb": true,
@@ -1,45 +1,17 @@
1
1
  import { ActionType, Reporter, IReportItem } from "./ad-sdk/ad-sdk";
2
+ import { AnalyticsEvent, AnalyticsAction } from "./Define";
2
3
 
3
- export enum GameAnalyticsPlatform {
4
- XiaomiTv = "xiaomi",
5
- Lewo = "lewo",
6
- }
7
-
8
- export enum AnalyticsEvent {
9
- GameLoading = "game_loading",
10
- StartGameButton = "start_game_button",
11
- WatchVideoContinueButton = "watch_video_continue_button",
12
- ReplayButton = "replay_button",
13
- RewardVideoAd = "reward_video_ad",
14
- }
15
-
16
- export enum AnalyticsAction {
17
- Exposure = "exposure",
18
- Click = "click",
19
- }
20
-
21
- export interface GameAnalyticsConfig {
22
- platform?: GameAnalyticsPlatform | string;
23
- app_item?: string;
24
- content_type?: string;
25
- content_id?: string;
26
- content_title?: string;
27
- user_id?: string;
28
- }
29
-
30
- interface AnalyticsEventDefinition {
31
- elementPosition: string;
32
- exposureEventName?: string;
33
- clickEventName?: string;
34
- }
4
+ const REPORT_URL = "https://sup.daoran.tv/bi-api/api/game/lewo/batch";
35
5
 
36
- const APP_ITEM_BY_PLATFORM: { [platform: string]: string } = {
37
- xiaomi: "25",
38
- lewo: "29",
6
+ /** 事件定义:element_position + 曝光/点击事件名 */
7
+ const EVENT_MAP: Record<AnalyticsEvent, { ep: string; expose: string; click?: string }> = {
8
+ [AnalyticsEvent.GameLoading]: { ep: "game_loading", expose: "game_loading_expose" },
9
+ [AnalyticsEvent.StartGameButton]: { ep: "start_game_button", expose: "start_game_expose", click: "start_game_click" },
10
+ [AnalyticsEvent.WatchVideoContinueButton]: { ep: "watch_video_continue_button", expose: "watch_video_continue_expose", click: "watch_video_continue_click" },
11
+ [AnalyticsEvent.ReplayButton]: { ep: "replay_button", expose: "replay_expose", click: "replay_click" },
12
+ [AnalyticsEvent.RewardVideoAd]: { ep: "reward_video_ad", expose: "ad_expose" },
39
13
  };
40
14
 
41
- const REPORT_URL = "https://sup.daoran.tv/bi-api/api/game/lewo/batch";
42
-
43
15
  export default class GameAnalytics {
44
16
  private static initialized: boolean = false;
45
17
  private static loadingReported: boolean = false;
@@ -48,49 +20,23 @@ export default class GameAnalytics {
48
20
  private static reportMaxSize: number = 50;
49
21
  private static reportKey = "game_analytics_report_cache";
50
22
 
51
- private static readonly definitions: { [event: string]: AnalyticsEventDefinition } = {
52
- game_loading: {
53
- elementPosition: "game_loading",
54
- exposureEventName: "game_loading_expose",
55
- },
56
- start_game_button: {
57
- elementPosition: "start_game_button",
58
- exposureEventName: "start_game_expose",
59
- clickEventName: "start_game_click",
60
- },
61
- watch_video_continue_button: {
62
- elementPosition: "watch_video_continue_button",
63
- exposureEventName: "watch_video_continue_expose",
64
- clickEventName: "watch_video_continue_click",
65
- },
66
- replay_button: {
67
- elementPosition: "replay_button",
68
- exposureEventName: "replay_expose",
69
- clickEventName: "replay_click",
70
- },
71
- reward_video_ad: {
72
- elementPosition: "reward_video_ad",
73
- exposureEventName: "ad_expose",
74
- },
75
- };
76
-
77
- public static init(config: GameAnalyticsConfig = {}): void {
78
- if (this.initialized) {
79
- if (config.user_id !== undefined) this.setUserId(config.user_id);
80
- return;
81
- }
23
+ public static init(config: {
24
+ app_item: string;
25
+ content_type?: string;
26
+ content_id?: string;
27
+ content_title?: string;
28
+ }): void {
29
+ if (GameAnalytics.initialized) return;
82
30
 
83
31
  try {
84
- const platform = config.platform || GameAnalyticsPlatform.XiaomiTv;
85
32
  Reporter.init({
86
33
  report_url: REPORT_URL,
87
- app_item: config.app_item || this.getAppItem(platform),
34
+ app_item: config.app_item,
88
35
  content_type: config.content_type || "游戏",
89
- content_id: config.content_id || "rexueqiangshou",
90
- content_title: config.content_title || "热血枪手",
36
+ content_id: config.content_id || "",
37
+ content_title: config.content_title || "",
91
38
  });
92
- this.initialized = true;
93
- if (config.user_id !== undefined) this.setUserId(config.user_id);
39
+ GameAnalytics.initialized = true;
94
40
  var httpReq = new XMLHttpRequest();
95
41
  httpReq.open("POST", 'https://sup.daoran.tv/bi-api/api/config/get');
96
42
  httpReq.setRequestHeader("Content-Type", "application/json");
@@ -109,15 +55,6 @@ export default class GameAnalytics {
109
55
  }
110
56
  }
111
57
 
112
- public static setUserId(userId: string): void {
113
- if (!this.initialized) return;
114
- try {
115
- Reporter.setCommonInfo({ user_id: userId || "" });
116
- } catch (error) {
117
- console.warn("[GameAnalytics] set user id failed", error);
118
- }
119
- }
120
-
121
58
  public static reportLoadingOnce(): void {
122
59
  if (this.loadingReported) return;
123
60
  this.loadingReported = true;
@@ -136,26 +73,23 @@ export default class GameAnalytics {
136
73
  adRequestId?: string
137
74
  ): void {
138
75
  if (!this.initialized) return;
139
-
140
- const definition = this.definitions[event];
141
- const eventName = definition && action === AnalyticsAction.Exposure
142
- ? definition.exposureEventName
143
- : definition && definition.clickEventName;
144
- if (!definition || !eventName) {
76
+ const def = EVENT_MAP[event];
77
+ const eventName = action === AnalyticsAction.Exposure ? def.expose : def.click;
78
+ if (!def || !eventName) {
145
79
  console.warn("[GameAnalytics] unsupported event/action", event, action);
146
80
  return;
147
81
  }
148
82
 
149
83
  try {
150
84
  const reportItem: any = {
151
- element_position: definition.elementPosition,
85
+ element_position: def.ep,
152
86
  action_type: action === AnalyticsAction.Exposure
153
87
  ? ActionType.Exposure
154
88
  : ActionType.Click,
155
89
  event_name: eventName,
156
90
  };
157
- if (event === AnalyticsEvent.RewardVideoAd) {
158
- reportItem.ad_request_id = adRequestId || "";
91
+ if (event === AnalyticsEvent.RewardVideoAd && adRequestId) {
92
+ reportItem.ad_request_id = adRequestId;
159
93
  }
160
94
  var reportCache: IReportItem[] = null;
161
95
  const cache = localStorage.getItem(this.reportKey);
@@ -173,25 +107,22 @@ export default class GameAnalytics {
173
107
  }
174
108
  }
175
109
 
176
- public static reportBatch(
177
- events: AnalyticsEvent[]
178
- ): void {
179
- if (!this.initialized) return;
180
-
110
+ public static reportBatch(events: AnalyticsEvent[]): void {
111
+ if (!this.initialized || events.length === 0) return;
181
112
  try {
182
- var reportArr: IReportItem[] = [];
113
+ const items: IReportItem[] = [];
183
114
  for (const e of events) {
184
- const definition = this.definitions[e];
185
- const eventName = definition.exposureEventName;
186
- const reportItem: any = {
187
- element_position: definition.elementPosition,
115
+ const def = EVENT_MAP[e];
116
+ if (!def) continue;
117
+ const item: any = {
118
+ element_position: def.ep,
188
119
  action_type: ActionType.Exposure,
189
- event_name: eventName,
120
+ event_name: def.expose,
121
+ ad_request_id: "",
190
122
  };
191
- reportItem.ad_request_id = "";
192
- reportArr.push(reportItem);
123
+ items.push(item);
193
124
  }
194
- Reporter.reportBatch(reportArr);
125
+ if (items.length > 0) Reporter.reportBatch(items);
195
126
  } catch (error) {
196
127
  console.warn("[GameAnalytics] report failed", error);
197
128
  }
@@ -199,7 +130,6 @@ export default class GameAnalytics {
199
130
 
200
131
  private static reportBatchCache(): void {
201
132
  if (!this.initialized) return;
202
-
203
133
  var reportCache: IReportItem[] = null;
204
134
  const cache = localStorage.getItem(this.reportKey);
205
135
  if (cache) {
@@ -217,15 +147,4 @@ export default class GameAnalytics {
217
147
  localStorage.setItem(this.reportKey, JSON.stringify(reportCache));
218
148
  }
219
149
  }
220
-
221
- static getAppItem(platform: string): string {
222
- const normalizedPlatform = (platform || "").toLowerCase();
223
- const appItem = APP_ITEM_BY_PLATFORM[normalizedPlatform];
224
- if (appItem) return appItem;
225
- console.warn(
226
- "[GameAnalytics] unknown platform, fallback to Xiaomi TV app_item=25",
227
- platform
228
- );
229
- return APP_ITEM_BY_PLATFORM[GameAnalyticsPlatform.XiaomiTv];
230
- }
231
150
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "ver": "1.1.0",
3
- "uuid": "fa1cfbaf-e828-42f9-b1d5-2b5664f0b48a",
3
+ "uuid": "d90d2ced-3868-4f9d-9356-cf6f9ced4f1e",
4
4
  "importer": "typescript",
5
5
  "isPlugin": false,
6
6
  "loadPluginInWeb": true,
@@ -0,0 +1,10 @@
1
+ {
2
+ "ver": "1.1.0",
3
+ "uuid": "7f86b204-659d-4805-afee-1c744576f395",
4
+ "importer": "typescript",
5
+ "isPlugin": false,
6
+ "loadPluginInWeb": true,
7
+ "loadPluginInNative": true,
8
+ "loadPluginInEditor": false,
9
+ "subMetas": {}
10
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "ver": "1.1.0",
3
+ "uuid": "f208d70d-2c4a-44ed-a43b-d5ebb0fd54c2",
4
+ "importer": "typescript",
5
+ "isPlugin": false,
6
+ "loadPluginInWeb": true,
7
+ "loadPluginInNative": true,
8
+ "loadPluginInEditor": false,
9
+ "subMetas": {}
10
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "ver": "1.1.0",
3
+ "uuid": "cb4b0aae-34e1-4cb6-84d9-15e19c4b8d33",
4
+ "importer": "typescript",
5
+ "isPlugin": false,
6
+ "loadPluginInWeb": true,
7
+ "loadPluginInNative": true,
8
+ "loadPluginInEditor": false,
9
+ "subMetas": {}
10
+ }
@@ -0,0 +1,133 @@
1
+ import { AdSdk, KeyCode, KeyAction } from "./ad-sdk/ad-sdk";
2
+ import FocusManager from "./focus/FocusManager";
3
+
4
+ /** 按键适配 - 统一处理遥控器、键盘、AdSdk 输入事件 */
5
+ export class KeyAdapter {
6
+ private static keyHandler: ((event: { key: KeyCode, action: KeyAction }) => void) | null = null;
7
+ private static keyboardBound: boolean = false;
8
+
9
+ /** 防重复:记录上次处理的按键,同一按键在 150ms 内忽略重复 */
10
+ private static lastKey: string = "";
11
+ private static lastAction: string = "";
12
+ private static lastTime: number = 0;
13
+ private static readonly DEDUP_MS = 150;
14
+
15
+ private static readonly KEYBOARD_MAP: { [keyCode: number]: KeyCode } = {
16
+ 0: KeyCode.Back,
17
+ 4: KeyCode.Back,
18
+ 6: KeyCode.Back,
19
+ 8: KeyCode.Back,
20
+ 13: KeyCode.Enter,
21
+ 19: KeyCode.Up,
22
+ 20: KeyCode.Down,
23
+ 21: KeyCode.Left,
24
+ 22: KeyCode.Right,
25
+ 23: KeyCode.Enter,
26
+ 27: KeyCode.Back,
27
+ 32: KeyCode.Enter,
28
+ 37: KeyCode.Left,
29
+ 38: KeyCode.Up,
30
+ 39: KeyCode.Right,
31
+ 40: KeyCode.Down,
32
+ 65: KeyCode.Left, // A
33
+ 66: KeyCode.Enter, // B
34
+ 68: KeyCode.Right, // D
35
+ 80: KeyCode.Enter, // P (Pause)
36
+ 83: KeyCode.Down, // S
37
+ 87: KeyCode.Up, // W
38
+ 1000: KeyCode.Left,
39
+ 1001: KeyCode.Right,
40
+ 1003: KeyCode.Up,
41
+ 1004: KeyCode.Down,
42
+ 1005: KeyCode.Enter,
43
+ 10009: KeyCode.Back,
44
+ };
45
+
46
+ /** 初始化输入监听 */
47
+ static init() {
48
+ if (KeyAdapter.keyHandler) return;
49
+ KeyAdapter.keyHandler = (event) => {
50
+ KeyAdapter.dispatchKey(event.key, event.action);
51
+ };
52
+ AdSdk.onKeyEvent(KeyAdapter.keyHandler);
53
+
54
+ cc.systemEvent.on(cc.SystemEvent.EventType.KEY_DOWN, KeyAdapter.onKeyboardDown, KeyAdapter);
55
+ cc.systemEvent.on(cc.SystemEvent.EventType.KEY_UP, KeyAdapter.onKeyboardUp, KeyAdapter);
56
+ KeyAdapter.keyboardBound = true;
57
+ }
58
+
59
+ /** 销毁输入监听 */
60
+ static destroy() {
61
+ if (KeyAdapter.keyHandler) {
62
+ AdSdk.offKeyEvent(KeyAdapter.keyHandler);
63
+ KeyAdapter.keyHandler = null;
64
+ }
65
+ if (KeyAdapter.keyboardBound) {
66
+ cc.systemEvent.off(cc.SystemEvent.EventType.KEY_DOWN, KeyAdapter.onKeyboardDown, KeyAdapter);
67
+ cc.systemEvent.off(cc.SystemEvent.EventType.KEY_UP, KeyAdapter.onKeyboardUp, KeyAdapter);
68
+ KeyAdapter.keyboardBound = false;
69
+ }
70
+ }
71
+
72
+ private static onKeyboardDown(event: cc.Event.EventKeyboard) {
73
+ const key = KeyAdapter.KEYBOARD_MAP[event.keyCode];
74
+ if (key) KeyAdapter.dispatchKey(key, KeyAction.Down);
75
+ }
76
+
77
+ private static onKeyboardUp(event: cc.Event.EventKeyboard) {
78
+ const key = KeyAdapter.KEYBOARD_MAP[event.keyCode];
79
+ if (key) KeyAdapter.dispatchKey(key, KeyAction.Up);
80
+ }
81
+
82
+ private static dispatchKey(key: KeyCode, action: KeyAction) {
83
+ // console.log(`[KeyAdapter] dispatchKey: ${key}, action: ${action}`);
84
+ // 防重复:同一按键+动作在 150ms 内重复触发则不处理
85
+ let now = Date.now();
86
+ if (key === KeyAdapter.lastKey && action === KeyAdapter.lastAction && now - KeyAdapter.lastTime < KeyAdapter.DEDUP_MS) {
87
+ console.log(`[KeyAdapter] ignore duplicate: ${key}, ${action}`);
88
+ return;
89
+ }
90
+ KeyAdapter.lastKey = key as string;
91
+ KeyAdapter.lastAction = action as string;
92
+ KeyAdapter.lastTime = now;
93
+ // 外部回调,优先执行,可用于拦截或扩展按键逻辑
94
+ if (action === KeyAction.Down) {
95
+ if (KeyAdapter.onKeyDown) KeyAdapter.onKeyDown(key);
96
+ } else {
97
+ if (KeyAdapter.onKeyUp) KeyAdapter.onKeyUp(key);
98
+ }
99
+
100
+ if (action !== KeyAction.Down) return;
101
+
102
+ switch (key) {
103
+ case KeyCode.Enter:
104
+ FocusManager.confirm();
105
+ break;
106
+ case KeyCode.Left:
107
+ FocusManager.move(KeyCode.Left);
108
+ break;
109
+ case KeyCode.Right:
110
+ FocusManager.move(KeyCode.Right);
111
+ break;
112
+ case KeyCode.Up:
113
+ FocusManager.move(KeyCode.Up);
114
+ break;
115
+ case KeyCode.Down:
116
+ FocusManager.move(KeyCode.Down);
117
+ break;
118
+ case KeyCode.Back:
119
+ // 返回键由 UIAdapter 处理,通过回调注入
120
+ if (KeyAdapter.onBack) KeyAdapter.onBack();
121
+ break;
122
+ }
123
+ }
124
+
125
+ /** 返回键回调(由 UIAdapter 注入) */
126
+ static onBack: (() => void) | null = null;
127
+
128
+ /** 按键按下回调,在默认处理逻辑前执行 */
129
+ static onKeyDown: ((key: KeyCode) => void) | null = null;
130
+
131
+ /** 按键抬起回调,在默认处理逻辑前执行 */
132
+ static onKeyUp: ((key: KeyCode) => void) | null = null;
133
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "ver": "1.1.0",
3
+ "uuid": "13f44f49-d4d7-4f6e-987f-c4775f11fe12",
4
+ "importer": "typescript",
5
+ "isPlugin": false,
6
+ "loadPluginInWeb": true,
7
+ "loadPluginInNative": true,
8
+ "loadPluginInEditor": false,
9
+ "subMetas": {}
10
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "ver": "1.1.0",
3
+ "uuid": "bd132b75-723a-41c6-93e5-d90414723a07",
4
+ "importer": "typescript",
5
+ "isPlugin": false,
6
+ "loadPluginInWeb": true,
7
+ "loadPluginInNative": true,
8
+ "loadPluginInEditor": false,
9
+ "subMetas": {}
10
+ }