Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add: LitMotion Debugger #168

Merged
merged 9 commits into from
Dec 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"name": "LitMotion.Editor",
"rootNamespace": "LitMotion.Editor",
"references": [
"GUID:3b570a5146f9d4f0fa107ed4559471a3"
"GUID:3b570a5146f9d4f0fa107ed4559471a3",
"GUID:e0cd26848372d4e5c891c569017e11f1"
],
"includePlatforms": [
"Editor"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,31 @@

namespace LitMotion.Editor
{
internal sealed class MotionTrackerViewItem : TreeViewItem
internal sealed class MotionDebuggerViewItem : TreeViewItem
{
public MotionTrackerViewItem(int id) : base(id) { }
public MotionDebuggerViewItem(int id) : base(id) { }

static readonly Regex removeHref = new("<a href.+>(.+)</a>", RegexOptions.Compiled);

public MotionHandle Handle { get; set; }
public string DebugName => debugName ??= Handle.GetDebugName();
string debugName;

public string MotionType { get; set; }
public string SchedulerType { get; set; }
public string Elapsed { get; set; }

string position;
public string Position
string stackTrace;
public string StackTrace
{
get { return position; }
get { return stackTrace; }
set
{
position = value;
PositionFirstLine = value == null ? string.Empty : GetFirstLine(position);
stackTrace = value;
StackTraceFirstLine = value == null ? string.Empty : GetFirstLine(stackTrace);
}
}

public string PositionFirstLine { get; private set; }
public string StackTraceFirstLine { get; private set; }

static string GetFirstLine(string str)
{
Expand All @@ -48,30 +51,29 @@ static string GetFirstLine(string str)
}
}

internal sealed class MotionTrackerTreeView : TreeView
internal sealed class MotionDebuggerTreeView : TreeView
{
const string sortedColumnIndexStateKey = "MotionTrackerTreeView_sortedColumnIndex";

public IReadOnlyList<TreeViewItem> CurrentBindingItems;

public MotionTrackerTreeView()
public MotionDebuggerTreeView()
: this(new TreeViewState(), new MultiColumnHeader(new MultiColumnHeaderState(new[]
{
new MultiColumnHeaderState.Column() { headerContent = new GUIContent("Motion Type"), width = 55},
new MultiColumnHeaderState.Column() { headerContent = new GUIContent("Scheduler"), width = 25},
new MultiColumnHeaderState.Column() { headerContent = new GUIContent("Elapsed"), width = 15},
new MultiColumnHeaderState.Column() { headerContent = new GUIContent("Stack Trace")},
new MultiColumnHeaderState.Column() { headerContent = new GUIContent("Name"), width = 50},
new MultiColumnHeaderState.Column() { headerContent = new GUIContent("Motion Type"), width = 80},
new MultiColumnHeaderState.Column() { headerContent = new GUIContent("Time"), width = 30},
})))
{

}

MotionTrackerTreeView(TreeViewState state, MultiColumnHeader header)
MotionDebuggerTreeView(TreeViewState state, MultiColumnHeader header)
: base(state, header)
{
rowHeight = 20;
showAlternatingRowBackgrounds = true;
showBorder = true;
showAlternatingRowBackgrounds = false;
showBorder = false;
header.sortingChanged += HeaderSortingChanged;

header.ResizeToFit();
Expand All @@ -94,13 +96,12 @@ void HeaderSortingChanged(MultiColumnHeader multiColumnHeader)
var index = multiColumnHeader.sortedColumnIndex;
var ascending = multiColumnHeader.IsSortedAscending(multiColumnHeader.sortedColumnIndex);

var items = rootItem.children.Cast<MotionTrackerViewItem>();
IOrderedEnumerable<MotionTrackerViewItem> orderedEnumerable = index switch
var items = rootItem.children.Cast<MotionDebuggerViewItem>();
var orderedEnumerable = index switch
{
0 => ascending ? items.OrderBy(item => item.MotionType) : items.OrderByDescending(item => item.MotionType),
1 => ascending ? items.OrderBy(item => item.SchedulerType) : items.OrderByDescending(item => item.SchedulerType),
2 => ascending ? items.OrderBy(item => double.Parse(item.Elapsed)) : items.OrderByDescending(item => double.Parse(item.Elapsed)),
3 => ascending ? items.OrderBy(item => item.Position) : items.OrderByDescending(item => item.PositionFirstLine),
0 => ascending ? items.OrderBy(item => item.DebugName) : items.OrderByDescending(item => item.DebugName),
1 => ascending ? items.OrderBy(item => item.MotionType) : items.OrderByDescending(item => item.MotionType),
2 => ascending ? items.OrderBy(item => item.Handle.Time) : items.OrderByDescending(item => item.Handle.Time),
_ => throw new ArgumentOutOfRangeException(nameof(index), index, null),
};
CurrentBindingItems = rootItem.children = orderedEnumerable.Cast<TreeViewItem>().ToList();
Expand Down Expand Up @@ -146,14 +147,16 @@ protected override TreeViewItem BuildRoot()
var children = new List<TreeViewItem>();

var id = 0;
foreach (var tracking in MotionTracker.Items)
foreach (var tracking in MotionDebugger.Items)
{
children.Add(new MotionTrackerViewItem(id)
if (!tracking.Handle.IsActive()) continue;

children.Add(new MotionDebuggerViewItem(id)
{
Handle = tracking.Handle,
MotionType = $"[{tracking.ValueType.Name}, {tracking.OptionsType.Name}, {tracking.AdapterType.Name}]",
SchedulerType = GetSchedulerName(tracking.Scheduler, tracking.CreatedOnEditor),
Elapsed = (DateTime.UtcNow - tracking.CreationTime).TotalSeconds.ToString("00.00"),
Position = tracking.StackTrace?.AddHyperLink()
StackTrace = tracking.StackTrace?.AddHyperLink()
});
id++;
}
Expand All @@ -170,7 +173,7 @@ protected override bool CanMultiSelect(TreeViewItem item)

protected override void RowGUI(RowGUIArgs args)
{
var item = args.item as MotionTrackerViewItem;
var item = args.item as MotionDebuggerViewItem;

for (var visibleColumnIndex = 0; visibleColumnIndex < args.GetNumVisibleColumns(); visibleColumnIndex++)
{
Expand All @@ -182,22 +185,25 @@ protected override void RowGUI(RowGUIArgs args)
switch (columnIndex)
{
case 0:
EditorGUI.LabelField(rect, item.MotionType, labelStyle);
EditorGUI.LabelField(rect, item.DebugName, labelStyle);
break;
case 1:
EditorGUI.LabelField(rect, item.SchedulerType, labelStyle);
EditorGUI.LabelField(rect, item.MotionType, labelStyle);
break;
case 2:
EditorGUI.LabelField(rect, item.Elapsed, labelStyle);
break;
case 3:
EditorGUI.LabelField(rect, item.PositionFirstLine, labelStyle);
EditorGUI.LabelField(rect, item.Handle.Time.ToString("00.00"), labelStyle);
break;
default:
throw new ArgumentOutOfRangeException(nameof(columnIndex), columnIndex, null);
}
}
}

protected override bool DoesItemMatchSearch(TreeViewItem item, string search)
{
var viewItem = item as MotionDebuggerViewItem;
return viewItem.DebugName.Contains(search, StringComparison.InvariantCultureIgnoreCase);
}
}

}
Loading