3
3
using System . IO ;
4
4
using System . Linq ;
5
5
using System . Runtime . CompilerServices ;
6
- using MLAPI . Configuration ;
7
6
using MLAPI . Exceptions ;
8
7
using MLAPI . Hashing ;
9
8
using MLAPI . Logging ;
10
9
using MLAPI . Messaging ;
11
- using MLAPI . Serialization . Pooled ;
12
10
using MLAPI . Transports ;
13
11
using MLAPI . Serialization ;
14
12
using UnityEngine ;
@@ -222,11 +220,10 @@ private void Awake()
222
220
}
223
221
224
222
/// <summary>
225
- /// Shows a previously hidden object to a client
223
+ /// Shows a previously hidden <see cref="NetworkObject"/> to a client
226
224
/// </summary>
227
- /// <param name="clientId">The client to show the object to</param>
228
- /// <param name="payload">An optional payload to send as part of the spawn</param>
229
- public void NetworkShow ( ulong clientId , Stream payload = null )
225
+ /// <param name="clientId">The client to show the <see cref="NetworkObject"/> to</param>
226
+ public void NetworkShow ( ulong clientId )
230
227
{
231
228
if ( ! IsSpawned )
232
229
{
@@ -245,16 +242,15 @@ public void NetworkShow(ulong clientId, Stream payload = null)
245
242
246
243
Observers . Add ( clientId ) ;
247
244
248
- NetworkManager . SpawnManager . SendSpawnCallForObject ( clientId , OwnerClientId , this , payload ) ;
245
+ NetworkManager . SpawnManager . SendSpawnCallForObject ( clientId , OwnerClientId , this ) ;
249
246
}
250
247
251
248
/// <summary>
252
- /// Shows a list of previously hidden objects to a client
249
+ /// Shows a list of previously hidden <see cref="NetworkObject"/>s to a client
253
250
/// </summary>
254
- /// <param name="networkObjects">The objects to show</param>
251
+ /// <param name="networkObjects">The <see cref="NetworkObject"/>s to show</param>
255
252
/// <param name="clientId">The client to show the objects to</param>
256
- /// <param name="payload">An optional payload to send as part of the spawns</param>
257
- public static void NetworkShow ( List < NetworkObject > networkObjects , ulong clientId , Stream payload = null )
253
+ public static void NetworkShow ( List < NetworkObject > networkObjects , ulong clientId )
258
254
{
259
255
if ( networkObjects == null || networkObjects . Count == 0 )
260
256
{
@@ -304,7 +300,7 @@ public static void NetworkShow(List<NetworkObject> networkObjects, ulong clientI
304
300
networkObjects [ i ] . Observers . Add ( clientId ) ;
305
301
306
302
networkManager . SpawnManager . WriteSpawnCallForObject ( nonNullContext . NetworkWriter , clientId ,
307
- networkObjects [ i ] , payload ) ;
303
+ networkObjects [ i ] ) ;
308
304
}
309
305
}
310
306
}
@@ -429,7 +425,7 @@ private void OnDestroy()
429
425
}
430
426
431
427
[ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
432
- private void SpawnInternal ( Stream spawnPayload , bool destroyWithScene , ulong ? ownerClientId , bool playerObject )
428
+ private void SpawnInternal ( bool destroyWithScene , ulong ? ownerClientId , bool playerObject )
433
429
{
434
430
if ( ! NetworkManager . IsListening )
435
431
{
@@ -441,52 +437,44 @@ private void SpawnInternal(Stream spawnPayload, bool destroyWithScene, ulong? ow
441
437
throw new NotServerException ( $ "Only server can spawn { nameof ( NetworkObject ) } s") ;
442
438
}
443
439
444
- if ( spawnPayload != null )
445
- {
446
- spawnPayload . Position = 0 ;
447
- }
448
-
449
- NetworkManager . SpawnManager . SpawnNetworkObjectLocally ( this , NetworkManager . SpawnManager . GetNetworkObjectId ( ) , false , playerObject , ownerClientId , spawnPayload , spawnPayload != null , spawnPayload == null ? 0 : ( int ) spawnPayload . Length , false , destroyWithScene ) ;
440
+ NetworkManager . SpawnManager . SpawnNetworkObjectLocally ( this , NetworkManager . SpawnManager . GetNetworkObjectId ( ) , false , playerObject , ownerClientId , null , false , destroyWithScene ) ;
450
441
ulong ownerId = ownerClientId != null ? ownerClientId . Value : NetworkManager . ServerClientId ;
451
442
for ( int i = 0 ; i < NetworkManager . ConnectedClientsList . Count ; i ++ )
452
443
{
453
444
if ( Observers . Contains ( NetworkManager . ConnectedClientsList [ i ] . ClientId ) )
454
445
{
455
- NetworkManager . SpawnManager . SendSpawnCallForObject ( NetworkManager . ConnectedClientsList [ i ] . ClientId , ownerId , this , spawnPayload ) ;
446
+ NetworkManager . SpawnManager . SendSpawnCallForObject ( NetworkManager . ConnectedClientsList [ i ] . ClientId , ownerId , this ) ;
456
447
}
457
448
}
458
449
}
459
450
460
451
/// <summary>
461
- /// Spawns this GameObject across the network. Can only be called from the Server
452
+ /// Spawns this <see cref="NetworkObject"/> across the network. Can only be called from the Server
462
453
/// </summary>
463
- /// <param name="spawnPayload">The writer containing the spawn payload</param>
464
454
/// <param name="destroyWithScene">Should the object be destroyed when the scene is changed</param>
465
- public void Spawn ( Stream spawnPayload = null , bool destroyWithScene = false )
455
+ public void Spawn ( bool destroyWithScene = false )
466
456
{
467
- SpawnInternal ( spawnPayload , destroyWithScene , null , false ) ;
457
+ SpawnInternal ( destroyWithScene , null , false ) ;
468
458
}
469
459
470
460
/// <summary>
471
- /// Spawns an object across the network with a given owner. Can only be called from server
461
+ /// Spawns a <see cref="NetworkObject"/> across the network with a given owner. Can only be called from server
472
462
/// </summary>
473
463
/// <param name="clientId">The clientId to own the object</param>
474
- /// <param name="spawnPayload">The writer containing the spawn payload</param>
475
- /// <param name="destroyWithScene">Should the object be destroyd when the scene is changed</param>
476
- public void SpawnWithOwnership ( ulong clientId , Stream spawnPayload = null , bool destroyWithScene = false )
464
+ /// <param name="destroyWithScene">Should the object be destroyed when the scene is changed</param>
465
+ public void SpawnWithOwnership ( ulong clientId , bool destroyWithScene = false )
477
466
{
478
- SpawnInternal ( spawnPayload , destroyWithScene , clientId , false ) ;
467
+ SpawnInternal ( destroyWithScene , clientId , false ) ;
479
468
}
480
469
481
470
/// <summary>
482
- /// Spawns an object across the network and makes it the player object for the given client
471
+ /// Spawns a <see cref="NetworkObject"/> across the network and makes it the player object for the given client
483
472
/// </summary>
484
473
/// <param name="clientId">The clientId whos player object this is</param>
485
- /// <param name="spawnPayload">The writer containing the spawn payload</param>
486
474
/// <param name="destroyWithScene">Should the object be destroyd when the scene is changed</param>
487
- public void SpawnAsPlayerObject ( ulong clientId , Stream spawnPayload = null , bool destroyWithScene = false )
475
+ public void SpawnAsPlayerObject ( ulong clientId , bool destroyWithScene = false )
488
476
{
489
- SpawnInternal ( spawnPayload , destroyWithScene , clientId , true ) ;
477
+ SpawnInternal ( destroyWithScene , clientId , true ) ;
490
478
}
491
479
492
480
/// <summary>
@@ -781,12 +769,12 @@ internal static void CheckOrphanChildren()
781
769
}
782
770
}
783
771
784
- internal void InvokeBehaviourNetworkSpawn ( Stream stream )
772
+ internal void InvokeBehaviourNetworkSpawn ( )
785
773
{
786
774
for ( int i = 0 ; i < ChildNetworkBehaviours . Count ; i ++ )
787
775
{
788
776
ChildNetworkBehaviours [ i ] . InternalOnNetworkSpawn ( ) ;
789
- ChildNetworkBehaviours [ i ] . OnNetworkSpawn ( stream ) ;
777
+ ChildNetworkBehaviours [ i ] . OnNetworkSpawn ( ) ;
790
778
}
791
779
}
792
780
@@ -1055,7 +1043,7 @@ internal static NetworkObject DeserializeSceneObject(NetworkBuffer objectStream,
1055
1043
}
1056
1044
1057
1045
// Spawn the NetworkObject
1058
- networkManager . SpawnManager . SpawnNetworkObjectLocally ( networkObject , networkId , isSceneObject , isPlayerObject , ownerClientId , objectStream , false , 0 , true , false ) ;
1046
+ networkManager . SpawnManager . SpawnNetworkObjectLocally ( networkObject , networkId , isSceneObject , isPlayerObject , ownerClientId , objectStream , true , false ) ;
1059
1047
1060
1048
return networkObject ;
1061
1049
}
0 commit comments