Skip to content

Commit 11f4d75

Browse files
committed
Added hover to NetworkProfiler
1 parent e964a7a commit 11f4d75

File tree

1 file changed

+34
-5
lines changed

1 file changed

+34
-5
lines changed

MLAPI-Editor/MLAPIProfiler.cs

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ GUIStyle wrapStyle
2727
}
2828
float updateDelay = 1f;
2929
int captureCount = 100;
30+
TickEvent eventHover = null;
3031
float showMax = 0;
3132
float showMin = 0;
3233
bool record = false;
@@ -37,7 +38,6 @@ struct ProfilerContainer
3738
{
3839
public ProfilerTick[] ticks;
3940
}
40-
4141
private void OnGUI()
4242
{
4343
if (!NetworkProfiler.IsRunning && record)
@@ -212,14 +212,20 @@ record = EditorGUILayout.Toggle("Record", record);
212212
{
213213
TickEvent tickEvent = tick.Events[j];
214214
Rect dataRect = new Rect(currentX, currentY, widthPerTick, heightPerEvent);
215+
216+
if (dataRect.Contains(Event.current.mousePosition)) eventHover = tickEvent;
217+
else if (eventHover == tickEvent) eventHover = null;
218+
215219
if (j == tick.Events.Count - 1)
216220
dataRect.height -= 45f;
217221
EditorGUI.DrawRect(dataRect, TickTypeToColor(tickEvent.EventType));
218222
float heightPerField = heightPerEvent / 12f;
219223
EditorGUI.LabelField(new Rect(dataRect.x, dataRect.y + heightPerField * -3f, dataRect.width, dataRect.height), "EventType: " + tickEvent.EventType.ToString(), wrapStyle);
220224
EditorGUI.LabelField(new Rect(dataRect.x, dataRect.y + heightPerField * -1f, dataRect.width, dataRect.height), "Size: " + tickEvent.Bytes + "B", wrapStyle);
221-
EditorGUI.LabelField(new Rect(dataRect.x, dataRect.y + heightPerField * 1f, dataRect.width, dataRect.height), "Channel: " + tickEvent.ChannelName, wrapStyle);
222-
EditorGUI.LabelField(new Rect(dataRect.x, dataRect.y + heightPerField * 3f, dataRect.width, dataRect.height), "MessageType: " + tickEvent.MessageType, wrapStyle);
225+
string channelName = tickEvent.ChannelName.Length > 5 ? tickEvent.ChannelName.Remove(5, tickEvent.ChannelName.Length - 5) + "..." : tickEvent.ChannelName;
226+
EditorGUI.LabelField(new Rect(dataRect.x, dataRect.y + heightPerField * 1f, dataRect.width, dataRect.height), "Channel: " + channelName, wrapStyle);
227+
string messageType = tickEvent.MessageType.Length > 5 ? tickEvent.MessageType.Remove(5, tickEvent.MessageType.Length - 5) + "..." : tickEvent.MessageType;
228+
EditorGUI.LabelField(new Rect(dataRect.x, dataRect.y + heightPerField * 3f, dataRect.width, dataRect.height), "MessageType: " + messageType, wrapStyle);
223229

224230
currentY += heightPerEvent + 5f;
225231
}
@@ -230,10 +236,23 @@ record = EditorGUILayout.Toggle("Record", record);
230236
currentX += widthPerTick;
231237
}
232238

239+
//Draw hover thingy
240+
if (eventHover != null)
241+
{
242+
Rect rect = new Rect(Event.current.mousePosition, new Vector2(500, 100));
243+
EditorGUI.DrawRect(rect, EditorColor);
244+
245+
float heightPerField = (rect.height - 5) / 4;
246+
EditorGUI.LabelField(new Rect(rect.x + 5, rect.y + 5, rect.width, rect.height), "EventType: " + eventHover.EventType.ToString());
247+
EditorGUI.LabelField(new Rect(rect.x + 5, rect.y + heightPerField * 1 + 5, rect.width, rect.height), "Size: " + eventHover.Bytes + "B");
248+
EditorGUI.LabelField(new Rect(rect.x + 5, rect.y + heightPerField * 2 + 5, rect.width, rect.height), "Channel: " + eventHover.ChannelName);
249+
EditorGUI.LabelField(new Rect(rect.x + 5, rect.y + heightPerField * 3 + 5, rect.width, rect.height), "MessageType: " + eventHover.MessageType);
250+
}
251+
233252
Repaint();
234253
}
235254

236-
private static Color TickTypeToColor(TickType type)
255+
private Color TickTypeToColor(TickType type)
237256
{
238257
switch (type)
239258
{
@@ -243,8 +262,18 @@ private static Color TickTypeToColor(TickType type)
243262
return new Color(0f, 0.85f, 0.85f, 0.28f);
244263
case TickType.Send:
245264
return new Color(0, 0.55f, 1f, 0.06f);
265+
default:
266+
return Color.clear;
267+
}
268+
}
269+
270+
private Color EditorColor
271+
{
272+
get
273+
{
274+
return EditorGUIUtility.isProSkin ? new Color32(56, 56, 56, 255) : new Color32(194, 194, 194, 255);
246275
}
247-
return EditorGUIUtility.isProSkin ? new Color32(70, 70, 70, 255) : new Color32(200, 200, 200, 255);
248276
}
249277
}
278+
250279
}

0 commit comments

Comments
 (0)