using UnityEditor; using UnityEngine; namespace MCPForUnity.Editor.Helpers { /// /// Handles automatic installation of the Python server when the package is first installed. /// [InitializeOnLoad] public static class PackageInstaller { private const string InstallationFlagKey = "MCPForUnity.ServerInstalled"; static PackageInstaller() { // Check if this is the first time the package is loaded if (!EditorPrefs.GetBool(InstallationFlagKey, false)) { // Schedule the installation for after Unity is fully loaded EditorApplication.delayCall += InstallServerOnFirstLoad; } } private static void InstallServerOnFirstLoad() { try { Debug.Log("MCP-FOR-UNITY: Installing Python server..."); ServerInstaller.EnsureServerInstalled(); // Mark as installed EditorPrefs.SetBool(InstallationFlagKey, true); Debug.Log("MCP-FOR-UNITY: Python server installation completed successfully."); } catch (System.Exception ex) { Debug.LogError($"MCP-FOR-UNITY: Failed to install Python server: {ex.Message}"); Debug.LogWarning("MCP-FOR-UNITY: You may need to manually install the Python server. Check the MCP for Unity Editor Window for instructions."); } } } }