1
- using System ;
1
+ using System ;
2
2
using System . Collections . Generic ;
3
3
using System . Reflection ;
4
4
using UnityEditor ;
@@ -16,10 +16,10 @@ public class NetworkingManagerEditor : Editor
16
16
private SerializedProperty dontDestroyOnLoadProperty ;
17
17
private SerializedProperty runInBackgroundProperty ;
18
18
private SerializedProperty logLevelProperty ;
19
-
19
+
20
20
// NetworkConfig
21
21
private SerializedProperty networkConfigProperty ;
22
-
22
+
23
23
// NetworkConfig fields
24
24
private SerializedProperty protocolVersionProperty ;
25
25
private SerializedProperty allowRuntimeSceneChanges ;
@@ -51,10 +51,10 @@ public class NetworkingManagerEditor : Editor
51
51
52
52
private NetworkingManager networkingManager ;
53
53
private bool initialized ;
54
-
54
+
55
55
private readonly List < Type > transportTypes = new List < Type > ( ) ;
56
- private string [ ] transportNames = new string [ ] { "Select transport..." } ;
57
-
56
+ private string [ ] transportNames = new string [ ] { "Select transport..." } ;
57
+
58
58
private void ReloadTransports ( )
59
59
{
60
60
transportTypes . Clear ( ) ;
@@ -75,7 +75,7 @@ private void ReloadTransports()
75
75
}
76
76
77
77
transportNames = new string [ transportTypes . Count + 1 ] ;
78
-
78
+
79
79
transportNames [ 0 ] = "Select transport..." ;
80
80
81
81
for ( int i = 0 ; i < transportTypes . Count ; i ++ )
@@ -91,13 +91,13 @@ private void Init()
91
91
92
92
initialized = true ;
93
93
networkingManager = ( NetworkingManager ) target ;
94
-
94
+
95
95
// Base properties
96
96
dontDestroyOnLoadProperty = serializedObject . FindProperty ( "DontDestroy" ) ;
97
97
runInBackgroundProperty = serializedObject . FindProperty ( "RunInBackground" ) ;
98
98
logLevelProperty = serializedObject . FindProperty ( "LogLevel" ) ;
99
99
networkConfigProperty = serializedObject . FindProperty ( "NetworkConfig" ) ;
100
-
100
+
101
101
// NetworkConfig properties
102
102
protocolVersionProperty = networkConfigProperty . FindPropertyRelative ( "ProtocolVersion" ) ;
103
103
allowRuntimeSceneChanges = networkConfigProperty . FindPropertyRelative ( "AllowRuntimeSceneChanges" ) ;
@@ -123,7 +123,7 @@ private void Init()
123
123
enableEncryptionProperty = networkConfigProperty . FindPropertyRelative ( "EnableEncryption" ) ;
124
124
signKeyExchangeProperty = networkConfigProperty . FindPropertyRelative ( "SignKeyExchange" ) ;
125
125
serverBase64PfxCertificateProperty = networkConfigProperty . FindPropertyRelative ( "ServerBase64PfxCertificate" ) ;
126
-
126
+
127
127
128
128
ReloadTransports ( ) ;
129
129
}
@@ -135,7 +135,7 @@ private void CheckNullProperties()
135
135
runInBackgroundProperty = serializedObject . FindProperty ( "RunInBackground" ) ;
136
136
logLevelProperty = serializedObject . FindProperty ( "LogLevel" ) ;
137
137
networkConfigProperty = serializedObject . FindProperty ( "NetworkConfig" ) ;
138
-
138
+
139
139
// NetworkConfig properties
140
140
protocolVersionProperty = networkConfigProperty . FindPropertyRelative ( "ProtocolVersion" ) ;
141
141
allowRuntimeSceneChanges = networkConfigProperty . FindPropertyRelative ( "AllowRuntimeSceneChanges" ) ;
@@ -225,10 +225,10 @@ public override void OnInspectorGUI()
225
225
{
226
226
Init ( ) ;
227
227
CheckNullProperties ( ) ;
228
-
228
+
229
229
{
230
230
SerializedProperty iterator = serializedObject . GetIterator ( ) ;
231
-
231
+
232
232
for ( bool enterChildren = true ; iterator . NextVisible ( enterChildren ) ; enterChildren = false )
233
233
{
234
234
using ( new EditorGUI . DisabledScope ( "m_Script" == iterator . propertyPath ) )
@@ -238,11 +238,11 @@ public override void OnInspectorGUI()
238
238
}
239
239
}
240
240
241
-
241
+
242
242
if ( ! networkingManager . IsServer && ! networkingManager . IsClient )
243
243
{
244
244
serializedObject . Update ( ) ;
245
-
245
+
246
246
EditorGUILayout . PropertyField ( dontDestroyOnLoadProperty ) ;
247
247
EditorGUILayout . PropertyField ( runInBackgroundProperty ) ;
248
248
EditorGUILayout . PropertyField ( logLevelProperty ) ;
@@ -252,36 +252,36 @@ public override void OnInspectorGUI()
252
252
253
253
registeredScenesList . DoLayoutList ( ) ;
254
254
EditorGUILayout . Space ( ) ;
255
-
256
-
255
+
256
+
257
257
EditorGUILayout . LabelField ( "General" , EditorStyles . boldLabel ) ;
258
258
EditorGUILayout . PropertyField ( protocolVersionProperty ) ;
259
-
259
+
260
260
EditorGUILayout . PropertyField ( networkTransportProperty ) ;
261
-
261
+
262
262
if ( networkTransportProperty . objectReferenceValue == null )
263
- {
263
+ {
264
264
EditorGUILayout . HelpBox ( "You have no transport selected. A transport is required for the MLAPI to work. Which one do you want?" , MessageType . Warning ) ;
265
265
266
266
int selection = EditorGUILayout . Popup ( 0 , transportNames ) ;
267
267
268
268
if ( selection > 0 )
269
269
{
270
270
ReloadTransports ( ) ;
271
-
271
+
272
272
Component transport = networkingManager . gameObject . GetComponent ( transportTypes [ selection - 1 ] ) ;
273
-
273
+
274
274
if ( transport == null )
275
275
{
276
276
transport = networkingManager . gameObject . AddComponent ( transportTypes [ selection - 1 ] ) ;
277
277
}
278
-
278
+
279
279
networkTransportProperty . objectReferenceValue = transport ;
280
-
280
+
281
281
Repaint ( ) ;
282
282
}
283
283
}
284
-
284
+
285
285
EditorGUILayout . PropertyField ( enableTimeResyncProperty ) ;
286
286
EditorGUILayout . PropertyField ( timeResyncIntervalProperty ) ;
287
287
@@ -296,52 +296,84 @@ public override void OnInspectorGUI()
296
296
{
297
297
EditorGUILayout . PropertyField ( maxObjectUpdatesPerTickProperty ) ;
298
298
EditorGUILayout . PropertyField ( ensureNetworkedVarLengthSafetyProperty ) ;
299
- }
300
-
299
+ }
300
+
301
301
EditorGUILayout . LabelField ( "Connection" , EditorStyles . boldLabel ) ;
302
302
EditorGUILayout . PropertyField ( connectionApprovalProperty ) ;
303
303
304
304
using ( new EditorGUI . DisabledScope ( ! networkingManager . NetworkConfig . ConnectionApproval ) )
305
305
{
306
306
EditorGUILayout . PropertyField ( clientConnectionBufferTimeoutProperty ) ;
307
307
}
308
-
308
+
309
309
EditorGUILayout . LabelField ( "Lag Compensation" , EditorStyles . boldLabel ) ;
310
310
EditorGUILayout . PropertyField ( secondsHistoryProperty ) ;
311
-
311
+
312
312
EditorGUILayout . LabelField ( "Spawning" , EditorStyles . boldLabel ) ;
313
313
EditorGUILayout . PropertyField ( forceSamePrefabsProperty ) ;
314
314
EditorGUILayout . PropertyField ( usePrefabSyncProperty ) ;
315
-
315
+
316
316
EditorGUILayout . PropertyField ( recycleNetworkIdsProperty ) ;
317
-
317
+
318
318
using ( new EditorGUI . DisabledScope ( ! networkingManager . NetworkConfig . RecycleNetworkIds ) )
319
319
{
320
320
EditorGUILayout . PropertyField ( networkIdRecycleDelayProperty ) ;
321
321
}
322
-
322
+
323
323
EditorGUILayout . LabelField ( "Bandwidth" , EditorStyles . boldLabel ) ;
324
324
EditorGUILayout . PropertyField ( rpcHashSizeProperty ) ;
325
325
326
326
EditorGUILayout . LabelField ( "Scene Management" , EditorStyles . boldLabel ) ;
327
327
EditorGUILayout . PropertyField ( loadSceneTimeOutProperty ) ;
328
328
EditorGUILayout . PropertyField ( allowRuntimeSceneChanges ) ;
329
-
329
+
330
330
EditorGUILayout . LabelField ( "Cryptography" , EditorStyles . boldLabel ) ;
331
331
EditorGUILayout . PropertyField ( enableEncryptionProperty ) ;
332
332
333
333
using ( new EditorGUI . DisabledScope ( ! networkingManager . NetworkConfig . EnableEncryption ) )
334
334
{
335
335
EditorGUILayout . PropertyField ( signKeyExchangeProperty ) ;
336
- EditorGUILayout . PropertyField ( serverBase64PfxCertificateProperty ) ;
336
+ EditorGUILayout . PropertyField ( serverBase64PfxCertificateProperty ) ;
337
337
}
338
-
338
+
339
339
serializedObject . ApplyModifiedProperties ( ) ;
340
+
341
+
342
+ // Start buttons below
343
+ {
344
+ string buttonDisabledReasonSuffix = "" ;
345
+
346
+ if ( ! EditorApplication . isPlaying )
347
+ {
348
+ buttonDisabledReasonSuffix = ". This can only be done in play mode" ;
349
+ GUI . enabled = false ;
350
+ }
351
+
352
+ if ( GUILayout . Button ( new GUIContent ( "Start Host" , "Starts a host instance" + buttonDisabledReasonSuffix ) ) )
353
+ {
354
+ networkingManager . StartHost ( ) ;
355
+ }
356
+
357
+ if ( GUILayout . Button ( new GUIContent ( "Start Server" , "Starts a server instance" + buttonDisabledReasonSuffix ) ) )
358
+ {
359
+ networkingManager . StartServer ( ) ;
360
+ }
361
+
362
+ if ( GUILayout . Button ( new GUIContent ( "Start Client" , "Starts a client instance" + buttonDisabledReasonSuffix ) ) )
363
+ {
364
+ networkingManager . StartClient ( ) ;
365
+ }
366
+
367
+ if ( ! EditorApplication . isPlaying )
368
+ {
369
+ GUI . enabled = true ;
370
+ }
371
+ }
340
372
}
341
373
else
342
374
{
343
375
string instanceType = "" ;
344
-
376
+
345
377
if ( networkingManager . IsHost )
346
378
instanceType = "Host" ;
347
379
else if ( networkingManager . IsServer )
@@ -350,8 +382,8 @@ public override void OnInspectorGUI()
350
382
instanceType = "Client" ;
351
383
352
384
EditorGUILayout . HelpBox ( "You cannot edit the NetworkConfig when a " + instanceType + " is running." , MessageType . Info ) ;
353
-
354
- if ( GUILayout . Toggle ( false , "Stop " + instanceType , EditorStyles . miniButtonMid ) )
385
+
386
+ if ( GUILayout . Button ( new GUIContent ( "Stop " + instanceType , "Stops the " + instanceType + " instance." ) ) )
355
387
{
356
388
if ( networkingManager . IsHost )
357
389
networkingManager . StopHost ( ) ;
0 commit comments