Skip to content
This repository was archived by the owner on May 16, 2023. It is now read-only.

Commit 0feee25

Browse files
committed
+ If the targeted object is a prefab, its GameObject children will be checked too. The child's name will be displayed on the node too.
+ Separate viewer stuff and the resolver and their own directories
1 parent 3745941 commit 0feee25

22 files changed

+128
-30
lines changed

Editor/Resolver.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Editor/DependencyResolver.cs renamed to Editor/Resolver/DependencyResolver.cs

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,17 @@ public IEnumerator<DependencyViewerOperation> BuildGraph()
3434
FindDependencies(_graph.RefTargetNode, _settings.DependenciesDepth);
3535
}
3636

37+
foreach (var currentOperation in FindReferences())
38+
{
39+
yield return currentOperation;
40+
}
41+
}
42+
43+
private IEnumerable<DependencyViewerOperation> FindReferences()
44+
{
3745
if (_settings.SceneSearchType != DependencyViewerSettings.SceneSearchMode.NoSearch)
3846
{
47+
// Search references in scenes
3948
List<Scene> currentOpenedScenes = DependencyViewerUtility.GetCurrentOpenedScenes();
4049
if (_settings.FindReferences)
4150
{
@@ -49,6 +58,7 @@ public IEnumerator<DependencyViewerOperation> BuildGraph()
4958
bool searchOnlyInCurrentScene = (_settings.SceneSearchType == DependencyViewerSettings.SceneSearchMode.SearchOnlyInCurrentScene);
5059
if (_settings.FindReferences && !searchOnlyInCurrentScene)
5160
{
61+
// Search references in assets
5262
foreach (var currentOperation in FindReferencesAmongAssets(_graph.RefTargetNode))
5363
{
5464
yield return currentOperation;
@@ -134,17 +144,19 @@ private List<GameObject> GetAllGameObjectsFromScenes(List<Scene> scenes)
134144

135145
private IEnumerable<DependencyViewerOperation> FindReferencesAmongAssets(DependencyViewerNode node)
136146
{
137-
AssetDependencyResolverOperation operationStatus = new AssetDependencyResolverOperation();
138-
operationStatus.node = node;
139-
140147
string[] excludeFilters = _settings.ExcludeAssetFilters.Split(',');
141148
int numPropertyChecked = 0;
142149

143150
var allLocalAssetPaths = from assetPath in AssetDatabase.GetAllAssetPaths()
144151
where assetPath.StartsWith("Assets/") && !IsAssetPathExcluded(assetPath, ref excludeFilters)
145152
select assetPath;
146-
147-
operationStatus.numTotalAssets = allLocalAssetPaths.Count();
153+
154+
AssetDependencyResolverOperation operationStatus = new AssetDependencyResolverOperation
155+
{
156+
node = node,
157+
numTotalAssets = allLocalAssetPaths.Count()
158+
};
159+
148160
foreach (string assetPath in allLocalAssetPaths)
149161
{
150162
++operationStatus.numProcessedAssets;
@@ -245,14 +257,27 @@ private void FindDependencies(DependencyViewerNode node, int depth = 1)
245257
{
246258
FindDependencies(node, components[i], depth);
247259
}
260+
261+
if (DependencyResolverUtility.IsPrefab(node.TargetObject))
262+
{
263+
UDGV.GameObjectUtility.ForeachChildrenGameObject(targetGameObject, (childGo) =>
264+
{
265+
bool isPrefabChild = true;
266+
components = childGo.GetComponents<Component>();
267+
for (int i = 0; i < components.Length; ++i)
268+
{
269+
FindDependencies(node, components[i], depth, isPrefabChild);
270+
}
271+
});
272+
}
248273
}
249274
else
250275
{
251276
FindDependencies(node, node.TargetObject, depth);
252277
}
253278
}
254279

255-
private void FindDependencies(DependencyViewerNode node, UnityEngine.Object obj, int depth = 1)
280+
private void FindDependencies(DependencyViewerNode node, UnityEngine.Object obj, int depth = 1, bool isPrefabChild = false)
256281
{
257282
SerializedObject targetObjectSO = new SerializedObject(obj);
258283
SerializedProperty sp = targetObjectSO.GetIterator();
@@ -262,8 +287,14 @@ private void FindDependencies(DependencyViewerNode node, UnityEngine.Object obj,
262287
sp.objectReferenceValue != null &&
263288
IsObjectAllowedBySettings(sp.objectReferenceValue))
264289
{
290+
// Dependency found!
265291
DependencyViewerNode dependencyNode = new DependencyViewerNode(sp.objectReferenceValue);
266292
DependencyViewerGraph.CreateNodeLink(node, dependencyNode);
293+
if (isPrefabChild)
294+
{
295+
Component comp = obj as Component;
296+
dependencyNode.GameObjectNameAsPrefabChild = comp.gameObject.name;
297+
}
267298

268299
if (depth > 1)
269300
{
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using UnityEditor;
4+
using UnityEngine;
5+
6+
public static class DependencyResolverUtility
7+
{
8+
public static bool IsObjectAnAsset(UnityEngine.Object obj)
9+
{
10+
return AssetDatabase.Contains(obj);
11+
}
12+
13+
public static bool IsPrefab(UnityEngine.Object obj)
14+
{
15+
return IsObjectAnAsset(obj) && (obj is GameObject);
16+
}
17+
}

Editor/Resolver/DependencyResolverUtility.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Editor/Utility/GameObjectUtility.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System;
2+
using System.Collections;
3+
using System.Collections.Generic;
4+
using UnityEngine;
5+
6+
namespace UDGV
7+
{
8+
internal static class GameObjectUtility
9+
{
10+
public static void ForeachChildrenGameObject(GameObject rootGameObject, Action<GameObject> callback)
11+
{
12+
Transform rootTransform = rootGameObject.transform;
13+
for (int i = 0; i < rootTransform.childCount; ++i)
14+
{
15+
Transform childTransform = rootTransform.GetChild(i);
16+
callback(childTransform.gameObject);
17+
ForeachChildrenGameObject(childTransform.gameObject, callback);
18+
}
19+
}
20+
}
21+
}

Editor/Utility/GameObjectUtility.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Editor/Viewer.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
File renamed without changes.

0 commit comments

Comments
 (0)