using System.IO; using UnityEditor; using UnityEngine; namespace LLM.Editor.Analysis { /// /// Provides the full text content of a C# script file. /// public class SourceCodeProvider : IContextProvider { public object GetContext(Object target, string qualifier) { string path = null; if (target is MonoScript script) { path = AssetDatabase.GetAssetPath(script); } else if (target != null) { path = AssetDatabase.GetAssetPath(target); } if (string.IsNullOrEmpty(path) || !path.EndsWith(".cs")) { return "Error: Target must be a MonoScript or a valid path to a C# file."; } if (!File.Exists(path)) { return $"Error: File not found at path '{path}'."; } return File.ReadAllText(path); } } }