Skip to content

Commit 3f6f291

Browse files
committed
Updated NetworkProfiler UI
1 parent 9f53619 commit 3f6f291

File tree

2 files changed

+25
-23
lines changed

2 files changed

+25
-23
lines changed

MLAPI-Editor/MLAPIProfiler.cs

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ private void StartRecording()
6060

6161
private void ClearDrawing()
6262
{
63+
currentTicks.Clear();
6364
curve = AnimationCurve.Constant(0, 1, 0);
6465
lastDrawn = 0;
6566
}
@@ -215,18 +216,18 @@ private void OnGUI()
215216
}
216217
else if (emptyStreak > 0 || i == totalTicks - 1)
217218
{
218-
Rect dataRect = new Rect(currentX, 100, propWidth * emptyStreak, position.height - 100);
219+
Rect dataRect = new Rect(currentX, 140f, propWidth * emptyStreak, position.height - 140f);
219220
currentX += propWidth * emptyStreak;
220-
if (emptyStreak >= 4) EditorGUI.LabelField(new Rect(dataRect.x, dataRect.y, dataRect.width, dataRect.height), emptyStreak.ToString(), wrapStyle);
221+
if (emptyStreak >= 2) EditorGUI.LabelField(new Rect(dataRect.x, dataRect.y, dataRect.width, dataRect.height), emptyStreak.ToString(), wrapStyle);
221222
emptyStreak = 0;
222223
}
223224

224225
if (tick.Events.Count > 0)
225226
{
226-
float heightPerEvent = ((position.height - 100f) - (5f * largestTickCount)) / largestTickCount;
227-
float heightPerTotalBackground = ((position.height - 100f) - (5f * largestTickCount)) / tick.Events.Count;
227+
float heightPerEvent = ((position.height - 140f) - (5f * largestTickCount)) / largestTickCount;
228+
float heightPerTotalBackground = ((position.height - 140f) - (5f * largestTickCount)) / tick.Events.Count;
228229

229-
float currentY = 100;
230+
float currentY = 140f;
230231
for (int j = 0; j < tick.Events.Count; j++)
231232
{
232233
TickEvent tickEvent = tick.Events[j];
@@ -238,23 +239,16 @@ private void OnGUI()
238239
eventHover = tickEvent;
239240
}
240241

241-
if (j == tick.Events.Count - 1)
242-
dataRect.height -= 45f;
243-
EditorGUI.DrawRect(dataRect, TickTypeToColor(tickEvent.EventType));
244-
float heightPerField = heightPerEvent / 12f;
245-
EditorGUI.LabelField(new Rect(dataRect.x, dataRect.y + heightPerField * -3f, dataRect.width, dataRect.height), "EventType: " + tickEvent.EventType.ToString(), wrapStyle);
246-
EditorGUI.LabelField(new Rect(dataRect.x, dataRect.y + heightPerField * -1f, dataRect.width, dataRect.height), "Size: " + tickEvent.Bytes + "B", wrapStyle);
247-
string channelName = tickEvent.ChannelName.Length > 5 ? tickEvent.ChannelName.Remove(5, tickEvent.ChannelName.Length - 5) + "..." : tickEvent.ChannelName;
248-
EditorGUI.LabelField(new Rect(dataRect.x, dataRect.y + heightPerField * 1f, dataRect.width, dataRect.height), "Channel: " + channelName, wrapStyle);
249-
string messageType = tickEvent.MessageType.Length > 5 ? tickEvent.MessageType.Remove(5, tickEvent.MessageType.Length - 5) + "..." : tickEvent.MessageType;
250-
EditorGUI.LabelField(new Rect(dataRect.x, dataRect.y + heightPerField * 3f, dataRect.width, dataRect.height), "MessageType: " + messageType, wrapStyle);
242+
EditorGUI.DrawRect(dataRect, TickTypeToColor(tickEvent.EventType, true));
243+
EditorGUI.LabelField(new Rect(dataRect.x, dataRect.y, dataRect.width, dataRect.height / 2), tickEvent.EventType.ToString(), wrapStyle);
244+
EditorGUI.LabelField(new Rect(dataRect.x, dataRect.y + dataRect.height / 2, dataRect.width, dataRect.height / 2), tickEvent.Bytes + "B", wrapStyle);
251245

252246
currentY += heightPerEvent + 5f;
253247
}
254248
}
255-
EditorGUI.DrawRect(new Rect(currentX, position.height - 40, widthPerTick, 40), TickTypeToColor(tick.Type));
256-
EditorGUI.LabelField(new Rect(currentX, position.height - 40, widthPerTick, 20), "TickType: " + tick.Type.ToString(), wrapStyle);
257-
EditorGUI.LabelField(new Rect(currentX, position.height - 20, widthPerTick, 20), "Frame: " + tick.Frame.ToString(), wrapStyle);
249+
EditorGUI.DrawRect(new Rect(currentX, 100, widthPerTick, 40), TickTypeToColor(tick.Type, false));
250+
EditorGUI.LabelField(new Rect(currentX, 100, widthPerTick, 20), tick.Type.ToString(), wrapStyle);
251+
EditorGUI.LabelField(new Rect(currentX, 120, widthPerTick, 20), tick.Frame.ToString(), wrapStyle);
258252
currentX += widthPerTick;
259253
}
260254

@@ -285,20 +279,19 @@ private void OnGUI()
285279
EditorGUI.LabelField(new Rect(rect.x + 5, rect.y + heightPerField * 2 + 5, rect.width, rect.height), "Channel: " + eventHover.ChannelName, GetStyleWithTextAlpha(EditorStyles.label, hoverAlpha));
286280
EditorGUI.LabelField(new Rect(rect.x + 5, rect.y + heightPerField * 3 + 5, rect.width, rect.height), "MessageType: " + eventHover.MessageType, GetStyleWithTextAlpha(EditorStyles.label, hoverAlpha));
287281
}
288-
289282
Repaint();
290283
}
291284

292-
private Color TickTypeToColor(TickType type)
285+
private Color TickTypeToColor(TickType type, bool alpha)
293286
{
294287
switch (type)
295288
{
296289
case TickType.Event:
297-
return new Color(0.58f, 0f, 0.56f, 0.37f);
290+
return new Color(0.58f, 0f, 0.56f, alpha ? 0.37f : 0.7f);
298291
case TickType.Receive:
299-
return new Color(0f, 0.85f, 0.85f, 0.28f);
292+
return new Color(0f, 0.85f, 0.85f, alpha ? 0.28f : 0.7f);
300293
case TickType.Send:
301-
return new Color(0, 0.55f, 1f, 0.06f);
294+
return new Color(0, 0.55f, 1f, alpha ? 0.06f : 0.7f);
302295
default:
303296
return Color.clear;
304297
}

MLAPI/Data/NetworkProfiler/ProfilerTickData.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,15 @@ internal void StartEvent(TickType type, uint bytes, string channelName, string m
5757
public TickType Type;
5858
public int Frame;
5959
public int EventId;
60+
public uint Bytes
61+
{
62+
get
63+
{
64+
uint bytes = 0;
65+
for (int i = 0; i < Events.Count; i++) bytes += Events[i].Bytes;
66+
return bytes;
67+
}
68+
}
6069
}
6170

6271
public class TickEvent

0 commit comments

Comments
 (0)