@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,141 @@
|
|
|
1
|
+
import { BaseToolHandler } from '../base/BaseToolHandler.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Handles Unity Editor selection operations
|
|
5
|
+
*/
|
|
6
|
+
export class SelectionToolHandler extends BaseToolHandler {
|
|
7
|
+
constructor(unityConnection) {
|
|
8
|
+
super(
|
|
9
|
+
'manage_selection',
|
|
10
|
+
'Manage editor selection: get/set/clear and optionally include details.',
|
|
11
|
+
{
|
|
12
|
+
type: 'object',
|
|
13
|
+
properties: {
|
|
14
|
+
action: {
|
|
15
|
+
type: 'string',
|
|
16
|
+
enum: ['get', 'set', 'clear', 'get_details'],
|
|
17
|
+
description: 'Operation: get, set, clear, or get_details.'
|
|
18
|
+
},
|
|
19
|
+
objectPaths: {
|
|
20
|
+
type: 'array',
|
|
21
|
+
items: {
|
|
22
|
+
type: 'string'
|
|
23
|
+
},
|
|
24
|
+
description: 'GameObject paths for set (e.g., ["/Main Camera", "/Player"]). Must start with /.'
|
|
25
|
+
},
|
|
26
|
+
includeDetails: {
|
|
27
|
+
type: 'boolean',
|
|
28
|
+
description: 'If true, return detailed info with get/get_details.'
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
required: ['action']
|
|
32
|
+
}
|
|
33
|
+
);
|
|
34
|
+
this.unityConnection = unityConnection;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Validate the parameters for the selection operation
|
|
39
|
+
*/
|
|
40
|
+
validate(params) {
|
|
41
|
+
const { action, objectPaths, includeDetails } = params;
|
|
42
|
+
|
|
43
|
+
// Check action is provided
|
|
44
|
+
if (!action) {
|
|
45
|
+
throw new Error('action is required');
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Validate action is one of the allowed values
|
|
49
|
+
const allowedActions = ['get', 'set', 'clear', 'get_details'];
|
|
50
|
+
if (!allowedActions.includes(action)) {
|
|
51
|
+
throw new Error(`action must be one of: ${allowedActions.join(', ')}`);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Validate based on action
|
|
55
|
+
if (action === 'set') {
|
|
56
|
+
if (!objectPaths) {
|
|
57
|
+
throw new Error('objectPaths is required for set action');
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (!Array.isArray(objectPaths)) {
|
|
61
|
+
throw new Error('objectPaths must be an array');
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (objectPaths.length === 0) {
|
|
65
|
+
throw new Error('objectPaths cannot be empty');
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Validate each path
|
|
69
|
+
for (const path of objectPaths) {
|
|
70
|
+
if (typeof path !== 'string') {
|
|
71
|
+
throw new Error('All object paths must be strings');
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (!path.startsWith('/')) {
|
|
75
|
+
throw new Error('All object paths must start with /');
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Call parent validation last
|
|
81
|
+
super.validate(params);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Execute the selection command
|
|
86
|
+
*/
|
|
87
|
+
async execute(params) {
|
|
88
|
+
// Ensure connected
|
|
89
|
+
if (!this.unityConnection.isConnected()) {
|
|
90
|
+
await this.unityConnection.connect();
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const result = await this.unityConnection.sendCommand('manage_selection', params);
|
|
94
|
+
|
|
95
|
+
if (result.error) {
|
|
96
|
+
throw new Error(result.error);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return result;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Get examples of how to use this tool
|
|
104
|
+
*/
|
|
105
|
+
getExamples() {
|
|
106
|
+
return {
|
|
107
|
+
getSelection: {
|
|
108
|
+
description: 'Get current selection',
|
|
109
|
+
params: {
|
|
110
|
+
action: 'get'
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
getSelectionWithDetails: {
|
|
114
|
+
description: 'Get current selection with detailed info',
|
|
115
|
+
params: {
|
|
116
|
+
action: 'get',
|
|
117
|
+
includeDetails: true
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
setSelection: {
|
|
121
|
+
description: 'Set selection to specific objects',
|
|
122
|
+
params: {
|
|
123
|
+
action: 'set',
|
|
124
|
+
objectPaths: ['/Main Camera', '/Directional Light']
|
|
125
|
+
}
|
|
126
|
+
},
|
|
127
|
+
clearSelection: {
|
|
128
|
+
description: 'Clear current selection',
|
|
129
|
+
params: {
|
|
130
|
+
action: 'clear'
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
getSelectionDetails: {
|
|
134
|
+
description: 'Get detailed information about selection',
|
|
135
|
+
params: {
|
|
136
|
+
action: 'get_details'
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { BaseToolHandler } from '../base/BaseToolHandler.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Handler for Unity tag management operations
|
|
5
|
+
*/
|
|
6
|
+
export class TagManagementToolHandler extends BaseToolHandler {
|
|
7
|
+
constructor(unityConnection) {
|
|
8
|
+
super(
|
|
9
|
+
'manage_tags',
|
|
10
|
+
'Manage project tags: add/remove/list with validation for reserved names.',
|
|
11
|
+
{
|
|
12
|
+
type: 'object',
|
|
13
|
+
properties: {
|
|
14
|
+
action: {
|
|
15
|
+
type: 'string',
|
|
16
|
+
enum: ['add', 'remove', 'get'],
|
|
17
|
+
description: 'Operation: add, remove, or get.'
|
|
18
|
+
},
|
|
19
|
+
tagName: {
|
|
20
|
+
type: 'string',
|
|
21
|
+
description: 'Tag name (required for add/remove). Alphanumeric/underscore only.'
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
required: ['action']
|
|
25
|
+
}
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
this.unityConnection = unityConnection;
|
|
29
|
+
|
|
30
|
+
// Reserved Unity tags that cannot be removed
|
|
31
|
+
this.RESERVED_TAGS = ['Untagged', 'Respawn', 'Finish', 'EditorOnly', 'MainCamera', 'Player', 'GameController'];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Validates the input parameters
|
|
36
|
+
* @param {Object} params - The input parameters
|
|
37
|
+
*/
|
|
38
|
+
validate(params) {
|
|
39
|
+
const { action, tagName } = params;
|
|
40
|
+
|
|
41
|
+
// Check if action is provided
|
|
42
|
+
if (!action) {
|
|
43
|
+
throw new Error('action is required');
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Check if action is valid
|
|
47
|
+
if (!['add', 'remove', 'get'].includes(action)) {
|
|
48
|
+
throw new Error('action must be one of: add, remove, get');
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// For add and remove actions, tagName is required
|
|
52
|
+
if (action === 'add' || action === 'remove') {
|
|
53
|
+
if (tagName === undefined || tagName === null) {
|
|
54
|
+
throw new Error(`tagName is required for ${action} action`);
|
|
55
|
+
}
|
|
56
|
+
if (typeof tagName === 'string' && tagName.trim() === '') {
|
|
57
|
+
throw new Error('tagName cannot be empty');
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Validate tag name if provided
|
|
62
|
+
if (tagName !== undefined && tagName !== '') {
|
|
63
|
+
|
|
64
|
+
// Check for invalid characters (Unity tag names should be alphanumeric with no spaces or special characters)
|
|
65
|
+
if (!/^[a-zA-Z0-9_]+$/.test(tagName)) {
|
|
66
|
+
throw new Error('tagName contains invalid characters. Only letters, numbers, and underscores are allowed');
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Check for reserved tag names when adding
|
|
70
|
+
if (action === 'add' && this.RESERVED_TAGS.includes(tagName)) {
|
|
71
|
+
throw new Error(`tagName is reserved`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Call parent validation last to avoid conflicts
|
|
76
|
+
super.validate(params);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Executes the tag management operation
|
|
81
|
+
* @param {Object} params - The validated input parameters
|
|
82
|
+
* @returns {Promise<Object>} The result of the tag operation
|
|
83
|
+
*/
|
|
84
|
+
async execute(params) {
|
|
85
|
+
// Ensure connection to Unity
|
|
86
|
+
if (!this.unityConnection.isConnected()) {
|
|
87
|
+
await this.unityConnection.connect();
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Send command to Unity
|
|
91
|
+
const response = await this.unityConnection.sendCommand('manage_tags', params);
|
|
92
|
+
|
|
93
|
+
// Handle Unity response
|
|
94
|
+
if (response.error) {
|
|
95
|
+
throw new Error(response.error);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return response;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Gets example usage for this tool
|
|
103
|
+
* @returns {Object} Example usage scenarios
|
|
104
|
+
*/
|
|
105
|
+
getExamples() {
|
|
106
|
+
return {
|
|
107
|
+
getTags: {
|
|
108
|
+
description: 'Get all available tags in the project',
|
|
109
|
+
params: {
|
|
110
|
+
action: 'get'
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
addTag: {
|
|
114
|
+
description: 'Add a new tag to the project',
|
|
115
|
+
params: {
|
|
116
|
+
action: 'add',
|
|
117
|
+
tagName: 'Enemy'
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
removeTag: {
|
|
121
|
+
description: 'Remove an existing tag from the project',
|
|
122
|
+
params: {
|
|
123
|
+
action: 'remove',
|
|
124
|
+
tagName: 'OldTag'
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { BaseToolHandler } from '../base/BaseToolHandler.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Handler for Unity Editor tool and plugin management operations
|
|
5
|
+
*/
|
|
6
|
+
export class ToolManagementToolHandler extends BaseToolHandler {
|
|
7
|
+
constructor(unityConnection) {
|
|
8
|
+
super(
|
|
9
|
+
'manage_tools',
|
|
10
|
+
'Manage editor tools/plugins: list, activate/deactivate, refresh cache.',
|
|
11
|
+
{
|
|
12
|
+
type: 'object',
|
|
13
|
+
properties: {
|
|
14
|
+
action: {
|
|
15
|
+
type: 'string',
|
|
16
|
+
enum: ['get', 'activate', 'deactivate', 'refresh'],
|
|
17
|
+
description: 'Operation: get, activate, deactivate, or refresh.'
|
|
18
|
+
},
|
|
19
|
+
toolName: {
|
|
20
|
+
type: 'string',
|
|
21
|
+
description: 'Tool name (required for activate/deactivate).'
|
|
22
|
+
},
|
|
23
|
+
category: {
|
|
24
|
+
type: 'string',
|
|
25
|
+
description: 'Optional: filter list by category.'
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
required: ['action']
|
|
29
|
+
}
|
|
30
|
+
);
|
|
31
|
+
this.unityConnection = unityConnection;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
validate(params) {
|
|
35
|
+
if (!params.action) {
|
|
36
|
+
throw new Error('action is required');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const validActions = ['get', 'activate', 'deactivate', 'refresh'];
|
|
40
|
+
if (!validActions.includes(params.action)) {
|
|
41
|
+
throw new Error(`action must be one of: ${validActions.join(', ')}`);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Validate toolName for activate/deactivate actions
|
|
45
|
+
if (params.action === 'activate' || params.action === 'deactivate') {
|
|
46
|
+
if (params.toolName === undefined || params.toolName === null) {
|
|
47
|
+
throw new Error(`toolName is required for ${params.action} action`);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (params.toolName === '') {
|
|
51
|
+
throw new Error('toolName cannot be empty');
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Validate category if provided
|
|
56
|
+
if (params.category !== undefined && params.category !== null && params.category === '') {
|
|
57
|
+
throw new Error('category cannot be empty');
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async execute(params) {
|
|
62
|
+
this.validate(params);
|
|
63
|
+
|
|
64
|
+
if (!this.unityConnection.isConnected()) {
|
|
65
|
+
await this.unityConnection.connect();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const result = await this.unityConnection.sendCommand('manage_tools', params);
|
|
69
|
+
return result;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
getExamples() {
|
|
73
|
+
return [
|
|
74
|
+
{
|
|
75
|
+
input: { action: 'get' },
|
|
76
|
+
output: {
|
|
77
|
+
success: true,
|
|
78
|
+
action: 'get',
|
|
79
|
+
tools: [
|
|
80
|
+
{
|
|
81
|
+
name: 'ProBuilder',
|
|
82
|
+
displayName: 'ProBuilder',
|
|
83
|
+
version: '5.1.0',
|
|
84
|
+
category: 'Modeling',
|
|
85
|
+
isInstalled: true,
|
|
86
|
+
isActive: true
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
name: 'Cinemachine',
|
|
90
|
+
displayName: 'Cinemachine',
|
|
91
|
+
version: '2.9.0',
|
|
92
|
+
category: 'Camera',
|
|
93
|
+
isInstalled: true,
|
|
94
|
+
isActive: false
|
|
95
|
+
}
|
|
96
|
+
],
|
|
97
|
+
installedCount: 2,
|
|
98
|
+
activeCount: 1
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
input: { action: 'activate', toolName: 'Cinemachine' },
|
|
103
|
+
output: {
|
|
104
|
+
success: true,
|
|
105
|
+
action: 'activate',
|
|
106
|
+
toolName: 'Cinemachine',
|
|
107
|
+
previousState: { isActive: false },
|
|
108
|
+
currentState: { isActive: true },
|
|
109
|
+
message: 'Tool activated: Cinemachine'
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
input: { action: 'deactivate', toolName: 'ProBuilder' },
|
|
114
|
+
output: {
|
|
115
|
+
success: true,
|
|
116
|
+
action: 'deactivate',
|
|
117
|
+
toolName: 'ProBuilder',
|
|
118
|
+
previousState: { isActive: true },
|
|
119
|
+
currentState: { isActive: false },
|
|
120
|
+
message: 'Tool deactivated: ProBuilder'
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
input: { action: 'refresh' },
|
|
125
|
+
output: {
|
|
126
|
+
success: true,
|
|
127
|
+
action: 'refresh',
|
|
128
|
+
message: 'Tool cache refreshed',
|
|
129
|
+
toolsCount: 15,
|
|
130
|
+
timestamp: '2024-01-01T12:00:00.000Z'
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
];
|
|
134
|
+
}
|
|
135
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { BaseToolHandler } from '../base/BaseToolHandler.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Handles Unity Editor window management operations
|
|
5
|
+
*/
|
|
6
|
+
export class WindowManagementToolHandler extends BaseToolHandler {
|
|
7
|
+
constructor(unityConnection) {
|
|
8
|
+
super(
|
|
9
|
+
'manage_windows',
|
|
10
|
+
'Manage editor windows: list/focus/get_state including hidden windows.',
|
|
11
|
+
{
|
|
12
|
+
type: 'object',
|
|
13
|
+
properties: {
|
|
14
|
+
action: {
|
|
15
|
+
type: 'string',
|
|
16
|
+
enum: ['get', 'focus', 'get_state'],
|
|
17
|
+
description: 'Operation: get (list), focus, or get_state.'
|
|
18
|
+
},
|
|
19
|
+
windowType: {
|
|
20
|
+
type: 'string',
|
|
21
|
+
description: 'Window type (e.g., SceneView, GameView, InspectorWindow). Required for focus/get_state.'
|
|
22
|
+
},
|
|
23
|
+
includeHidden: {
|
|
24
|
+
type: 'boolean',
|
|
25
|
+
description: 'If true, includes hidden/minimized windows for get.'
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
required: ['action']
|
|
29
|
+
}
|
|
30
|
+
);
|
|
31
|
+
this.unityConnection = unityConnection;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Validate the parameters for the window management operation
|
|
36
|
+
*/
|
|
37
|
+
validate(params) {
|
|
38
|
+
const { action, windowType } = params;
|
|
39
|
+
|
|
40
|
+
// Check action is provided
|
|
41
|
+
if (!action) {
|
|
42
|
+
throw new Error('action is required');
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Validate action is one of the allowed values
|
|
46
|
+
const allowedActions = ['get', 'focus', 'get_state'];
|
|
47
|
+
if (!allowedActions.includes(action)) {
|
|
48
|
+
throw new Error(`action must be one of: ${allowedActions.join(', ')}`);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Validate based on action
|
|
52
|
+
if (action === 'focus' || action === 'get_state') {
|
|
53
|
+
if (windowType === undefined || windowType === null) {
|
|
54
|
+
throw new Error(`windowType is required for ${action} action`);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (windowType === '') {
|
|
58
|
+
throw new Error('windowType cannot be empty');
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Call parent validation last
|
|
63
|
+
super.validate(params);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Execute the window management command
|
|
68
|
+
*/
|
|
69
|
+
async execute(params) {
|
|
70
|
+
// Ensure connected
|
|
71
|
+
if (!this.unityConnection.isConnected()) {
|
|
72
|
+
await this.unityConnection.connect();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const result = await this.unityConnection.sendCommand('manage_windows', params);
|
|
76
|
+
|
|
77
|
+
if (result.error) {
|
|
78
|
+
throw new Error(result.error);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return result;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Get examples of how to use this tool
|
|
86
|
+
*/
|
|
87
|
+
getExamples() {
|
|
88
|
+
return {
|
|
89
|
+
getAllWindows: {
|
|
90
|
+
description: 'Get all open editor windows',
|
|
91
|
+
params: {
|
|
92
|
+
action: 'get'
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
getAllWindowsIncludingHidden: {
|
|
96
|
+
description: 'Get all windows including hidden ones',
|
|
97
|
+
params: {
|
|
98
|
+
action: 'get',
|
|
99
|
+
includeHidden: true
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
focusSceneView: {
|
|
103
|
+
description: 'Focus the Scene view window',
|
|
104
|
+
params: {
|
|
105
|
+
action: 'focus',
|
|
106
|
+
windowType: 'SceneView'
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
focusGameView: {
|
|
110
|
+
description: 'Focus the Game view window',
|
|
111
|
+
params: {
|
|
112
|
+
action: 'focus',
|
|
113
|
+
windowType: 'GameView'
|
|
114
|
+
}
|
|
115
|
+
},
|
|
116
|
+
getWindowState: {
|
|
117
|
+
description: 'Get detailed state of a specific window',
|
|
118
|
+
params: {
|
|
119
|
+
action: 'get_state',
|
|
120
|
+
windowType: 'InspectorWindow'
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { BaseToolHandler } from '../base/BaseToolHandler.js';
|
|
2
|
+
import { validateVector3, validateLayer } from '../../utils/validators.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Handler for the create_gameobject tool
|
|
6
|
+
* Creates GameObjects in Unity scene
|
|
7
|
+
*/
|
|
8
|
+
export class CreateGameObjectToolHandler extends BaseToolHandler {
|
|
9
|
+
constructor(unityConnection) {
|
|
10
|
+
super(
|
|
11
|
+
'create_gameobject',
|
|
12
|
+
'Create a GameObject in Unity scene',
|
|
13
|
+
{
|
|
14
|
+
type: 'object',
|
|
15
|
+
properties: {
|
|
16
|
+
name: {
|
|
17
|
+
type: 'string',
|
|
18
|
+
description: 'Name of the GameObject (default: "GameObject")'
|
|
19
|
+
},
|
|
20
|
+
primitiveType: {
|
|
21
|
+
type: 'string',
|
|
22
|
+
description: 'Type of primitive to create',
|
|
23
|
+
enum: ['cube', 'sphere', 'cylinder', 'capsule', 'plane', 'quad']
|
|
24
|
+
},
|
|
25
|
+
position: {
|
|
26
|
+
type: 'object',
|
|
27
|
+
description: 'World position',
|
|
28
|
+
properties: {
|
|
29
|
+
x: { type: 'number' },
|
|
30
|
+
y: { type: 'number' },
|
|
31
|
+
z: { type: 'number' }
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
rotation: {
|
|
35
|
+
type: 'object',
|
|
36
|
+
description: 'Rotation in Euler angles',
|
|
37
|
+
properties: {
|
|
38
|
+
x: { type: 'number' },
|
|
39
|
+
y: { type: 'number' },
|
|
40
|
+
z: { type: 'number' }
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
scale: {
|
|
44
|
+
type: 'object',
|
|
45
|
+
description: 'Local scale',
|
|
46
|
+
properties: {
|
|
47
|
+
x: { type: 'number' },
|
|
48
|
+
y: { type: 'number' },
|
|
49
|
+
z: { type: 'number' }
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
parentPath: {
|
|
53
|
+
type: 'string',
|
|
54
|
+
description: 'Path to parent GameObject (e.g., "/Parent/Child")'
|
|
55
|
+
},
|
|
56
|
+
tag: {
|
|
57
|
+
type: 'string',
|
|
58
|
+
description: 'Tag to assign to the GameObject'
|
|
59
|
+
},
|
|
60
|
+
layer: {
|
|
61
|
+
type: 'number',
|
|
62
|
+
description: 'Layer index (0-31)',
|
|
63
|
+
minimum: 0,
|
|
64
|
+
maximum: 31
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
required: []
|
|
68
|
+
}
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
this.unityConnection = unityConnection;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Validates the input parameters
|
|
76
|
+
* @param {object} params - Input parameters
|
|
77
|
+
* @throws {Error} If validation fails
|
|
78
|
+
*/
|
|
79
|
+
validate(params) {
|
|
80
|
+
super.validate(params);
|
|
81
|
+
|
|
82
|
+
// Validate primitive type if provided
|
|
83
|
+
if (params.primitiveType) {
|
|
84
|
+
const validTypes = ['cube', 'sphere', 'cylinder', 'capsule', 'plane', 'quad'];
|
|
85
|
+
if (!validTypes.includes(params.primitiveType.toLowerCase())) {
|
|
86
|
+
throw new Error(`primitiveType must be one of: ${validTypes.join(', ')}`);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Validate vector3 properties
|
|
91
|
+
if (params.position) validateVector3(params.position, 'position');
|
|
92
|
+
if (params.rotation) validateVector3(params.rotation, 'rotation');
|
|
93
|
+
if (params.scale) validateVector3(params.scale, 'scale');
|
|
94
|
+
|
|
95
|
+
// Validate layer
|
|
96
|
+
if (params.layer !== undefined) {
|
|
97
|
+
validateLayer(Number(params.layer));
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Executes the create_gameobject command
|
|
103
|
+
* @param {object} params - Input parameters
|
|
104
|
+
* @returns {Promise<object>} Created GameObject info
|
|
105
|
+
*/
|
|
106
|
+
async execute(params) {
|
|
107
|
+
console.error('[CreateGameObject] Starting execution with params:', params);
|
|
108
|
+
|
|
109
|
+
// Ensure connected
|
|
110
|
+
if (!this.unityConnection.isConnected()) {
|
|
111
|
+
console.error('[CreateGameObject] Not connected to Unity, attempting to connect...');
|
|
112
|
+
await this.unityConnection.connect();
|
|
113
|
+
console.error('[CreateGameObject] Connected to Unity');
|
|
114
|
+
} else {
|
|
115
|
+
console.error('[CreateGameObject] Already connected to Unity');
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Send create_gameobject command
|
|
119
|
+
console.error('[CreateGameObject] Sending command to Unity...');
|
|
120
|
+
const result = await this.unityConnection.sendCommand('create_gameobject', params);
|
|
121
|
+
console.error('[CreateGameObject] Received result from Unity:', result);
|
|
122
|
+
|
|
123
|
+
// Check for errors from Unity
|
|
124
|
+
if (result.error) {
|
|
125
|
+
console.error('[CreateGameObject] Unity returned error:', result.error);
|
|
126
|
+
throw new Error(result.error);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return result;
|
|
130
|
+
}
|
|
131
|
+
}
|