|
@@ -5,6 +5,7 @@ using UnityEngine;
|
|
|
using UnityEditor.Compilation;
|
|
|
using System.Collections.Generic;
|
|
|
using IntelligentProjectAnalyzer.Analyzer;
|
|
|
+using UnityEditor.SceneManagement;
|
|
|
|
|
|
// All using statements now refer to the new data-only class
|
|
|
using static IntelligentProjectAnalyzer.Editor.DependencyBuilderData;
|
|
@@ -21,12 +22,13 @@ namespace IntelligentProjectAnalyzer.Editor
|
|
|
/// Finds all relevant asset GUIDs for scripts, prefabs, and ScriptableObjects.
|
|
|
/// </summary>
|
|
|
/// <returns>A tuple containing queues of GUIDs for each asset type.</returns>
|
|
|
- public static (Queue<string> scriptGuids, Queue<string> prefabGuids, Queue<string> soGuids) FindAssetGuids()
|
|
|
+ public static (Queue<string> scriptGuids, Queue<string> prefabGuids, Queue<string> soGuids, Queue<string> sceneGuids) FindAssetGuids()
|
|
|
{
|
|
|
var scripts = new Queue<string>(AssetDatabase.FindAssets("t:MonoScript"));
|
|
|
var prefabs = new Queue<string>(AssetDatabase.FindAssets("t:Prefab"));
|
|
|
var scriptableObjects = new Queue<string>(AssetDatabase.FindAssets("t:ScriptableObject"));
|
|
|
- return (scripts, prefabs, scriptableObjects);
|
|
|
+ var scenes = new Queue<string>(AssetDatabase.FindAssets("t:Scene"));
|
|
|
+ return (scripts, prefabs, scriptableObjects, scenes);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -46,7 +48,7 @@ namespace IntelligentProjectAnalyzer.Editor
|
|
|
{
|
|
|
var assetPath = AssetDatabase.GUIDToAssetPath(guid);
|
|
|
if (string.IsNullOrEmpty(assetPath) || !assetPath.StartsWith("Assets/")) return null;
|
|
|
-
|
|
|
+
|
|
|
var go = AssetDatabase.LoadAssetAtPath<GameObject>(assetPath);
|
|
|
if (go == null) return null;
|
|
|
|
|
@@ -173,5 +175,54 @@ namespace IntelligentProjectAnalyzer.Editor
|
|
|
}
|
|
|
return setupData;
|
|
|
}
|
|
|
+
|
|
|
+ public static SceneMetadata PreFetchSceneMetadata(string guid)
|
|
|
+ {
|
|
|
+ var assetPath = AssetDatabase.GUIDToAssetPath(guid);
|
|
|
+ if (string.IsNullOrEmpty(assetPath) || !assetPath.StartsWith("Assets/")) return null;
|
|
|
+
|
|
|
+ var scene = EditorSceneManager.OpenScene(assetPath, OpenSceneMode.Single);
|
|
|
+
|
|
|
+ var sceneMetaData = new SceneMetadata() { Guid = guid };
|
|
|
+ var hash = new HashSet<string>();
|
|
|
+
|
|
|
+ // Find all components on the prefab and its children to get their script GUIDs.
|
|
|
+ foreach (var root in scene.GetRootGameObjects())
|
|
|
+ {
|
|
|
+ var components = root.GetComponentsInChildren<Component>(true);
|
|
|
+ foreach (var component in components)
|
|
|
+ {
|
|
|
+ if (component == null) continue;
|
|
|
+
|
|
|
+ var script = MonoScript.FromMonoBehaviour(component as MonoBehaviour);
|
|
|
+ if (script == null) continue;
|
|
|
+
|
|
|
+ var scriptAssetPath = AssetDatabase.GetAssetPath(script);
|
|
|
+ if (string.IsNullOrEmpty(scriptAssetPath)) continue;
|
|
|
+
|
|
|
+ var scriptGuid = AssetDatabase.AssetPathToGUID(scriptAssetPath);
|
|
|
+ if (!string.IsNullOrEmpty(scriptGuid) && scriptAssetPath.StartsWith("Assets/"))
|
|
|
+ {
|
|
|
+ hash.Add(scriptGuid);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ var assetDependencies = AssetDatabase.GetDependencies(assetPath);
|
|
|
+ foreach (var dependency in assetDependencies)
|
|
|
+ {
|
|
|
+ if (string.IsNullOrEmpty(dependency) || !dependency.StartsWith("Assets/") || dependency == assetPath)
|
|
|
+ {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ var dependencyGuid = AssetDatabase.AssetPathToGUID(dependency);
|
|
|
+ if (!string.IsNullOrEmpty(dependencyGuid))
|
|
|
+ {
|
|
|
+ hash.Add(dependencyGuid);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ sceneMetaData.DependencyGuids = hash.ToList();
|
|
|
+ return sceneMetaData;
|
|
|
+ }
|
|
|
}
|
|
|
}
|