Skip to content

Commit 0ff8a15

Browse files
committed
Fixed Import datafile
1 parent ee9aac1 commit 0ff8a15

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

MLAPI-Editor/MLAPIProfiler.cs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using MLAPI.Data.NetworkProfiler;
2+
using MLAPI.NetworkingManagerComponents.Binary;
23
using System.Collections.Generic;
4+
using System.IO;
35
using UnityEditor;
46
using UnityEngine;
57

@@ -32,7 +34,7 @@ GUIStyle wrapStyle
3234
float lastDrawn = 0;
3335
struct ProfilerContainer
3436
{
35-
ProfilerTick[] ticks;
37+
public ProfilerTick[] ticks;
3638
}
3739
private void OnGUI()
3840
{
@@ -46,16 +48,38 @@ private void OnGUI()
4648
lastDrawn = 0;
4749
NetworkProfiler.Start(captureCount);
4850
}
51+
4952
//Draw top bar
5053
EditorGUILayout.BeginVertical();
5154
EditorGUILayout.BeginHorizontal();
5255
bool prevRec = record;
5356
record = EditorGUILayout.Toggle("Record", record);
57+
5458
if (GUILayout.Button("Import datafile"))
5559
{
56-
string path = EditorUtility.OpenFilePanel("Choose a NetworkProfilerFile", "", "");
60+
ProfilerTick[] ticks = BinarySerializer.Deserialize<ProfilerContainer>(File.ReadAllBytes(EditorUtility.OpenFilePanel("Choose a NetworkProfiler file", "", ""))).ticks;
61+
if (ticks.Length >= 2)
62+
curve = AnimationCurve.Constant(ticks[0].EventId, ticks[(ticks.Length - 1)].EventId, 0);
63+
else
64+
curve = AnimationCurve.Constant(0, 1, 0);
65+
currentTicks.Clear();
66+
for (int i = 0; i < ticks.Length; i++)
67+
{
68+
currentTicks.Add(ticks[i]);
5769

70+
uint bytes = 0;
71+
if (ticks[i].Events.Count > 0)
72+
{
73+
for (int j = 0; j < ticks[i].Events.Count; j++)
74+
{
75+
TickEvent tickEvent = ticks[i].Events[j];
76+
bytes += tickEvent.Bytes;
77+
}
78+
}
79+
curve.AddKey(ticks[i].EventId, bytes);
80+
}
5881
}
82+
5983
EditorGUILayout.EndHorizontal();
6084
float prevHis = captureCount;
6185
captureCount = EditorGUILayout.DelayedIntField("History count", captureCount);

0 commit comments

Comments
 (0)