1
- using System ;
1
+ using System ;
2
2
using System . Collections . Generic ;
3
3
using System . ComponentModel ;
4
4
using System . IO ;
@@ -32,7 +32,7 @@ internal void ValidateHash()
32
32
{
33
33
PrefabHashGenerator = gameObject . name ;
34
34
}
35
-
35
+
36
36
PrefabHash = PrefabHashGenerator . GetStableHash64 ( ) ;
37
37
}
38
38
@@ -60,9 +60,9 @@ internal set
60
60
_ownerClientId = value ;
61
61
}
62
62
}
63
-
63
+
64
64
internal ulong ? _ownerClientId = null ;
65
-
65
+
66
66
/// <summary>
67
67
/// InstanceId is the id that is unique to the object and scene for a scene object when UsePrefabSync is false.
68
68
/// If UsePrefabSync is true or if it's used on non scene objects, this has no effect.
@@ -85,6 +85,10 @@ internal set
85
85
[ SerializeField ]
86
86
public string PrefabHashGenerator ;
87
87
/// <summary>
88
+ /// If true, the object will always be replicated as root on clients and the parent will be ignored.
89
+ /// </summary>
90
+ public bool AlwaysReplicateAsRoot ;
91
+ /// <summary>
88
92
/// Gets if this object is a player object
89
93
/// </summary>
90
94
[ EditorBrowsable ( EditorBrowsableState . Never ) ]
@@ -153,7 +157,7 @@ internal set
153
157
/// Delegate invoked when the MLAPI needs to know if the object should be visible to a client, if null it will assume true
154
158
/// </summary>
155
159
public VisibilityDelegate CheckObjectVisibility = null ;
156
-
160
+
157
161
/// <summary>
158
162
/// Whether or not to destroy this object if it's owner is destroyed.
159
163
/// If false, the objects ownership will be given to the server.
@@ -172,7 +176,7 @@ public HashSet<ulong>.Enumerator GetObservers()
172
176
{
173
177
throw new SpawnStateException ( "Object is not spawned" ) ;
174
178
}
175
-
179
+
176
180
return observers . GetEnumerator ( ) ;
177
181
}
178
182
@@ -187,7 +191,7 @@ public bool IsNetworkVisibleTo(ulong clientId)
187
191
{
188
192
throw new SpawnStateException ( "Object is not spawned" ) ;
189
193
}
190
-
194
+
191
195
return observers . Contains ( clientId ) ;
192
196
}
193
197
@@ -202,7 +206,7 @@ public void NetworkShow(ulong clientId, Stream payload = null)
202
206
{
203
207
throw new SpawnStateException ( "Object is not spawned" ) ;
204
208
}
205
-
209
+
206
210
if ( ! NetworkingManager . Singleton . IsServer )
207
211
{
208
212
throw new NotServerException ( "Only server can change visibility" ) ;
@@ -212,10 +216,10 @@ public void NetworkShow(ulong clientId, Stream payload = null)
212
216
{
213
217
throw new VisibilityChangeException ( "The object is already visible" ) ;
214
218
}
215
-
219
+
216
220
// Send spawn call
217
221
observers . Add ( clientId ) ;
218
-
222
+
219
223
SpawnManager . SendSpawnCallForObject ( clientId , this , payload ) ;
220
224
}
221
225
@@ -245,22 +249,22 @@ public static void NetworkShow(List<NetworkedObject> networkedObjects, ulong cli
245
249
throw new VisibilityChangeException ( "NetworkedObject with NetworkId: " + networkedObjects [ i ] . NetworkId + " is already visible" ) ;
246
250
}
247
251
}
248
-
252
+
249
253
using ( PooledBitStream stream = PooledBitStream . Get ( ) )
250
254
{
251
255
using ( PooledBitWriter writer = PooledBitWriter . Get ( stream ) )
252
256
{
253
257
writer . WriteUInt16Packed ( ( ushort ) networkedObjects . Count ) ;
254
258
}
255
-
259
+
256
260
for ( int i = 0 ; i < networkedObjects . Count ; i ++ )
257
261
{
258
262
// Send spawn call
259
263
networkedObjects [ i ] . observers . Add ( clientId ) ;
260
-
264
+
261
265
SpawnManager . WriteSpawnCallForObject ( stream , clientId , networkedObjects [ i ] , payload ) ;
262
266
}
263
-
267
+
264
268
InternalMessageSender . Send ( MLAPIConstants . MLAPI_ADD_OBJECTS , "MLAPI_INTERNAL" , stream , SecuritySendFlags . None , null ) ;
265
269
}
266
270
}
@@ -275,7 +279,7 @@ public void NetworkHide(ulong clientId)
275
279
{
276
280
throw new SpawnStateException ( "Object is not spawned" ) ;
277
281
}
278
-
282
+
279
283
if ( ! NetworkingManager . Singleton . IsServer )
280
284
{
281
285
throw new NotServerException ( "Only server can change visibility" ) ;
@@ -290,11 +294,11 @@ public void NetworkHide(ulong clientId)
290
294
{
291
295
throw new VisibilityChangeException ( "Cannot hide an object from the server" ) ;
292
296
}
293
-
294
-
297
+
298
+
295
299
// Send destroy call
296
300
observers . Remove ( clientId ) ;
297
-
301
+
298
302
using ( PooledBitStream stream = PooledBitStream . Get ( ) )
299
303
{
300
304
using ( PooledBitWriter writer = PooledBitWriter . Get ( stream ) )
@@ -305,7 +309,7 @@ public void NetworkHide(ulong clientId)
305
309
}
306
310
}
307
311
}
308
-
312
+
309
313
/// <summary>
310
314
/// Hides a list of objects from a client
311
315
/// </summary>
@@ -317,7 +321,7 @@ public static void NetworkHide(List<NetworkedObject> networkedObjects, ulong cli
317
321
{
318
322
throw new NotServerException ( "Only server can change visibility" ) ;
319
323
}
320
-
324
+
321
325
if ( clientId == NetworkingManager . Singleton . ServerClientId )
322
326
{
323
327
throw new VisibilityChangeException ( "Cannot hide an object from the server" ) ;
@@ -343,20 +347,20 @@ public static void NetworkHide(List<NetworkedObject> networkedObjects, ulong cli
343
347
using ( PooledBitWriter writer = PooledBitWriter . Get ( stream ) )
344
348
{
345
349
writer . WriteUInt16Packed ( ( ushort ) networkedObjects . Count ) ;
346
-
350
+
347
351
for ( int i = 0 ; i < networkedObjects . Count ; i ++ )
348
352
{
349
353
// Send destroy call
350
354
networkedObjects [ i ] . observers . Remove ( clientId ) ;
351
-
355
+
352
356
writer . WriteUInt64Packed ( networkedObjects [ i ] . NetworkId ) ;
353
357
}
354
358
}
355
-
359
+
356
360
InternalMessageSender . Send ( MLAPIConstants . MLAPI_DESTROY_OBJECTS , "MLAPI_INTERNAL" , stream , SecuritySendFlags . None , null ) ;
357
361
}
358
362
}
359
-
363
+
360
364
private void OnDestroy ( )
361
365
{
362
366
if ( NetworkingManager . Singleton != null )
@@ -374,7 +378,7 @@ public void Spawn(Stream spawnPayload = null, bool destroyWithScene = false)
374
378
{
375
379
if ( spawnPayload != null )
376
380
spawnPayload . Position = 0 ;
377
-
381
+
378
382
SpawnManager . SpawnNetworkedObjectLocally ( this , SpawnManager . GetNetworkObjectId ( ) , false , false , null , spawnPayload , spawnPayload != null , spawnPayload == null ? 0 : ( int ) spawnPayload . Length , false , destroyWithScene ) ;
379
383
380
384
for ( int i = 0 ; i < NetworkingManager . Singleton . ConnectedClientsList . Count ; i ++ )
@@ -390,7 +394,7 @@ public void Spawn(Stream spawnPayload = null, bool destroyWithScene = false)
390
394
/// Unspawns this GameObject and destroys it for other clients. This should be used if the object should be kept on the server
391
395
/// </summary>
392
396
public void UnSpawn ( )
393
- {
397
+ {
394
398
SpawnManager . UnSpawnObject ( this ) ;
395
399
}
396
400
@@ -404,7 +408,7 @@ public void SpawnWithOwnership(ulong clientId, Stream spawnPayload = null, bool
404
408
{
405
409
if ( spawnPayload != null )
406
410
spawnPayload . Position = 0 ;
407
-
411
+
408
412
SpawnManager . SpawnNetworkedObjectLocally ( this , SpawnManager . GetNetworkObjectId ( ) , false , false , clientId , spawnPayload , spawnPayload != null , spawnPayload == null ? 0 : ( int ) spawnPayload . Length , false , destroyWithScene ) ;
409
413
410
414
for ( int i = 0 ; i < NetworkingManager . Singleton . ConnectedClientsList . Count ; i ++ )
@@ -426,9 +430,9 @@ public void SpawnAsPlayerObject(ulong clientId, Stream spawnPayload = null, bool
426
430
{
427
431
if ( spawnPayload != null )
428
432
spawnPayload . Position = 0 ;
429
-
433
+
430
434
SpawnManager . SpawnNetworkedObjectLocally ( this , SpawnManager . GetNetworkObjectId ( ) , false , true , clientId , spawnPayload , spawnPayload != null , spawnPayload == null ? 0 : ( int ) spawnPayload . Length , false , destroyWithScene ) ;
431
-
435
+
432
436
for ( int i = 0 ; i < NetworkingManager . Singleton . ConnectedClientsList . Count ; i ++ )
433
437
{
434
438
if ( observers . Contains ( NetworkingManager . Singleton . ConnectedClientsList [ i ] . ClientId ) )
@@ -470,7 +474,7 @@ internal void InvokeBehaviourOnGainedOwnership()
470
474
}
471
475
}
472
476
473
- internal void ResetNetworkedStartInvoked ( )
477
+ internal void ResetNetworkedStartInvoked ( )
474
478
{
475
479
for ( int i = 0 ; i < childNetworkedBehaviours . Count ; i ++ )
476
480
{
@@ -527,15 +531,15 @@ internal static void NetworkedBehaviourUpdate()
527
531
{
528
532
if ( _lastProcessedObject >= SpawnManager . SpawnedObjectsList . Count )
529
533
_lastProcessedObject = 0 ;
530
-
534
+
531
535
// Sync all vars
532
536
for ( int j = 0 ; j < SpawnManager . SpawnedObjectsList [ _lastProcessedObject ] . childNetworkedBehaviours . Count ; j ++ )
533
537
SpawnManager . SpawnedObjectsList [ _lastProcessedObject ] . childNetworkedBehaviours [ j ] . NetworkedVarUpdate ( ) ;
534
-
538
+
535
539
_lastProcessedObject ++ ;
536
540
}
537
541
}
538
-
542
+
539
543
internal void WriteNetworkedVarData ( Stream stream , ulong clientId )
540
544
{
541
545
for ( int i = 0 ; i < childNetworkedBehaviours . Count ; i ++ )
0 commit comments