-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
582 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
17 changes: 17 additions & 0 deletions
17
src/MessagePipe.Unity/Assets/Plugins/MessagePipe/Editor/MessagePipe.Editor.asmdef
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"name": "MessagePipe.Editor", | ||
"references": [ | ||
"MessagePipe" | ||
], | ||
"includePlatforms": [ | ||
"Editor" | ||
], | ||
"excludePlatforms": [], | ||
"allowUnsafeCode": false, | ||
"overrideReferences": false, | ||
"precompiledReferences": [], | ||
"autoReferenced": false, | ||
"defineConstraints": [], | ||
"versionDefines": [], | ||
"noEngineReferences": false | ||
} |
7 changes: 7 additions & 0 deletions
7
src/MessagePipe.Unity/Assets/Plugins/MessagePipe/Editor/MessagePipe.Editor.asmdef.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
150 changes: 150 additions & 0 deletions
150
...MessagePipe.Unity/Assets/Plugins/MessagePipe/Editor/MessagePipeDiagnosticsInfoTreeView.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member | ||
|
||
using UnityEngine; | ||
using UnityEditor; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System; | ||
using UnityEditor.IMGUI.Controls; | ||
using System.Text; | ||
using System.Text.RegularExpressions; | ||
|
||
namespace MessagePipe.Editor | ||
{ | ||
public class MessagePipeDiagnosticsInfoTreeViewItem : TreeViewItem | ||
{ | ||
static Regex removeHref = new Regex("<a href.+>(.+)</a>", RegexOptions.Compiled); | ||
|
||
public int Count { get; set; } | ||
public string Caller { get; set; } | ||
public string[] StackTraces { get; set; } | ||
|
||
public MessagePipeDiagnosticsInfoTreeViewItem(int id) : base(id) | ||
{ | ||
|
||
} | ||
} | ||
|
||
public class MessagePipeDiagnosticsInfoTreeView : TreeView | ||
{ | ||
const string sortedColumnIndexStateKey = "MessagePipeDiagnosticsInfoTreeView_sortedColumnIndex"; | ||
|
||
public IReadOnlyList<TreeViewItem> CurrentBindingItems; | ||
int trackId = 0; | ||
|
||
public MessagePipeDiagnosticsInfoTreeView() | ||
: this(new TreeViewState(), new MultiColumnHeader(new MultiColumnHeaderState(new[] | ||
{ | ||
new MultiColumnHeaderState.Column() { headerContent = new GUIContent("Count"), width = 5}, | ||
new MultiColumnHeaderState.Column() { headerContent = new GUIContent("Caller")}, | ||
}))) | ||
{ | ||
} | ||
|
||
MessagePipeDiagnosticsInfoTreeView(TreeViewState state, MultiColumnHeader header) | ||
: base(state, header) | ||
{ | ||
rowHeight = 20; | ||
showAlternatingRowBackgrounds = true; | ||
showBorder = true; | ||
header.sortingChanged += Header_sortingChanged; | ||
|
||
header.ResizeToFit(); | ||
Reload(); | ||
|
||
header.sortedColumnIndex = SessionState.GetInt(sortedColumnIndexStateKey, 1); | ||
} | ||
|
||
public void ReloadAndSort() | ||
{ | ||
var currentSelected = this.state.selectedIDs; | ||
Reload(); | ||
Header_sortingChanged(this.multiColumnHeader); | ||
this.state.selectedIDs = currentSelected; | ||
} | ||
|
||
private void Header_sortingChanged(MultiColumnHeader multiColumnHeader) | ||
{ | ||
SessionState.SetInt(sortedColumnIndexStateKey, multiColumnHeader.sortedColumnIndex); | ||
var index = multiColumnHeader.sortedColumnIndex; | ||
var ascending = multiColumnHeader.IsSortedAscending(multiColumnHeader.sortedColumnIndex); | ||
|
||
var items = rootItem.children.Cast<MessagePipeDiagnosticsInfoTreeViewItem>(); | ||
|
||
IOrderedEnumerable<MessagePipeDiagnosticsInfoTreeViewItem> orderedEnumerable; | ||
switch (index) | ||
{ | ||
case 0: | ||
orderedEnumerable = ascending ? items.OrderBy(item => item.Count) : items.OrderByDescending(item => item.Count); | ||
break; | ||
case 1: | ||
orderedEnumerable = ascending ? items.OrderBy(item => item.Caller) : items.OrderByDescending(item => item.Caller); | ||
break; | ||
default: | ||
throw new ArgumentOutOfRangeException(nameof(index), index, null); | ||
} | ||
|
||
CurrentBindingItems = rootItem.children = orderedEnumerable.Cast<TreeViewItem>().ToList(); | ||
BuildRows(rootItem); | ||
} | ||
|
||
protected override TreeViewItem BuildRoot() | ||
{ | ||
var root = new TreeViewItem { depth = -1 }; | ||
|
||
var children = new List<TreeViewItem>(); | ||
|
||
if (MessagePipeDiagnosticsInfoWindow.diagnosticsInfo != null) | ||
{ | ||
var grouped = MessagePipeDiagnosticsInfoWindow.diagnosticsInfo.GroupedByCaller; | ||
foreach (var item in grouped) | ||
{ | ||
var viewItem = new MessagePipeDiagnosticsInfoTreeViewItem(trackId++) | ||
{ | ||
Count = item.Count(), | ||
Caller = item.Key, | ||
StackTraces = item.ToArray() | ||
}; | ||
children.Add(viewItem); | ||
} | ||
} | ||
|
||
CurrentBindingItems = children; | ||
root.children = CurrentBindingItems as List<TreeViewItem>; | ||
return root; | ||
} | ||
|
||
protected override bool CanMultiSelect(TreeViewItem item) | ||
{ | ||
return false; | ||
} | ||
|
||
protected override void RowGUI(RowGUIArgs args) | ||
{ | ||
var item = args.item as MessagePipeDiagnosticsInfoTreeViewItem; | ||
|
||
for (var visibleColumnIndex = 0; visibleColumnIndex < args.GetNumVisibleColumns(); visibleColumnIndex++) | ||
{ | ||
var rect = args.GetCellRect(visibleColumnIndex); | ||
var columnIndex = args.GetColumn(visibleColumnIndex); | ||
|
||
var labelStyle = args.selected ? EditorStyles.whiteLabel : EditorStyles.label; | ||
labelStyle.alignment = TextAnchor.MiddleLeft; | ||
switch (columnIndex) | ||
{ | ||
case 0: | ||
EditorGUI.LabelField(rect, item.Count.ToString(), labelStyle); | ||
break; | ||
case 1: | ||
EditorGUI.LabelField(rect, item.Caller, labelStyle); | ||
break; | ||
default: | ||
throw new ArgumentOutOfRangeException(nameof(columnIndex), columnIndex, null); | ||
} | ||
} | ||
} | ||
} | ||
|
||
} | ||
|
11 changes: 11 additions & 0 deletions
11
...gePipe.Unity/Assets/Plugins/MessagePipe/Editor/MessagePipeDiagnosticsInfoTreeView.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.