drgame-cc 1.0.52 → 1.0.54
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.
- package/drscript/KeyAdapter.ts +11 -0
- package/drscript/PlatformAdapter.ts +2 -2
- package/drscript/README.md +1 -7
- package/drscript/virtualgamepad/VirtualGamepad.ts +638 -0
- package/drscript/virtualgamepad/VirtualGamepadView.ts +311 -280
- package/package.json +1 -1
- package/drscript/virtualgamepad/VirtualGamepadClient.ts +0 -214
- package/drscript/virtualgamepad/VirtualGamepadConfig.ts +0 -70
- package/drscript/virtualgamepad/VirtualGamepadManager.ts +0 -809
package/drscript/KeyAdapter.ts
CHANGED
|
@@ -6,6 +6,14 @@ export class KeyAdapter {
|
|
|
6
6
|
private static keyHandler: ((event: { key: KeyCode, action: KeyAction }) => void) | null = null;
|
|
7
7
|
private static keyboardBound: boolean = false;
|
|
8
8
|
|
|
9
|
+
/** 虚拟手柄模式:激活时忽略键盘/遥控器/AdSdk 输入 */
|
|
10
|
+
private static _virtualGamepadActive: boolean = false;
|
|
11
|
+
|
|
12
|
+
/** 设置虚拟手柄模式,连接时自动禁用键盘/遥控器输入 */
|
|
13
|
+
public static setVirtualGamepadMode(active: boolean) {
|
|
14
|
+
KeyAdapter._virtualGamepadActive = active;
|
|
15
|
+
}
|
|
16
|
+
|
|
9
17
|
/** 防重复:记录上次处理的按键,同一按键在 150ms 内忽略重复 */
|
|
10
18
|
private static lastKey: string = "";
|
|
11
19
|
private static lastAction: string = "";
|
|
@@ -70,16 +78,19 @@ export class KeyAdapter {
|
|
|
70
78
|
}
|
|
71
79
|
|
|
72
80
|
private static onKeyboardDown(event: cc.Event.EventKeyboard) {
|
|
81
|
+
if (KeyAdapter._virtualGamepadActive) return;
|
|
73
82
|
const key = KeyAdapter.KEYBOARD_MAP[event.keyCode];
|
|
74
83
|
if (key) KeyAdapter.dispatchKey(key, KeyAction.Down);
|
|
75
84
|
}
|
|
76
85
|
|
|
77
86
|
private static onKeyboardUp(event: cc.Event.EventKeyboard) {
|
|
87
|
+
if (KeyAdapter._virtualGamepadActive) return;
|
|
78
88
|
const key = KeyAdapter.KEYBOARD_MAP[event.keyCode];
|
|
79
89
|
if (key) KeyAdapter.dispatchKey(key, KeyAction.Up);
|
|
80
90
|
}
|
|
81
91
|
|
|
82
92
|
private static dispatchKey(key: KeyCode, action: KeyAction) {
|
|
93
|
+
if (KeyAdapter._virtualGamepadActive) return;
|
|
83
94
|
// console.log(`[KeyAdapter] dispatchKey: ${key}, action: ${action}`);
|
|
84
95
|
// 防重复:同一按键+动作在 150ms 内重复触发则不处理
|
|
85
96
|
let now = Date.now();
|
|
@@ -74,11 +74,11 @@ export class PlatformAdapter {
|
|
|
74
74
|
/** 是否 Cocos 环境 */
|
|
75
75
|
private static get isCocos() { return window['cc'] != undefined; }
|
|
76
76
|
/** 是否基座环境 */
|
|
77
|
-
|
|
77
|
+
public static get isWebBridge() { return this.webBridge.isAvailable(); }
|
|
78
78
|
/** 是否可以观看视频 */
|
|
79
79
|
private static get canWatchVideo() { return this.isXiaomi; }
|
|
80
80
|
/** 是否小米平台 */
|
|
81
|
-
|
|
81
|
+
public static get isXiaomi() {
|
|
82
82
|
if (typeof window === 'undefined') return null;
|
|
83
83
|
return window['AppBridge'] || null;
|
|
84
84
|
}
|
package/drscript/README.md
CHANGED
|
@@ -58,13 +58,7 @@ PlatformAdapter.showHelperWin('skeleton', () => {
|
|
|
58
58
|
PlatformAdapter.report(AnalyticsEvent.StartGame, AnalyticsAction.Click);
|
|
59
59
|
// 批量上报
|
|
60
60
|
PlatformAdapter.reportBatch([AnalyticsEvent.StartGame, AnalyticsEvent.LevelComplete]);
|
|
61
|
-
|
|
62
|
-
### 1.8 属性
|
|
63
|
-
```typescript
|
|
64
|
-
PlatformAdapter.isCocos // 是否 Cocos 环境
|
|
65
|
-
PlatformAdapter.isWebBridge // 是否基座环境
|
|
66
|
-
PlatformAdapter.canWatchVideo // 是否可以观看视频(小米 TV)
|
|
67
|
-
PlatformAdapter.isVIP // 是否 VIP 用户
|
|
61
|
+
|
|
68
62
|
```
|
|
69
63
|
## 二、KeyAdapter 按键适配
|
|
70
64
|
### 2.1 外部回调
|