1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- using UnityEditor;
- using System.Collections.Generic;
- using Object = UnityEngine.Object;
- namespace LLM.Editor.Analysis
- {
- /// <summary>
- /// Provides context about the currently selected objects in the Unity Editor.
- /// Distinguishes between objects in the scene and assets in the project.
- /// </summary>
- public class SelectionProvider : IContextProvider
- {
- public class SelectionResult
- {
- public string name;
- public string id;
- public string type;
- public bool isSceneObject;
- public string assetPath;
- }
- public object GetContext(Object target, string qualifier)
- {
- var selectedObjects = Selection.objects;
- if (selectedObjects == null || selectedObjects.Length == 0)
- {
- return "No objects are currently selected in the editor.";
- }
- var results = new List<SelectionResult>();
- foreach (var obj in selectedObjects)
- {
- var result = new SelectionResult
- {
- name = obj.name,
- type = obj.GetType().FullName
- };
- if (AssetDatabase.Contains(obj))
- {
- // It's an asset in the Project window
- result.isSceneObject = false;
- var path = AssetDatabase.GetAssetPath(obj);
- result.assetPath = path;
- result.id = AssetDatabase.AssetPathToGUID(path);
- }
- else
- {
- // It's a GameObject or component in the Scene
- result.isSceneObject = true;
- result.assetPath = null;
- result.id = obj.GetInstanceID().ToString();
- }
- results.Add(result);
- }
- return results;
- }
- }
- }
|