missed import

main
Justin Barnett 2025-03-18 10:03:32 -04:00
parent b14fc27dc0
commit 931794cb01
1 changed files with 12 additions and 11 deletions

View File

@ -1,5 +1,6 @@
using UnityEngine; using UnityEngine;
using UnityEditor; using UnityEditor;
using System;
using System.IO; using System.IO;
using System.Text; using System.Text;
using System.Linq; using System.Linq;
@ -55,15 +56,15 @@ namespace MCPServer.Editor.Commands
// Ensure script name ends with .cs // Ensure script name ends with .cs
if (!scriptName.EndsWith(".cs")) if (!scriptName.EndsWith(".cs"))
scriptName += ".cs"; scriptName += ".cs";
string scriptPath; string scriptPath;
// If content is provided, use it directly // If content is provided, use it directly
if (!string.IsNullOrEmpty(content)) if (!string.IsNullOrEmpty(content))
{ {
// Use specified folder or default to Scripts // Use specified folder or default to Scripts
scriptPath = string.IsNullOrEmpty(scriptFolder) ? "Scripts" : scriptFolder; scriptPath = string.IsNullOrEmpty(scriptFolder) ? "Scripts" : scriptFolder;
// Ensure folder exists // Ensure folder exists
string folderPath = Path.Combine(Application.dataPath, scriptPath); string folderPath = Path.Combine(Application.dataPath, scriptPath);
if (!Directory.Exists(folderPath)) if (!Directory.Exists(folderPath))
@ -71,19 +72,19 @@ namespace MCPServer.Editor.Commands
Directory.CreateDirectory(folderPath); Directory.CreateDirectory(folderPath);
AssetDatabase.Refresh(); AssetDatabase.Refresh();
} }
// Create the script file with provided content // Create the script file with provided content
string fullPath = Path.Combine(Application.dataPath, scriptPath, scriptName); string fullPath = Path.Combine(Application.dataPath, scriptPath, scriptName);
File.WriteAllText(fullPath, content); File.WriteAllText(fullPath, content);
// Refresh the AssetDatabase // Refresh the AssetDatabase
AssetDatabase.Refresh(); AssetDatabase.Refresh();
return new { message = $"Created script: {Path.Combine(scriptPath, scriptName)}" }; return new { message = $"Created script: {Path.Combine(scriptPath, scriptName)}" };
} }
// Otherwise generate content based on template and parameters // Otherwise generate content based on template and parameters
// Ensure Scripts folder exists // Ensure Scripts folder exists
EnsureScriptsFolderExists(); EnsureScriptsFolderExists();
@ -109,7 +110,7 @@ namespace MCPServer.Editor.Commands
// Add using directives // Add using directives
contentBuilder.AppendLine("using UnityEngine;"); contentBuilder.AppendLine("using UnityEngine;");
contentBuilder.AppendLine(); contentBuilder.AppendLine();
// Add namespace if specified // Add namespace if specified
if (!string.IsNullOrEmpty(namespaceName)) if (!string.IsNullOrEmpty(namespaceName))
{ {
@ -188,7 +189,7 @@ namespace MCPServer.Editor.Commands
{ {
throw new System.Exception($"Directory does not exist: {Path.GetDirectoryName(scriptPath)}"); throw new System.Exception($"Directory does not exist: {Path.GetDirectoryName(scriptPath)}");
} }
// Create the file with content // Create the file with content
File.WriteAllText(fullPath, content); File.WriteAllText(fullPath, content);
AssetDatabase.Refresh(); AssetDatabase.Refresh();
@ -215,7 +216,7 @@ namespace MCPServer.Editor.Commands
public static object ListScripts(JObject @params) public static object ListScripts(JObject @params)
{ {
string folderPath = (string)@params["folder_path"] ?? "Assets"; string folderPath = (string)@params["folder_path"] ?? "Assets";
// Special handling for "Assets" path since it's already the root // Special handling for "Assets" path since it's already the root
string fullPath; string fullPath;
if (folderPath.Equals("Assets", StringComparison.OrdinalIgnoreCase)) if (folderPath.Equals("Assets", StringComparison.OrdinalIgnoreCase))