-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDependencyBackend.cs
More file actions
104 lines (85 loc) · 2.83 KB
/
Copy pathDependencyBackend.cs
File metadata and controls
104 lines (85 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
using UnityEngine;
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
namespace RelationsInspector.Backend.AssetDependency
{
using ObjMap = Dictionary<Object, HashSet<Object>>;
[Title( "Object dependencies" )]
[Version( "1.0.0" )]
[Description( "Shows all objects that a target object depends on, including the dependencies between those." )]
[Documentation( @"https://seldomu.github.io/riBackends/ObjectDependency/" )]
class DependencyBackend : MinimalBackend<Object, string>
{
ObjMap graph;
string searchString;
public override void Awake( GetAPI getAPI )
{
graph = new ObjMap();
base.Awake( getAPI );
}
public override IEnumerable<Object> Init( object target )
{
var targetObj = target as Object;
// generate the dependency graph for this target
var rootGOgraph = ObjectGraphUtil.GetDependencyGraph( targetObj, new Object[ 0 ] );
// merge it with the existing graphs (of other targets)
graph = ObjectGraphUtil.MergeGraphs( graph, rootGOgraph );
System.GC.Collect();
// targets have probably been substituted by cycleReps in the graph, so just use all parent-less nodes as seeds
return ObjectGraphUtil.GetRoots( rootGOgraph );
}
public override IEnumerable<Relation<Object, string>> GetRelations( Object entity )
{
if ( !graph.ContainsKey( entity ) )
yield break;
foreach ( var node in graph[ entity ] )
yield return new Relation<Object, string>( entity, node, string.Empty );
}
public override string GetEntityTooltip( Object entity )
{
var asCycleRep = entity as CycleRep;
if ( asCycleRep == null )
return base.GetEntityTooltip( entity );
if ( asCycleRep.gameObject == null )
return string.Join( "\n", asCycleRep.members.Select( x => x.name ).ToArray() );
return asCycleRep.gameObject.name;
}
public override void OnEntitySelectionChange( Object[] selection )
{
// replaces gameobject-cycleReps by their gameObjects
System.Func<Object, Object> substitute = x =>
{
var asRep = x as CycleRep;
if ( asRep == null )
return x;
if ( asRep.members.Count() == 1 )
return asRep.members.First();
if ( asRep.gameObject != null )
return asRep.gameObject;
return asRep;
};
Selection.objects = selection.Select( substitute ).ToArray();
}
public override Rect OnGUI()
{
GUILayout.BeginHorizontal( EditorStyles.toolbar );
{
GUILayout.FlexibleSpace();
searchString = BackendUtil.DrawEntitySelectSearchField( searchString, api );
}
GUILayout.EndHorizontal();
return BackendUtil.GetMaxRect();
}
public override void OnDestroy()
{
if ( graph != null )
{
// destroy all cycleReps
var cycleReps = ObjectGraphUtil.GetAllNodes( graph ).OfType<CycleRep>().ToArray();
foreach ( var cycleRep in cycleReps )
Object.DestroyImmediate( cycleRep );
}
}
}
}