@akiojin/unity-mcp-server 2.14.14
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/LICENSE +21 -0
- package/README.md +206 -0
- package/bin/unity-mcp-server +2 -0
- package/package.json +73 -0
- package/src/core/codeIndex.js +163 -0
- package/src/core/codeIndexDb.js +96 -0
- package/src/core/config.js +165 -0
- package/src/core/indexWatcher.js +52 -0
- package/src/core/projectInfo.js +111 -0
- package/src/core/server.js +294 -0
- package/src/core/unityConnection.js +426 -0
- package/src/handlers/analysis/AnalyzeSceneContentsToolHandler.js +35 -0
- package/src/handlers/analysis/FindByComponentToolHandler.js +20 -0
- package/src/handlers/analysis/GetAnimatorStateToolHandler.js +37 -0
- package/src/handlers/analysis/GetComponentValuesToolHandler.js +20 -0
- package/src/handlers/analysis/GetGameObjectDetailsToolHandler.js +35 -0
- package/src/handlers/analysis/GetInputActionsStateToolHandler.js +37 -0
- package/src/handlers/analysis/GetObjectReferencesToolHandler.js +20 -0
- package/src/handlers/asset/AssetDatabaseToolHandler.js +221 -0
- package/src/handlers/asset/AssetDependencyToolHandler.js +201 -0
- package/src/handlers/asset/AssetImportSettingsToolHandler.js +170 -0
- package/src/handlers/asset/CreateMaterialToolHandler.js +96 -0
- package/src/handlers/asset/CreatePrefabToolHandler.js +78 -0
- package/src/handlers/asset/ExitPrefabModeToolHandler.js +83 -0
- package/src/handlers/asset/InstantiatePrefabToolHandler.js +133 -0
- package/src/handlers/asset/ModifyMaterialToolHandler.js +76 -0
- package/src/handlers/asset/ModifyPrefabToolHandler.js +72 -0
- package/src/handlers/asset/OpenPrefabToolHandler.js +121 -0
- package/src/handlers/asset/SavePrefabToolHandler.js +106 -0
- package/src/handlers/base/BaseToolHandler.js +133 -0
- package/src/handlers/compilation/GetCompilationStateToolHandler.js +90 -0
- package/src/handlers/component/AddComponentToolHandler.js +126 -0
- package/src/handlers/component/GetComponentTypesToolHandler.js +100 -0
- package/src/handlers/component/ListComponentsToolHandler.js +85 -0
- package/src/handlers/component/ModifyComponentToolHandler.js +143 -0
- package/src/handlers/component/RemoveComponentToolHandler.js +108 -0
- package/src/handlers/console/ClearConsoleToolHandler.js +160 -0
- package/src/handlers/console/ReadConsoleToolHandler.js +276 -0
- package/src/handlers/editor/LayerManagementToolHandler.js +160 -0
- package/src/handlers/editor/SelectionToolHandler.js +141 -0
- package/src/handlers/editor/TagManagementToolHandler.js +129 -0
- package/src/handlers/editor/ToolManagementToolHandler.js +135 -0
- package/src/handlers/editor/WindowManagementToolHandler.js +125 -0
- package/src/handlers/gameobject/CreateGameObjectToolHandler.js +131 -0
- package/src/handlers/gameobject/DeleteGameObjectToolHandler.js +101 -0
- package/src/handlers/gameobject/FindGameObjectToolHandler.js +119 -0
- package/src/handlers/gameobject/GetHierarchyToolHandler.js +132 -0
- package/src/handlers/gameobject/ModifyGameObjectToolHandler.js +128 -0
- package/src/handlers/index.js +389 -0
- package/src/handlers/input/AddInputActionToolHandler.js +20 -0
- package/src/handlers/input/AddInputBindingToolHandler.js +20 -0
- package/src/handlers/input/CreateActionMapToolHandler.js +20 -0
- package/src/handlers/input/CreateCompositeBindingToolHandler.js +20 -0
- package/src/handlers/input/GamepadSimulationHandler.js +116 -0
- package/src/handlers/input/InputSystemHandler.js +80 -0
- package/src/handlers/input/KeyboardSimulationHandler.js +79 -0
- package/src/handlers/input/ManageControlSchemesToolHandler.js +20 -0
- package/src/handlers/input/MouseSimulationHandler.js +107 -0
- package/src/handlers/input/RemoveActionMapToolHandler.js +20 -0
- package/src/handlers/input/RemoveAllBindingsToolHandler.js +20 -0
- package/src/handlers/input/RemoveInputActionToolHandler.js +20 -0
- package/src/handlers/input/RemoveInputBindingToolHandler.js +20 -0
- package/src/handlers/input/TouchSimulationHandler.js +142 -0
- package/src/handlers/menu/ExecuteMenuItemToolHandler.js +304 -0
- package/src/handlers/package/PackageManagerToolHandler.js +248 -0
- package/src/handlers/package/RegistryConfigToolHandler.js +198 -0
- package/src/handlers/playmode/GetEditorStateToolHandler.js +81 -0
- package/src/handlers/playmode/PauseToolHandler.js +44 -0
- package/src/handlers/playmode/PlayToolHandler.js +91 -0
- package/src/handlers/playmode/StopToolHandler.js +77 -0
- package/src/handlers/playmode/WaitForEditorStateToolHandler.js +45 -0
- package/src/handlers/scene/CreateSceneToolHandler.js +91 -0
- package/src/handlers/scene/GetSceneInfoToolHandler.js +20 -0
- package/src/handlers/scene/ListScenesToolHandler.js +58 -0
- package/src/handlers/scene/LoadSceneToolHandler.js +92 -0
- package/src/handlers/scene/SaveSceneToolHandler.js +76 -0
- package/src/handlers/screenshot/AnalyzeScreenshotToolHandler.js +238 -0
- package/src/handlers/screenshot/CaptureScreenshotToolHandler.js +692 -0
- package/src/handlers/script/BuildCodeIndexToolHandler.js +163 -0
- package/src/handlers/script/ScriptCreateClassFileToolHandler.js +60 -0
- package/src/handlers/script/ScriptEditStructuredToolHandler.js +173 -0
- package/src/handlers/script/ScriptIndexStatusToolHandler.js +61 -0
- package/src/handlers/script/ScriptPackagesListToolHandler.js +103 -0
- package/src/handlers/script/ScriptReadToolHandler.js +106 -0
- package/src/handlers/script/ScriptRefactorRenameToolHandler.js +83 -0
- package/src/handlers/script/ScriptRefsFindToolHandler.js +144 -0
- package/src/handlers/script/ScriptRemoveSymbolToolHandler.js +79 -0
- package/src/handlers/script/ScriptSearchToolHandler.js +320 -0
- package/src/handlers/script/ScriptSymbolFindToolHandler.js +117 -0
- package/src/handlers/script/ScriptSymbolsGetToolHandler.js +96 -0
- package/src/handlers/settings/GetProjectSettingsToolHandler.js +161 -0
- package/src/handlers/settings/UpdateProjectSettingsToolHandler.js +272 -0
- package/src/handlers/system/GetCommandStatsToolHandler.js +25 -0
- package/src/handlers/system/PingToolHandler.js +53 -0
- package/src/handlers/system/RefreshAssetsToolHandler.js +45 -0
- package/src/handlers/ui/ClickUIElementToolHandler.js +110 -0
- package/src/handlers/ui/FindUIElementsToolHandler.js +63 -0
- package/src/handlers/ui/GetUIElementStateToolHandler.js +50 -0
- package/src/handlers/ui/SetUIElementValueToolHandler.js +49 -0
- package/src/handlers/ui/SimulateUIInputToolHandler.js +156 -0
- package/src/handlers/video/CaptureVideoForToolHandler.js +96 -0
- package/src/handlers/video/CaptureVideoStartToolHandler.js +38 -0
- package/src/handlers/video/CaptureVideoStatusToolHandler.js +30 -0
- package/src/handlers/video/CaptureVideoStopToolHandler.js +32 -0
- package/src/lsp/CSharpLspUtils.js +134 -0
- package/src/lsp/LspProcessManager.js +60 -0
- package/src/lsp/LspRpcClient.js +133 -0
- package/src/tools/analysis/analyzeSceneContents.js +100 -0
- package/src/tools/analysis/findByComponent.js +87 -0
- package/src/tools/analysis/getAnimatorState.js +326 -0
- package/src/tools/analysis/getComponentValues.js +182 -0
- package/src/tools/analysis/getGameObjectDetails.js +159 -0
- package/src/tools/analysis/getInputActionsState.js +329 -0
- package/src/tools/analysis/getObjectReferences.js +86 -0
- package/src/tools/input/inputActionsEditor.js +556 -0
- package/src/tools/scene/createScene.js +112 -0
- package/src/tools/scene/getSceneInfo.js +95 -0
- package/src/tools/scene/listScenes.js +82 -0
- package/src/tools/scene/loadScene.js +122 -0
- package/src/tools/scene/saveScene.js +91 -0
- package/src/tools/system/ping.js +72 -0
- package/src/tools/video/recordFor.js +31 -0
- package/src/tools/video/recordPlayMode.js +61 -0
- package/src/utils/csharpParse.js +88 -0
- package/src/utils/validators.js +90 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { BaseToolHandler } from '../base/BaseToolHandler.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Handles keyboard input simulation
|
|
5
|
+
*/
|
|
6
|
+
export class KeyboardSimulationHandler extends BaseToolHandler {
|
|
7
|
+
constructor(unityConnection) {
|
|
8
|
+
super(
|
|
9
|
+
'simulate_keyboard',
|
|
10
|
+
'Simulate keyboard input (press/release/type/combo) with typing speed.',
|
|
11
|
+
{
|
|
12
|
+
type: 'object',
|
|
13
|
+
properties: {
|
|
14
|
+
action: {
|
|
15
|
+
type: 'string',
|
|
16
|
+
enum: ['press', 'release', 'type', 'combo'],
|
|
17
|
+
description: 'The keyboard action to perform'
|
|
18
|
+
},
|
|
19
|
+
key: {
|
|
20
|
+
type: 'string',
|
|
21
|
+
description: 'The key to press/release (for press/release actions)'
|
|
22
|
+
},
|
|
23
|
+
keys: {
|
|
24
|
+
type: 'array',
|
|
25
|
+
items: { type: 'string' },
|
|
26
|
+
description: 'Array of keys for combo action'
|
|
27
|
+
},
|
|
28
|
+
text: {
|
|
29
|
+
type: 'string',
|
|
30
|
+
description: 'Text to type (for type action)'
|
|
31
|
+
},
|
|
32
|
+
typingSpeed: {
|
|
33
|
+
type: 'number',
|
|
34
|
+
|
|
35
|
+
description: 'Milliseconds per character when typing'
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
required: ['action']
|
|
39
|
+
}
|
|
40
|
+
);
|
|
41
|
+
this.unityConnection = unityConnection;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
validate(params) {
|
|
45
|
+
const { action, key, keys, text } = params;
|
|
46
|
+
|
|
47
|
+
if (!action) {
|
|
48
|
+
throw new Error('action is required');
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
switch (action) {
|
|
52
|
+
case 'press':
|
|
53
|
+
case 'release':
|
|
54
|
+
if (!key) {
|
|
55
|
+
throw new Error(`key is required for ${action} action`);
|
|
56
|
+
}
|
|
57
|
+
break;
|
|
58
|
+
case 'type':
|
|
59
|
+
if (!text) {
|
|
60
|
+
throw new Error('text is required for type action');
|
|
61
|
+
}
|
|
62
|
+
break;
|
|
63
|
+
case 'combo':
|
|
64
|
+
if (!keys || !Array.isArray(keys) || keys.length === 0) {
|
|
65
|
+
throw new Error('keys array is required for combo action');
|
|
66
|
+
}
|
|
67
|
+
break; }
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async execute(params) {
|
|
71
|
+
// Ensure connected
|
|
72
|
+
if (!this.unityConnection.isConnected()) {
|
|
73
|
+
await this.unityConnection.connect();
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const result = await this.unityConnection.sendCommand('simulate_keyboard_input', params);
|
|
77
|
+
return result;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { BaseToolHandler } from '../base/BaseToolHandler.js';
|
|
2
|
+
import {
|
|
3
|
+
manageControlSchemesToolDefinition,
|
|
4
|
+
manageControlSchemesHandler
|
|
5
|
+
} from '../../tools/input/inputActionsEditor.js';
|
|
6
|
+
|
|
7
|
+
export class ManageControlSchemesToolHandler extends BaseToolHandler {
|
|
8
|
+
constructor(unityConnection) {
|
|
9
|
+
super(
|
|
10
|
+
manageControlSchemesToolDefinition.name,
|
|
11
|
+
manageControlSchemesToolDefinition.description,
|
|
12
|
+
manageControlSchemesToolDefinition.inputSchema
|
|
13
|
+
);
|
|
14
|
+
this.unityConnection = unityConnection;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async execute(args) {
|
|
18
|
+
return manageControlSchemesHandler(this.unityConnection, args);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { BaseToolHandler } from '../base/BaseToolHandler.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Handles mouse input simulation
|
|
5
|
+
*/
|
|
6
|
+
export class MouseSimulationHandler extends BaseToolHandler {
|
|
7
|
+
constructor(unityConnection) {
|
|
8
|
+
super(
|
|
9
|
+
'simulate_mouse',
|
|
10
|
+
'Simulate mouse input (move/click/drag/scroll) with absolute/relative coords.',
|
|
11
|
+
{
|
|
12
|
+
type: 'object',
|
|
13
|
+
properties: {
|
|
14
|
+
action: {
|
|
15
|
+
type: 'string',
|
|
16
|
+
enum: ['move', 'click', 'drag', 'scroll'],
|
|
17
|
+
description: 'The mouse action to perform'
|
|
18
|
+
},
|
|
19
|
+
x: {
|
|
20
|
+
type: 'number',
|
|
21
|
+
description: 'X coordinate for move action'
|
|
22
|
+
},
|
|
23
|
+
y: {
|
|
24
|
+
type: 'number',
|
|
25
|
+
description: 'Y coordinate for move action'
|
|
26
|
+
},
|
|
27
|
+
absolute: {
|
|
28
|
+
type: 'boolean',
|
|
29
|
+
description: 'Whether coordinates are absolute or relative (default: true)'
|
|
30
|
+
},
|
|
31
|
+
button: {
|
|
32
|
+
type: 'string',
|
|
33
|
+
enum: ['left', 'right', 'middle'],
|
|
34
|
+
description: 'Mouse button for click/drag actions'
|
|
35
|
+
},
|
|
36
|
+
clickCount: {
|
|
37
|
+
type: 'number',
|
|
38
|
+
description: 'Number of clicks (for double/triple click)'
|
|
39
|
+
},
|
|
40
|
+
startX: {
|
|
41
|
+
type: 'number',
|
|
42
|
+
description: 'Start X for drag action'
|
|
43
|
+
},
|
|
44
|
+
startY: {
|
|
45
|
+
type: 'number',
|
|
46
|
+
description: 'Start Y for drag action'
|
|
47
|
+
},
|
|
48
|
+
endX: {
|
|
49
|
+
type: 'number',
|
|
50
|
+
description: 'End X for drag action'
|
|
51
|
+
},
|
|
52
|
+
endY: {
|
|
53
|
+
type: 'number',
|
|
54
|
+
description: 'End Y for drag action'
|
|
55
|
+
},
|
|
56
|
+
deltaX: {
|
|
57
|
+
type: 'number',
|
|
58
|
+
|
|
59
|
+
description: 'Horizontal scroll delta'
|
|
60
|
+
},
|
|
61
|
+
deltaY: {
|
|
62
|
+
type: 'number',
|
|
63
|
+
|
|
64
|
+
description: 'Vertical scroll delta'
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
required: ['action']
|
|
68
|
+
}
|
|
69
|
+
);
|
|
70
|
+
this.unityConnection = unityConnection;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
validate(params) {
|
|
74
|
+
const { action, x, y, startX, startY, endX, endY } = params;
|
|
75
|
+
|
|
76
|
+
if (!action) {
|
|
77
|
+
throw new Error('action is required');
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
switch (action) {
|
|
81
|
+
case 'move':
|
|
82
|
+
if (x === undefined || y === undefined) {
|
|
83
|
+
throw new Error('x and y coordinates are required for move action');
|
|
84
|
+
}
|
|
85
|
+
break;
|
|
86
|
+
case 'drag':
|
|
87
|
+
if (startX === undefined || startY === undefined ||
|
|
88
|
+
endX === undefined || endY === undefined) {
|
|
89
|
+
throw new Error('startX, startY, endX, and endY are required for drag action');
|
|
90
|
+
}
|
|
91
|
+
break;
|
|
92
|
+
case 'click':
|
|
93
|
+
case 'scroll':
|
|
94
|
+
// These actions have optional parameters
|
|
95
|
+
break; }
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
async execute(params) {
|
|
99
|
+
// Ensure connected
|
|
100
|
+
if (!this.unityConnection.isConnected()) {
|
|
101
|
+
await this.unityConnection.connect();
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const result = await this.unityConnection.sendCommand('simulate_mouse_input', params);
|
|
105
|
+
return result;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { BaseToolHandler } from '../base/BaseToolHandler.js';
|
|
2
|
+
import {
|
|
3
|
+
removeActionMapToolDefinition,
|
|
4
|
+
removeActionMapHandler
|
|
5
|
+
} from '../../tools/input/inputActionsEditor.js';
|
|
6
|
+
|
|
7
|
+
export class RemoveActionMapToolHandler extends BaseToolHandler {
|
|
8
|
+
constructor(unityConnection) {
|
|
9
|
+
super(
|
|
10
|
+
removeActionMapToolDefinition.name,
|
|
11
|
+
removeActionMapToolDefinition.description,
|
|
12
|
+
removeActionMapToolDefinition.inputSchema
|
|
13
|
+
);
|
|
14
|
+
this.unityConnection = unityConnection;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async execute(args) {
|
|
18
|
+
return removeActionMapHandler(this.unityConnection, args);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { BaseToolHandler } from '../base/BaseToolHandler.js';
|
|
2
|
+
import {
|
|
3
|
+
removeAllBindingsToolDefinition,
|
|
4
|
+
removeAllBindingsHandler
|
|
5
|
+
} from '../../tools/input/inputActionsEditor.js';
|
|
6
|
+
|
|
7
|
+
export class RemoveAllBindingsToolHandler extends BaseToolHandler {
|
|
8
|
+
constructor(unityConnection) {
|
|
9
|
+
super(
|
|
10
|
+
removeAllBindingsToolDefinition.name,
|
|
11
|
+
removeAllBindingsToolDefinition.description,
|
|
12
|
+
removeAllBindingsToolDefinition.inputSchema
|
|
13
|
+
);
|
|
14
|
+
this.unityConnection = unityConnection;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async execute(args) {
|
|
18
|
+
return removeAllBindingsHandler(this.unityConnection, args);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { BaseToolHandler } from '../base/BaseToolHandler.js';
|
|
2
|
+
import {
|
|
3
|
+
removeInputActionToolDefinition,
|
|
4
|
+
removeInputActionHandler
|
|
5
|
+
} from '../../tools/input/inputActionsEditor.js';
|
|
6
|
+
|
|
7
|
+
export class RemoveInputActionToolHandler extends BaseToolHandler {
|
|
8
|
+
constructor(unityConnection) {
|
|
9
|
+
super(
|
|
10
|
+
removeInputActionToolDefinition.name,
|
|
11
|
+
removeInputActionToolDefinition.description,
|
|
12
|
+
removeInputActionToolDefinition.inputSchema
|
|
13
|
+
);
|
|
14
|
+
this.unityConnection = unityConnection;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async execute(args) {
|
|
18
|
+
return removeInputActionHandler(this.unityConnection, args);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { BaseToolHandler } from '../base/BaseToolHandler.js';
|
|
2
|
+
import {
|
|
3
|
+
removeInputBindingToolDefinition,
|
|
4
|
+
removeInputBindingHandler
|
|
5
|
+
} from '../../tools/input/inputActionsEditor.js';
|
|
6
|
+
|
|
7
|
+
export class RemoveInputBindingToolHandler extends BaseToolHandler {
|
|
8
|
+
constructor(unityConnection) {
|
|
9
|
+
super(
|
|
10
|
+
removeInputBindingToolDefinition.name,
|
|
11
|
+
removeInputBindingToolDefinition.description,
|
|
12
|
+
removeInputBindingToolDefinition.inputSchema
|
|
13
|
+
);
|
|
14
|
+
this.unityConnection = unityConnection;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async execute(args) {
|
|
18
|
+
return removeInputBindingHandler(this.unityConnection, args);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { BaseToolHandler } from '../base/BaseToolHandler.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Handles touch input simulation
|
|
5
|
+
*/
|
|
6
|
+
export class TouchSimulationHandler extends BaseToolHandler {
|
|
7
|
+
constructor(unityConnection) {
|
|
8
|
+
super(
|
|
9
|
+
'simulate_touch',
|
|
10
|
+
'Simulate touch input (tap/swipe/pinch/multi) with coordinates and timing.',
|
|
11
|
+
{
|
|
12
|
+
type: 'object',
|
|
13
|
+
properties: {
|
|
14
|
+
action: {
|
|
15
|
+
type: 'string',
|
|
16
|
+
enum: ['tap', 'swipe', 'pinch', 'multi'],
|
|
17
|
+
description: 'The touch action to perform'
|
|
18
|
+
},
|
|
19
|
+
x: {
|
|
20
|
+
type: 'number',
|
|
21
|
+
description: 'X coordinate for tap action'
|
|
22
|
+
},
|
|
23
|
+
y: {
|
|
24
|
+
type: 'number',
|
|
25
|
+
description: 'Y coordinate for tap action'
|
|
26
|
+
},
|
|
27
|
+
touchId: {
|
|
28
|
+
type: 'number',
|
|
29
|
+
|
|
30
|
+
minimum: 0,
|
|
31
|
+
maximum: 9,
|
|
32
|
+
description: 'Touch ID (0-9)'
|
|
33
|
+
},
|
|
34
|
+
startX: {
|
|
35
|
+
type: 'number',
|
|
36
|
+
description: 'Start X for swipe action'
|
|
37
|
+
},
|
|
38
|
+
startY: {
|
|
39
|
+
type: 'number',
|
|
40
|
+
description: 'Start Y for swipe action'
|
|
41
|
+
},
|
|
42
|
+
endX: {
|
|
43
|
+
type: 'number',
|
|
44
|
+
description: 'End X for swipe action'
|
|
45
|
+
},
|
|
46
|
+
endY: {
|
|
47
|
+
type: 'number',
|
|
48
|
+
description: 'End Y for swipe action'
|
|
49
|
+
},
|
|
50
|
+
duration: {
|
|
51
|
+
type: 'number',
|
|
52
|
+
|
|
53
|
+
description: 'Swipe duration in milliseconds'
|
|
54
|
+
},
|
|
55
|
+
centerX: {
|
|
56
|
+
type: 'number',
|
|
57
|
+
description: 'Center X for pinch gesture'
|
|
58
|
+
},
|
|
59
|
+
centerY: {
|
|
60
|
+
type: 'number',
|
|
61
|
+
description: 'Center Y for pinch gesture'
|
|
62
|
+
},
|
|
63
|
+
startDistance: {
|
|
64
|
+
type: 'number',
|
|
65
|
+
|
|
66
|
+
description: 'Start distance between fingers for pinch'
|
|
67
|
+
},
|
|
68
|
+
endDistance: {
|
|
69
|
+
type: 'number',
|
|
70
|
+
|
|
71
|
+
description: 'End distance between fingers for pinch'
|
|
72
|
+
},
|
|
73
|
+
touches: {
|
|
74
|
+
type: 'array',
|
|
75
|
+
items: {
|
|
76
|
+
type: 'object',
|
|
77
|
+
properties: {
|
|
78
|
+
x: { type: 'number' },
|
|
79
|
+
y: { type: 'number' },
|
|
80
|
+
phase: {
|
|
81
|
+
type: 'string',
|
|
82
|
+
enum: ['began', 'moved', 'stationary', 'ended']
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
required: ['x', 'y']
|
|
86
|
+
},
|
|
87
|
+
description: 'Array of touch points for multi-touch'
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
required: ['action']
|
|
91
|
+
}
|
|
92
|
+
);
|
|
93
|
+
this.unityConnection = unityConnection;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
validate(params) {
|
|
97
|
+
const { action, x, y, startX, startY, endX, endY, touches } = params;
|
|
98
|
+
|
|
99
|
+
if (!action) {
|
|
100
|
+
throw new Error('action is required');
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
switch (action) {
|
|
104
|
+
case 'tap':
|
|
105
|
+
if (x === undefined || y === undefined) {
|
|
106
|
+
throw new Error('x and y coordinates are required for tap action');
|
|
107
|
+
}
|
|
108
|
+
break;
|
|
109
|
+
case 'swipe':
|
|
110
|
+
if (startX === undefined || startY === undefined ||
|
|
111
|
+
endX === undefined || endY === undefined) {
|
|
112
|
+
throw new Error('startX, startY, endX, and endY are required for swipe action');
|
|
113
|
+
}
|
|
114
|
+
break;
|
|
115
|
+
case 'pinch':
|
|
116
|
+
// Optional parameters with defaults
|
|
117
|
+
break;
|
|
118
|
+
case 'multi':
|
|
119
|
+
if (!touches || !Array.isArray(touches) || touches.length === 0) {
|
|
120
|
+
throw new Error('touches array is required for multi-touch action');
|
|
121
|
+
}
|
|
122
|
+
if (touches.length > 10) {
|
|
123
|
+
throw new Error('Maximum 10 simultaneous touches supported');
|
|
124
|
+
}
|
|
125
|
+
for (const touch of touches) {
|
|
126
|
+
if (touch.x === undefined || touch.y === undefined) {
|
|
127
|
+
throw new Error('Each touch must have x and y coordinates');
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
break; }
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
async execute(params) {
|
|
134
|
+
// Ensure connected
|
|
135
|
+
if (!this.unityConnection.isConnected()) {
|
|
136
|
+
await this.unityConnection.connect();
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const result = await this.unityConnection.sendCommand('simulate_touch_input', params);
|
|
140
|
+
return result;
|
|
141
|
+
}
|
|
142
|
+
}
|