using System;
using System.IO;
using UnityEditor;
using UnityEngine;
using System.Linq;
using UnityEditor.UIElements;
using UnityEngine.UIElements;
using System.Collections.Generic;
using Object = UnityEngine.Object;
namespace IntelligentProjectAnalyzer.Editor.DependencyViewer
{
///
/// An editor window that displays the dependencies and references for a selected asset.
/// It uses UI Toolkit for its interface and a DependencyGraph for data processing.
///
public class DependencyViewerWindow : EditorWindow
{
private const string UxmlPath = "DependencyViewerWindow.uxml";
private const string USSPath = "DependencyViewerWindow.uss";
private ObjectField _assetSelector;
private ListView _dependenciesList;
private ListView _referencesList;
private Button _refreshButton;
private Object _selectedAsset;
private DependencyGraph _graph;
[MenuItem("Analyzer/Dependency Viewer")]
public static void ShowWindow()
{
var wnd = GetWindow();
wnd.titleContent = new GUIContent("Dependency Viewer");
}
public void CreateGUI()
{
var visualTree = AssetDatabase.LoadAssetAtPath(FindAssetPath(UxmlPath));
if (visualTree == null)
{
rootVisualElement.Add(new Label($"Could not find UXML file at path '{UxmlPath}'. Make sure it's in an 'Editor' folder."));
return;
}
visualTree.CloneTree(rootVisualElement);
var styleSheet = AssetDatabase.LoadAssetAtPath(FindAssetPath(USSPath));
if (styleSheet != null)
{
rootVisualElement.styleSheets.Add(styleSheet);
}
_graph = new DependencyGraph();
_assetSelector = rootVisualElement.Q("script-selector");
_dependenciesList = rootVisualElement.Q("dependencies-list");
_referencesList = rootVisualElement.Q("references-list");
_refreshButton = rootVisualElement.Q