Skip to content

Commit 673bc1b

Browse files
committed
Add PackageInstaller for automatic Python server installation on first package load
1 parent 5c4ea29 commit 673bc1b

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using UnityEditor;
2+
using UnityEngine;
3+
4+
namespace UnityMcpBridge.Editor.Helpers
5+
{
6+
/// <summary>
7+
/// Handles automatic installation of the Python server when the package is first installed.
8+
/// </summary>
9+
[InitializeOnLoad]
10+
public static class PackageInstaller
11+
{
12+
private const string InstallationFlagKey = "UnityMCP.ServerInstalled";
13+
14+
static PackageInstaller()
15+
{
16+
// Check if this is the first time the package is loaded
17+
if (!EditorPrefs.GetBool(InstallationFlagKey, false))
18+
{
19+
// Schedule the installation for after Unity is fully loaded
20+
EditorApplication.delayCall += InstallServerOnFirstLoad;
21+
}
22+
}
23+
24+
private static void InstallServerOnFirstLoad()
25+
{
26+
try
27+
{
28+
Debug.Log("Unity MCP: Installing Python server...");
29+
ServerInstaller.EnsureServerInstalled();
30+
31+
// Mark as installed
32+
EditorPrefs.SetBool(InstallationFlagKey, true);
33+
34+
Debug.Log("Unity MCP: Python server installation completed successfully.");
35+
}
36+
catch (System.Exception ex)
37+
{
38+
Debug.LogError($"Unity MCP: Failed to install Python server: {ex.Message}");
39+
Debug.LogWarning("Unity MCP: You may need to manually install the Python server. Check the Unity MCP Editor Window for instructions.");
40+
}
41+
}
42+
}
43+
}

0 commit comments

Comments
 (0)