1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- using LLM.Editor.Client;
- using UnityEditor;
- using UnityEngine;
- namespace LLM.Editor.Settings
- {
- /// <summary>
- /// Creates the "MCP Assistant" entry in Unity's Project Settings window,
- /// allowing for project-wide configuration of the LLM client.
- /// </summary>
- internal static class MCPSettingsProvider
- {
- private static SerializedObject _settings;
- [SettingsProvider]
- public static SettingsProvider CreateMCPSettingsProvider()
- {
- var provider = new SettingsProvider("Project/MCP Assistant", SettingsScope.Project)
- {
- label = "MCP Assistant",
- guiHandler = OnGUI,
- };
- return provider;
- }
- private static void OnGUI(string searchContext)
- {
- if (_settings == null)
- {
- var settingsAsset = FindSettingsAsset();
- if (settingsAsset != null)
- {
- _settings = new SerializedObject(settingsAsset);
- }
- }
- if (_settings == null)
- {
- EditorGUILayout.HelpBox("MCPSettings asset not found. Please create one via 'Assets > Create > LLM > MCP Settings'.", MessageType.Error);
- return;
- }
- _settings.Update();
- EditorGUILayout.LabelField("Client Configuration", EditorStyles.boldLabel);
- var useDummyClientProp = _settings.FindProperty("useDummyClient");
-
- EditorGUI.BeginChangeCheck();
- EditorGUILayout.PropertyField(useDummyClientProp, new GUIContent("Use Dummy Client", "Bypass the real LLM API and use a local, mock client for testing."));
- if (EditorGUI.EndChangeCheck())
- {
- // When the value changes, invalidate the cached client in the factory.
- ApiClientFactory.InvalidateClient();
- }
-
- EditorGUILayout.HelpBox("Toggling this will switch between the live Gemini API and a local dummy client for testing command execution.", MessageType.Info);
-
- EditorGUILayout.Space();
- EditorGUILayout.LabelField("Gemini API Configuration", EditorStyles.boldLabel);
- EditorGUILayout.PropertyField(_settings.FindProperty("gcpProjectId"));
- EditorGUILayout.PropertyField(_settings.FindProperty("gcpRegion"));
- EditorGUILayout.PropertyField(_settings.FindProperty("modelName"));
- EditorGUILayout.PropertyField(_settings.FindProperty("gcloudPath"));
- _settings.ApplyModifiedProperties();
- }
- private static MCPSettings FindSettingsAsset()
- {
- var guids = AssetDatabase.FindAssets($"t:{nameof(MCPSettings)}");
- if (guids.Length <= 0) return null;
- var path = AssetDatabase.GUIDToAssetPath(guids[0]);
- return AssetDatabase.LoadAssetAtPath<MCPSettings>(path);
- }
- }
- }
|