using UnityEditor; using UnityEngine; namespace UnityMcpBridge.Editor.Helpers { /// /// Handles automatic installation of the Python server when the package is first installed. /// [InitializeOnLoad] public static class PackageInstaller { private const string InstallationFlagKey = "UnityMCP.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("UNITY-MCP: Installing Python server..."); ServerInstaller.EnsureServerInstalled(); // Mark as installed EditorPrefs.SetBool(InstallationFlagKey, true); Debug.Log("UNITY-MCP: Python server installation completed successfully."); } catch (System.Exception ex) { Debug.LogError($"UNITY-MCP: Failed to install Python server: {ex.Message}"); Debug.LogWarning("UNITY-MCP: You may need to manually install the Python server. Check the Unity MCP Editor Window for instructions."); } } } }