@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,58 @@
|
|
|
1
|
+
import { BaseToolHandler } from '../base/BaseToolHandler.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Handler for listing scenes in Unity
|
|
5
|
+
*/
|
|
6
|
+
export class ListScenesToolHandler extends BaseToolHandler {
|
|
7
|
+
constructor(unityConnection) {
|
|
8
|
+
super(
|
|
9
|
+
'list_scenes',
|
|
10
|
+
'List scenes in project (filter to loaded/build scenes or by path).',
|
|
11
|
+
{
|
|
12
|
+
type: 'object',
|
|
13
|
+
properties: {
|
|
14
|
+
includeLoadedOnly: {
|
|
15
|
+
type: 'boolean',
|
|
16
|
+
description: 'Only include currently loaded scenes (default: false)'
|
|
17
|
+
},
|
|
18
|
+
includeBuildScenesOnly: {
|
|
19
|
+
type: 'boolean',
|
|
20
|
+
description: 'Only include scenes in build settings (default: false)'
|
|
21
|
+
},
|
|
22
|
+
includePath: {
|
|
23
|
+
type: 'string',
|
|
24
|
+
description: 'Filter scenes by path pattern (e.g., "Levels" to find scenes in Levels folder)'
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
required: []
|
|
28
|
+
}
|
|
29
|
+
);
|
|
30
|
+
this.unityConnection = unityConnection;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Executes the list scenes command
|
|
35
|
+
* @param {object} params - Validated input parameters
|
|
36
|
+
* @returns {Promise<object>} List result
|
|
37
|
+
*/
|
|
38
|
+
async execute(params) {
|
|
39
|
+
// Ensure connected
|
|
40
|
+
if (!this.unityConnection.isConnected()) {
|
|
41
|
+
throw new Error('Unity connection not available');
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Send command to Unity
|
|
45
|
+
const result = await this.unityConnection.sendCommand('list_scenes', params);
|
|
46
|
+
|
|
47
|
+
// The unityConnection.sendCommand already extracts the result field
|
|
48
|
+
// Check for Unity-side errors
|
|
49
|
+
if (result && result.error) {
|
|
50
|
+
const error = new Error(result.error);
|
|
51
|
+
error.code = 'UNITY_ERROR';
|
|
52
|
+
throw error;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Return the result directly since it's already unwrapped
|
|
56
|
+
return result;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { BaseToolHandler } from '../base/BaseToolHandler.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Handler for loading scenes in Unity
|
|
5
|
+
*/
|
|
6
|
+
export class LoadSceneToolHandler extends BaseToolHandler {
|
|
7
|
+
constructor(unityConnection) {
|
|
8
|
+
super(
|
|
9
|
+
'load_scene',
|
|
10
|
+
'Load a scene by path or name (Single/Additive).',
|
|
11
|
+
{
|
|
12
|
+
type: 'object',
|
|
13
|
+
properties: {
|
|
14
|
+
scenePath: {
|
|
15
|
+
type: 'string',
|
|
16
|
+
description: 'Full path to the scene file (e.g., "Assets/Scenes/MainMenu.unity")'
|
|
17
|
+
},
|
|
18
|
+
sceneName: {
|
|
19
|
+
type: 'string',
|
|
20
|
+
description: 'Name of the scene to load (must be in build settings). Use either scenePath or sceneName, not both.'
|
|
21
|
+
},
|
|
22
|
+
loadMode: {
|
|
23
|
+
type: 'string',
|
|
24
|
+
enum: ['Single', 'Additive'],
|
|
25
|
+
description: 'How to load the scene. Single replaces current scene(s), Additive adds to current scene(s) (default: Single)'
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
required: []
|
|
29
|
+
}
|
|
30
|
+
);
|
|
31
|
+
this.unityConnection = unityConnection;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Validates the input parameters
|
|
36
|
+
* @param {object} params - Input parameters
|
|
37
|
+
* @throws {Error} If validation fails
|
|
38
|
+
*/
|
|
39
|
+
validate(params) {
|
|
40
|
+
// Don't call super.validate() since we have no required fields
|
|
41
|
+
|
|
42
|
+
// Validate that either scenePath or sceneName is provided
|
|
43
|
+
if (!params.scenePath && !params.sceneName) {
|
|
44
|
+
throw new Error('Either scenePath or sceneName must be provided');
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Validate that only one is provided
|
|
48
|
+
if (params.scenePath && params.sceneName) {
|
|
49
|
+
throw new Error('Provide either scenePath or sceneName, not both');
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Validate load mode
|
|
53
|
+
if (params.loadMode && !['Single', 'Additive'].includes(params.loadMode)) {
|
|
54
|
+
throw new Error('Invalid load mode. Must be "Single" or "Additive"');
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Executes the load scene command
|
|
60
|
+
* @param {object} params - Validated input parameters
|
|
61
|
+
* @returns {Promise<object>} Load result
|
|
62
|
+
*/
|
|
63
|
+
async execute(params) {
|
|
64
|
+
// Ensure connected
|
|
65
|
+
if (!this.unityConnection.isConnected()) {
|
|
66
|
+
throw new Error('Unity connection not available');
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Send command to Unity
|
|
70
|
+
const result = await this.unityConnection.sendCommand('load_scene', params);
|
|
71
|
+
|
|
72
|
+
// Check for Unity-side errors
|
|
73
|
+
if (result.status === 'error') {
|
|
74
|
+
const error = new Error(result.error);
|
|
75
|
+
error.code = 'UNITY_ERROR';
|
|
76
|
+
throw error;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Handle undefined or null results from Unity
|
|
80
|
+
if (result.result === undefined || result.result === null) {
|
|
81
|
+
return {
|
|
82
|
+
status: 'success',
|
|
83
|
+
sceneName: params.sceneName || 'Unknown',
|
|
84
|
+
scenePath: params.scenePath || 'Unknown',
|
|
85
|
+
loadMode: params.loadMode || 'Single',
|
|
86
|
+
message: 'Scene operation completed but Unity returned no details'
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return result.result;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { BaseToolHandler } from '../base/BaseToolHandler.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Handler for saving scenes in Unity
|
|
5
|
+
*/
|
|
6
|
+
export class SaveSceneToolHandler extends BaseToolHandler {
|
|
7
|
+
constructor(unityConnection) {
|
|
8
|
+
super(
|
|
9
|
+
'save_scene',
|
|
10
|
+
'Save current scene or save as a specified path.',
|
|
11
|
+
{
|
|
12
|
+
type: 'object',
|
|
13
|
+
properties: {
|
|
14
|
+
scenePath: {
|
|
15
|
+
type: 'string',
|
|
16
|
+
description: 'Path where to save the scene. If not provided, saves to current scene path. Required if saveAs is true.'
|
|
17
|
+
},
|
|
18
|
+
saveAs: {
|
|
19
|
+
type: 'boolean',
|
|
20
|
+
description: 'Whether to save as a new scene (creates a copy). Default: false'
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
required: []
|
|
24
|
+
}
|
|
25
|
+
);
|
|
26
|
+
this.unityConnection = unityConnection;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Validates the input parameters
|
|
31
|
+
* @param {object} params - Input parameters
|
|
32
|
+
* @throws {Error} If validation fails
|
|
33
|
+
*/
|
|
34
|
+
validate(params) {
|
|
35
|
+
// Don't call super.validate() since we have no required fields
|
|
36
|
+
|
|
37
|
+
// Validate saveAs requires scenePath
|
|
38
|
+
if (params.saveAs && !params.scenePath) {
|
|
39
|
+
throw new Error('scenePath is required when saveAs is true');
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Executes the save scene command
|
|
45
|
+
* @param {object} params - Validated input parameters
|
|
46
|
+
* @returns {Promise<object>} Save result
|
|
47
|
+
*/
|
|
48
|
+
async execute(params) {
|
|
49
|
+
// Ensure connected
|
|
50
|
+
if (!this.unityConnection.isConnected()) {
|
|
51
|
+
throw new Error('Unity connection not available');
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Send command to Unity
|
|
55
|
+
const result = await this.unityConnection.sendCommand('save_scene', params);
|
|
56
|
+
|
|
57
|
+
// Check for Unity-side errors
|
|
58
|
+
if (result.status === 'error') {
|
|
59
|
+
const error = new Error(result.error);
|
|
60
|
+
error.code = 'UNITY_ERROR';
|
|
61
|
+
throw error;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Handle undefined or null results from Unity
|
|
65
|
+
if (result.result === undefined || result.result === null) {
|
|
66
|
+
return {
|
|
67
|
+
status: 'success',
|
|
68
|
+
scenePath: params.scenePath || 'Current scene path',
|
|
69
|
+
saveAs: params.saveAs === true,
|
|
70
|
+
message: 'Scene save completed but Unity returned no details'
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return result.result;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import { BaseToolHandler } from '../base/BaseToolHandler.js';
|
|
2
|
+
import fs from 'fs/promises';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Handler for analyzing screenshots from Unity Editor
|
|
7
|
+
*/
|
|
8
|
+
export class AnalyzeScreenshotToolHandler extends BaseToolHandler {
|
|
9
|
+
constructor(unityConnection) {
|
|
10
|
+
super(
|
|
11
|
+
'analyze_screenshot',
|
|
12
|
+
'Analyze a screenshot: dimensions/colors, UI elements, and scene content (basic/ui/content/full). For LLMs, prefer basic/ui; use full only when necessary. Provide either imagePath (preferred) or base64 (not both).',
|
|
13
|
+
{
|
|
14
|
+
type: 'object',
|
|
15
|
+
properties: {
|
|
16
|
+
imagePath: {
|
|
17
|
+
type: 'string',
|
|
18
|
+
description: 'Path to the screenshot file to analyze (must be within Assets folder)'
|
|
19
|
+
},
|
|
20
|
+
base64Data: {
|
|
21
|
+
type: 'string',
|
|
22
|
+
description: 'Base64 encoded image data (alternative to imagePath)'
|
|
23
|
+
},
|
|
24
|
+
analysisType: {
|
|
25
|
+
type: 'string',
|
|
26
|
+
enum: ['basic', 'ui', 'content', 'full'],
|
|
27
|
+
|
|
28
|
+
description: 'Type of analysis: basic (colors, dimensions), ui (UI element detection), content (scene content), full (all)'
|
|
29
|
+
},
|
|
30
|
+
prompt: {
|
|
31
|
+
type: 'string',
|
|
32
|
+
description: 'Optional prompt for AI-based analysis (e.g., "Find all buttons in the UI")'
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
required: []
|
|
36
|
+
}
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
this.unityConnection = unityConnection;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Validates the input parameters
|
|
44
|
+
* @param {Object} params - The input parameters
|
|
45
|
+
* @throws {Error} If validation fails
|
|
46
|
+
*/
|
|
47
|
+
validate(params) {
|
|
48
|
+
const { imagePath, base64Data, analysisType = 'basic' } = params;
|
|
49
|
+
|
|
50
|
+
// Must provide either imagePath or base64Data
|
|
51
|
+
if (!imagePath && !base64Data) {
|
|
52
|
+
throw new Error('Either imagePath or base64Data must be provided');
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Cannot provide both
|
|
56
|
+
if (imagePath && base64Data) {
|
|
57
|
+
throw new Error('Provide either imagePath or base64Data, not both');
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Validate image path if provided
|
|
61
|
+
if (imagePath) {
|
|
62
|
+
if (!imagePath.startsWith('Assets/')) {
|
|
63
|
+
throw new Error('imagePath must be within the Assets folder');
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const ext = path.extname(imagePath).toLowerCase();
|
|
67
|
+
if (!['.png', '.jpg', '.jpeg'].includes(ext)) {
|
|
68
|
+
throw new Error('imagePath must be a PNG or JPEG file');
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Validate analysis type
|
|
73
|
+
if (!['basic', 'ui', 'content', 'full'].includes(analysisType)) {
|
|
74
|
+
throw new Error('analysisType must be one of: basic, ui, content, full');
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Executes the screenshot analysis
|
|
80
|
+
* @param {Object} params - The validated input parameters
|
|
81
|
+
* @returns {Promise<Object>} The analysis result
|
|
82
|
+
*/
|
|
83
|
+
async execute(params) {
|
|
84
|
+
const { imagePath, base64Data, analysisType = 'basic', prompt } = params;
|
|
85
|
+
|
|
86
|
+
// If we have base64 data, we can do some analysis locally
|
|
87
|
+
if (base64Data) {
|
|
88
|
+
return this.analyzeBase64Image(base64Data, analysisType, prompt);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Otherwise, send to Unity for analysis
|
|
92
|
+
if (!this.unityConnection.isConnected()) {
|
|
93
|
+
await this.unityConnection.connect();
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const response = await this.unityConnection.sendCommand('analyze_screenshot', {
|
|
97
|
+
imagePath,
|
|
98
|
+
analysisType
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
if (response.error) {
|
|
102
|
+
throw new Error(response.error);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Build comprehensive result
|
|
106
|
+
const result = {
|
|
107
|
+
imagePath: response.imagePath,
|
|
108
|
+
width: response.width,
|
|
109
|
+
height: response.height,
|
|
110
|
+
format: response.format,
|
|
111
|
+
fileSize: response.fileSize,
|
|
112
|
+
analysisType: response.analysisType,
|
|
113
|
+
message: response.message || 'Screenshot analyzed successfully'
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
// Add analysis results based on type
|
|
117
|
+
if (response.dominantColors) {
|
|
118
|
+
result.dominantColors = response.dominantColors;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (response.uiElements) {
|
|
122
|
+
result.uiElements = response.uiElements;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// If prompt was provided, add AI analysis placeholder
|
|
126
|
+
if (prompt) {
|
|
127
|
+
result.aiAnalysis = {
|
|
128
|
+
prompt: prompt,
|
|
129
|
+
note: 'AI analysis requires integration with vision model. This is a placeholder for future implementation.'
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return result;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Analyzes a base64 encoded image
|
|
138
|
+
* @param {string} base64Data - The base64 encoded image
|
|
139
|
+
* @param {string} analysisType - The type of analysis to perform
|
|
140
|
+
* @param {string} prompt - Optional AI prompt
|
|
141
|
+
* @returns {Object} Analysis results
|
|
142
|
+
*/
|
|
143
|
+
analyzeBase64Image(base64Data, analysisType, prompt) {
|
|
144
|
+
// Decode base64 to get image size
|
|
145
|
+
const buffer = Buffer.from(base64Data, 'base64');
|
|
146
|
+
const fileSize = buffer.length;
|
|
147
|
+
|
|
148
|
+
// Basic analysis result
|
|
149
|
+
const result = {
|
|
150
|
+
source: 'base64',
|
|
151
|
+
fileSize: fileSize,
|
|
152
|
+
analysisType: analysisType,
|
|
153
|
+
message: 'Base64 image analysis completed'
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
// Add placeholder for different analysis types
|
|
157
|
+
switch (analysisType) {
|
|
158
|
+
case 'basic':
|
|
159
|
+
result.analysis = {
|
|
160
|
+
note: 'Basic analysis of base64 images requires image processing library integration',
|
|
161
|
+
fileSize: fileSize,
|
|
162
|
+
estimatedFormat: fileSize > 100000 ? 'Likely PNG or high-quality JPEG' : 'Likely compressed JPEG'
|
|
163
|
+
};
|
|
164
|
+
break;
|
|
165
|
+
|
|
166
|
+
case 'ui':
|
|
167
|
+
result.uiAnalysis = {
|
|
168
|
+
note: 'UI element detection requires computer vision integration',
|
|
169
|
+
placeholder: 'This would detect buttons, text fields, panels, etc.'
|
|
170
|
+
};
|
|
171
|
+
break;
|
|
172
|
+
|
|
173
|
+
case 'content':
|
|
174
|
+
result.contentAnalysis = {
|
|
175
|
+
note: 'Content analysis requires scene understanding models',
|
|
176
|
+
placeholder: 'This would identify GameObjects, lighting, materials, etc.'
|
|
177
|
+
};
|
|
178
|
+
break;
|
|
179
|
+
|
|
180
|
+
case 'full':
|
|
181
|
+
result.fullAnalysis = {
|
|
182
|
+
basic: { note: 'Requires image processing library' },
|
|
183
|
+
ui: { note: 'Requires computer vision' },
|
|
184
|
+
content: { note: 'Requires scene understanding' }
|
|
185
|
+
};
|
|
186
|
+
break;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// Add AI analysis placeholder if prompt provided
|
|
190
|
+
if (prompt) {
|
|
191
|
+
result.aiAnalysis = {
|
|
192
|
+
prompt: prompt,
|
|
193
|
+
note: 'To enable AI analysis, integrate with a vision model API (e.g., GPT-4V, Claude 3 Vision)',
|
|
194
|
+
suggestion: 'You can use the base64Data with a vision API to analyze: ' + prompt
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
return result;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Gets example usage for this tool
|
|
203
|
+
* @returns {Object} Example usage scenarios
|
|
204
|
+
*/
|
|
205
|
+
getExamples() {
|
|
206
|
+
return {
|
|
207
|
+
analyzeScreenshot: {
|
|
208
|
+
description: 'Analyze a screenshot file',
|
|
209
|
+
params: {
|
|
210
|
+
imagePath: 'Assets/Screenshots/game_view.png',
|
|
211
|
+
analysisType: 'basic'
|
|
212
|
+
}
|
|
213
|
+
},
|
|
214
|
+
analyzeUIElements: {
|
|
215
|
+
description: 'Detect UI elements in screenshot',
|
|
216
|
+
params: {
|
|
217
|
+
imagePath: 'Assets/Screenshots/ui_capture.png',
|
|
218
|
+
analysisType: 'ui'
|
|
219
|
+
}
|
|
220
|
+
},
|
|
221
|
+
analyzeWithPrompt: {
|
|
222
|
+
description: 'AI-guided analysis with prompt',
|
|
223
|
+
params: {
|
|
224
|
+
imagePath: 'Assets/Screenshots/scene.png',
|
|
225
|
+
analysisType: 'full',
|
|
226
|
+
prompt: 'Identify all interactive elements and describe the scene lighting'
|
|
227
|
+
}
|
|
228
|
+
},
|
|
229
|
+
analyzeBase64: {
|
|
230
|
+
description: 'Analyze base64 encoded image',
|
|
231
|
+
params: {
|
|
232
|
+
base64Data: 'iVBORw0KGgoAAAANS...',
|
|
233
|
+
analysisType: 'basic'
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
}
|