@@ -29,38 +29,57 @@ GUIStyle wrapStyle
29
29
int captureCount = 100 ;
30
30
float showMax = 0 ;
31
31
float showMin = 0 ;
32
- bool record = false ;
33
32
AnimationCurve curve = AnimationCurve . Constant ( 0 , 1 , 0 ) ;
34
33
readonly List < ProfilerTick > currentTicks = new List < ProfilerTick > ( ) ;
35
34
float lastDrawn = 0 ;
36
35
struct ProfilerContainer
37
36
{
38
37
public ProfilerTick [ ] ticks ;
39
38
}
40
- private void OnGUI ( )
39
+
40
+ private void StopRecording ( )
41
41
{
42
- if ( ! NetworkProfiler . IsRunning && record )
43
- {
44
- if ( NetworkProfiler . Ticks != null && NetworkProfiler . Ticks . Count >= 2 )
45
- curve = AnimationCurve . Constant ( NetworkProfiler . Ticks . ElementAt ( 0 ) . Frame , NetworkProfiler . Ticks . ElementAt ( NetworkProfiler . Ticks . Count - 1 ) . Frame , 0 ) ;
46
- else
47
- curve = AnimationCurve . Constant ( 0 , 1 , 0 ) ;
42
+ NetworkProfiler . Stop ( ) ;
43
+ }
48
44
49
- lastDrawn = 0 ;
50
- NetworkProfiler . Start ( captureCount ) ;
51
- }
45
+ private void StartRecording ( )
46
+ {
47
+ if ( NetworkProfiler . IsRunning )
48
+ StopRecording ( ) ;
49
+
50
+ if ( NetworkProfiler . Ticks != null && NetworkProfiler . Ticks . Count >= 2 )
51
+ curve = AnimationCurve . Constant ( NetworkProfiler . Ticks . ElementAt ( 0 ) . Frame , NetworkProfiler . Ticks . ElementAt ( NetworkProfiler . Ticks . Count - 1 ) . Frame , 0 ) ;
52
+ else
53
+ curve = AnimationCurve . Constant ( 0 , 1 , 0 ) ;
54
+
55
+ lastDrawn = 0 ;
56
+ NetworkProfiler . Start ( captureCount ) ;
57
+ }
58
+
59
+ private void ChangeRecordState ( )
60
+ {
61
+ if ( NetworkProfiler . IsRunning ) StopRecording ( ) ;
62
+ else StartRecording ( ) ;
63
+ }
64
+
65
+ private void OnGUI ( )
66
+ {
67
+ bool recording = NetworkProfiler . IsRunning ;
52
68
53
69
//Draw top bar
54
70
EditorGUILayout . BeginVertical ( ) ;
55
71
EditorGUILayout . BeginHorizontal ( ) ;
56
- bool prevRec = record ;
57
- record = EditorGUILayout . Toggle ( "Record" , record ) ;
72
+ if ( GUILayout . Button ( recording ? "Stop" : "Capture" ) ) ChangeRecordState ( ) ;
58
73
59
74
if ( GUILayout . Button ( "Import datafile" ) )
60
75
{
61
76
ProfilerTick [ ] ticks = BinarySerializer . Deserialize < ProfilerContainer > ( File . ReadAllBytes ( EditorUtility . OpenFilePanel ( "Choose a NetworkProfiler file" , "" , "" ) ) ) . ticks ;
62
77
if ( ticks . Length >= 2 )
78
+ {
63
79
curve = AnimationCurve . Constant ( ticks [ 0 ] . EventId , ticks [ ( ticks . Length - 1 ) ] . EventId , 0 ) ;
80
+ showMax = ticks . Length ;
81
+ showMin = ticks . Length - Mathf . Clamp ( 100 , 0 , ticks . Length ) ;
82
+ }
64
83
else
65
84
curve = AnimationCurve . Constant ( 0 , 1 , 0 ) ;
66
85
currentTicks . Clear ( ) ;
@@ -83,7 +102,11 @@ record = EditorGUILayout.Toggle("Record", record);
83
102
84
103
if ( GUILayout . Button ( "Export datafile" ) )
85
104
{
86
- File . WriteAllBytes ( EditorUtility . SaveFilePanel ( "Save NetworkProfiler data" , "" , "networkProfilerData" , "" ) , BinarySerializer . Serialize ( new ProfilerContainer ( ) { ticks = currentTicks . ToArray ( ) } ) ) ;
105
+ int ticksInRange = 0 ;
106
+ for ( int i = 0 ; i < currentTicks . Count ; i ++ ) if ( currentTicks [ i ] . EventId >= showMin && currentTicks [ i ] . EventId <= showMin ) ticksInRange ++ ;
107
+ ProfilerTick [ ] ticks = new ProfilerTick [ ticksInRange ] ;
108
+ for ( int i = 0 ; i < currentTicks . Count ; i ++ ) if ( currentTicks [ i ] . EventId >= showMin && currentTicks [ i ] . EventId <= showMin ) ticks [ i ] = currentTicks [ i ] ;
109
+ File . WriteAllBytes ( EditorUtility . SaveFilePanel ( "Save NetworkProfiler data" , "" , "networkProfilerData" , "" ) , BinarySerializer . Serialize ( new ProfilerContainer ( ) { ticks = ticks } ) ) ;
87
110
}
88
111
89
112
EditorGUILayout . EndHorizontal ( ) ;
@@ -94,34 +117,7 @@ record = EditorGUILayout.Toggle("Record", record);
94
117
updateDelay = EditorGUILayout . Slider ( "Refresh delay" , updateDelay , 0.1f , 10f ) ;
95
118
EditorGUILayout . EndVertical ( ) ;
96
119
97
- if ( prevRec != record )
98
- {
99
- if ( prevRec )
100
- {
101
- NetworkProfiler . Stop ( ) ;
102
- }
103
- else
104
- {
105
- if ( NetworkProfiler . Ticks != null && NetworkProfiler . Ticks . Count >= 2 )
106
- curve = AnimationCurve . Constant ( NetworkProfiler . Ticks . ElementAt ( 0 ) . EventId , NetworkProfiler . Ticks . ElementAt ( NetworkProfiler . Ticks . Count - 1 ) . EventId , 0 ) ;
107
- else
108
- curve = AnimationCurve . Constant ( 0 , 1 , 0 ) ;
109
- lastDrawn = 0 ;
110
- NetworkProfiler . Start ( captureCount ) ;
111
- }
112
- }
113
- if ( prevHis != captureCount )
114
- {
115
- NetworkProfiler . Stop ( ) ;
116
-
117
- if ( NetworkProfiler . Ticks != null && NetworkProfiler . Ticks . Count >= 2 )
118
- curve = AnimationCurve . Constant ( NetworkProfiler . Ticks . ElementAt ( 0 ) . EventId , NetworkProfiler . Ticks . ElementAt ( NetworkProfiler . Ticks . Count - 1 ) . EventId , 0 ) ;
119
- else
120
- curve = AnimationCurve . Constant ( 0 , 1 , 0 ) ;
121
-
122
- lastDrawn = 0 ;
123
- NetworkProfiler . Start ( captureCount ) ;
124
- }
120
+ if ( prevHis != captureCount ) StartRecording ( ) ;
125
121
126
122
//Cache
127
123
if ( NetworkProfiler . IsRunning )
@@ -198,7 +194,7 @@ record = EditorGUILayout.Toggle("Record", record);
198
194
{
199
195
Rect dataRect = new Rect ( currentX , 100 , propWidth * emptyStreak , position . height - 100 ) ;
200
196
currentX += propWidth * emptyStreak ;
201
- EditorGUI . LabelField ( new Rect ( dataRect . x , dataRect . y , dataRect . width , dataRect . height ) , emptyStreak . ToString ( ) , wrapStyle ) ;
197
+ if ( emptyStreak >= 4 ) EditorGUI . LabelField ( new Rect ( dataRect . x , dataRect . y , dataRect . width , dataRect . height ) , emptyStreak . ToString ( ) , wrapStyle ) ;
202
198
emptyStreak = 0 ;
203
199
}
204
200
0 commit comments