|
|
|
|
|
|
|
|
|
|
private void OnEnable() |
|
|
|
{ |
|
|
|
nodeRoots = new List<CallTreeNode>(); |
|
|
|
nodeRoots = new Dictionary<string, List<CallTreeNode>>(); |
|
|
|
BuildCallTree(); |
|
|
|
ReloadCallHierarchy(); |
|
|
|
BuildCallTree(); |
|
|
|
ReloadCallHierarchy(); |
|
|
|
} |
|
|
|
|
|
|
|
private void OnGUI() |
|
|
|
|
|
|
{ |
|
|
|
if (GUILayout.Button("Update", EditorStyles.toolbarButton)) |
|
|
|
if (GUILayout.Button("Reload", EditorStyles.toolbarButton)) |
|
|
|
BuildCallTree(); |
|
|
|
ReloadCallHierarchy(); |
|
|
|
GUILayout.FlexibleSpace(); |
|
|
|
|
|
|
|
GUILayout.FlexibleSpace(); |
|
|
|
if (GUILayout.Button("Clear", EditorStyles.toolbarButton)) |
|
|
|
{ |
|
|
|
m_TreeView.SetFilter(null); |
|
|
|
} |
|
|
|
List<CallTreeNode> nodeRoots; |
|
|
|
Dictionary<string, List<CallTreeNode>> nodeRoots; |
|
|
|
void BuildCallTree() |
|
|
|
void ReloadCallHierarchy() |
|
|
|
nodeRoots = new List<CallTreeNode>(); |
|
|
|
nodeRoots = new Dictionary<string, List<CallTreeNode>>(); |
|
|
|
var allEvents = Resources.FindObjectsOfTypeAll<EventBase>().ToList(); |
|
|
|
var allStateMachines = Resources.FindObjectsOfTypeAll<StateMachine>().ToList(); |
|
|
|
foreach (var evt in allEvents) |
|
|
|
{ |
|
|
|
nodeRoots.Add(GetNode(evt)); |
|
|
|
} |
|
|
|
AddToCategory<EventBase>("Events"); |
|
|
|
AddToCategory<StateMachine>("State Machines"); |
|
|
|
AddToCategory<Factory>("Factories"); |
|
|
|
foreach (var sm in allStateMachines) |
|
|
|
m_TreeView.Reload(); |
|
|
|
} |
|
|
|
|
|
|
|
void AddToCategory<T>(string name) where T:MonoBehaviour |
|
|
|
{ |
|
|
|
var list = Resources.FindObjectsOfTypeAll<T>().ToList(); |
|
|
|
|
|
|
|
if (list.Count > 0) |
|
|
|
nodeRoots.Add(name, new List<CallTreeNode>()); |
|
|
|
|
|
|
|
var listRoot = nodeRoots[name]; |
|
|
|
foreach (var item in list) |
|
|
|
nodeRoots.Add(GetStateMachineNode(sm)); |
|
|
|
if(typeof(T) == typeof(StateMachine)) |
|
|
|
{ |
|
|
|
listRoot.Add(GetStateMachineNode(item as StateMachine)); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
listRoot.Add(GetNode(item)); |
|
|
|
} |
|
|
|
m_TreeView.Reload(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
CallTreeNode GetNode(MonoBehaviour bhv) |
|
|
|
|
|
|
if (field.FieldType.IsAssignableFrom(typeof(Callable[]))) |
|
|
|
{ |
|
|
|
var node = new CallTreeNode(bhv, CallTreeNodeType.Callable, field.Name); |
|
|
|
rootNode.Children.Add(node); |
|
|
|
// Add Callables from this Callable[] array
|
|
|
|
foreach (var call in value) |
|
|
|
|
|
|
|
if (value != null && value.Length > 0) |
|
|
|
node.Children.Add(GetNode(call)); |
|
|
|
rootNode.Children.Add(node); |
|
|
|
// Add Callables from this Callable[] array
|
|
|
|
foreach (var call in value) |
|
|
|
{ |
|
|
|
node.Children.Add(GetNode(call)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
class CallTreeView : TreeView |
|
|
|
{ |
|
|
|
List<CallTreeNode> m_Roots; |
|
|
|
Dictionary<string, List<CallTreeNode>> m_Roots; |
|
|
|
public CallTreeView(List<CallTreeNode> roots) : base(new TreeViewState()) |
|
|
|
public CallTreeView(Dictionary<string, List<CallTreeNode>> roots) : base(new TreeViewState()) |
|
|
|
{ |
|
|
|
m_Roots = roots; |
|
|
|
m_Bindings = new Dictionary<int, CallTreeNode>(); |
|
|
|
|
|
|
|
|
|
|
protected override TreeViewItem BuildRoot() |
|
|
|
{ |
|
|
|
int id = 0; |
|
|
|
int id = -1; |
|
|
|
var treeRoot = new TreeViewItem(id, -1, "~Root"); |
|
|
|
foreach(var node in m_Roots) |
|
|
|
var treeRoot = new TreeViewItem(++id, -1, "~Root"); |
|
|
|
|
|
|
|
foreach(var kvp in m_Roots) |
|
|
|
if (node.ContainsReference(m_filter)) |
|
|
|
if (kvp.Value == null || kvp.Value.Count == 0) |
|
|
|
continue; |
|
|
|
|
|
|
|
var currentRoot = new TreeViewItem(++id, 0, kvp.Key); |
|
|
|
treeRoot.AddChild(currentRoot); |
|
|
|
foreach (var node in kvp.Value) |
|
|
|
treeRoot.AddChild(GetNode(node, ref id, 0)); |
|
|
|
if (node.ContainsReference(m_filter)) |
|
|
|
{ |
|
|
|
currentRoot.AddChild(GetNode(node, ref id, 1)); |
|
|
|
} |
|
|
|
if(treeRoot.children == null) |
|
|
|
if (treeRoot.children == null) |
|
|
|
|
|
|
|
return treeRoot; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
protected override void SelectionChanged(IList<int> selectedIds) |
|
|
|
{ |
|
|
|
base.SelectionChanged(selectedIds); |
|
|
|
if (selectedIds.Count > 0) |
|
|
|
if (selectedIds.Count > 0 && m_Bindings.ContainsKey(selectedIds[0])) |
|
|
|
Selection.activeObject = m_Bindings[selectedIds[0]].Target; |
|
|
|
} |
|
|
|
|
|
|
|