@@ -10,6 +10,8 @@ namespace MLAPI
10
10
{
11
11
public class NetworkingManager : MonoBehaviour
12
12
{
13
+ public bool DontDestroy = true ;
14
+ public bool RunInBackground = true ;
13
15
public List < GameObject > SpawnablePrefabs ;
14
16
public GameObject DefaultPlayerPrefab ;
15
17
public static NetworkingManager singleton ;
@@ -42,15 +44,28 @@ public bool isHost
42
44
43
45
private void OnValidate ( )
44
46
{
45
- for ( int i = 0 ; i < SpawnablePrefabs . Count ; i ++ )
47
+ if ( SpawnablePrefabs != null )
46
48
{
47
- NetworkedObject netObject = SpawnablePrefabs [ i ] . GetComponentInChildren < NetworkedObject > ( ) ;
49
+ for ( int i = 0 ; i < SpawnablePrefabs . Count ; i ++ )
50
+ {
51
+ if ( SpawnablePrefabs [ i ] == null )
52
+ continue ;
53
+ NetworkedObject netObject = SpawnablePrefabs [ i ] . GetComponentInChildren < NetworkedObject > ( ) ;
54
+ if ( netObject == null )
55
+ {
56
+ Debug . LogWarning ( "MLAPI: All SpawnablePrefabs need a NetworkedObject component. Please add one to the prefab " + SpawnablePrefabs [ i ] . gameObject . name ) ;
57
+ continue ;
58
+ }
59
+ netObject . SpawnablePrefabIndex = i ;
60
+ }
61
+ }
62
+ if ( DefaultPlayerPrefab != null )
63
+ {
64
+ NetworkedObject netObject = DefaultPlayerPrefab . GetComponentInChildren < NetworkedObject > ( ) ;
48
65
if ( netObject == null )
49
66
{
50
- Debug . LogWarning ( "MLAPI: All SpawnablePrefabs need a NetworkedObject component. Please add one to the prefab " + SpawnablePrefabs [ i ] . gameObject . name ) ;
51
- continue ;
67
+ Debug . LogWarning ( "MLAPI: The player object needs a NetworkedObject component." ) ;
52
68
}
53
- netObject . SpawnablePrefabIndex = i ;
54
69
}
55
70
}
56
71
@@ -250,7 +265,10 @@ private void OnEnable()
250
265
return ;
251
266
}
252
267
singleton = this ;
253
- DontDestroyOnLoad ( gameObject ) ;
268
+ if ( DontDestroy )
269
+ DontDestroyOnLoad ( gameObject ) ;
270
+ if ( RunInBackground )
271
+ Application . runInBackground = true ;
254
272
}
255
273
256
274
private void OnDestroy ( )
0 commit comments