@@ -752,6 +752,7 @@ private void HandleIncomingData(int clientId, byte[] data, int channelId)
752752 }
753753 if ( NetworkConfig . HandleObjectSpawning )
754754 {
755+ SpawnManager . DestroyUnspawnedObjects ( ) ;
755756 int objectCount = messageReader . ReadInt32 ( ) ;
756757 for ( int i = 0 ; i < objectCount ; i ++ )
757758 {
@@ -760,13 +761,24 @@ private void HandleIncomingData(int clientId, byte[] data, int channelId)
760761 int ownerId = messageReader . ReadInt32 ( ) ;
761762 int prefabId = messageReader . ReadInt32 ( ) ;
762763 bool isActive = messageReader . ReadBoolean ( ) ;
763- if ( isPlayerObject )
764+
765+ float xPos = messageReader . ReadSingle ( ) ;
766+ float yPos = messageReader . ReadSingle ( ) ;
767+ float zPos = messageReader . ReadSingle ( ) ;
768+
769+ float xRot = messageReader . ReadSingle ( ) ;
770+ float yRot = messageReader . ReadSingle ( ) ;
771+ float zRot = messageReader . ReadSingle ( ) ;
772+
773+ if ( isPlayerObject )
764774 {
765775 SpawnManager . SpawnPlayerObject ( ownerId , networkId ) ;
766776 }
767777 else
768778 {
769- GameObject go = SpawnManager . SpawnObject ( prefabId , networkId , ownerId ) ;
779+ GameObject go = SpawnManager . SpawnObject ( prefabId , networkId , ownerId ,
780+ new Vector3 ( xPos , yPos , zPos ) , Quaternion . Euler ( xRot , yRot , zRot ) ) ;
781+
770782 go . SetActive ( isActive ) ;
771783 }
772784 }
@@ -798,14 +810,23 @@ private void HandleIncomingData(int clientId, byte[] data, int channelId)
798810 int ownerId = messageReader . ReadInt32 ( ) ;
799811 int prefabId = messageReader . ReadInt32 ( ) ;
800812
813+ float xPos = messageReader . ReadSingle ( ) ;
814+ float yPos = messageReader . ReadSingle ( ) ;
815+ float zPos = messageReader . ReadSingle ( ) ;
816+
817+ float xRot = messageReader . ReadSingle ( ) ;
818+ float yRot = messageReader . ReadSingle ( ) ;
819+ float zRot = messageReader . ReadSingle ( ) ;
820+
801821 if ( isPlayerObject )
802822 {
803823 connectedClients . Add ( ownerId , new NetworkedClient ( ) { ClientId = ownerId } ) ;
804824 SpawnManager . SpawnPlayerObject ( ownerId , networkId ) ;
805825 }
806826 else
807827 {
808- SpawnManager . SpawnObject ( prefabId , networkId , ownerId ) ;
828+ SpawnManager . SpawnObject ( prefabId , networkId , ownerId ,
829+ new Vector3 ( xPos , yPos , zPos ) , Quaternion . Euler ( xRot , yRot , zRot ) ) ;
809830 }
810831 }
811832 else
@@ -1504,6 +1525,14 @@ private void HandleApproval(int clientId, bool approved)
15041525 writer . Write ( pair . Value . OwnerClientId ) ;
15051526 writer . Write ( pair . Value . SpawnablePrefabIndex ) ;
15061527 writer . Write ( pair . Value . gameObject . activeInHierarchy ) ;
1528+
1529+ writer . Write ( pair . Value . transform . position . x ) ;
1530+ writer . Write ( pair . Value . transform . position . y ) ;
1531+ writer . Write ( pair . Value . transform . position . z ) ;
1532+
1533+ writer . Write ( pair . Value . transform . rotation . x ) ;
1534+ writer . Write ( pair . Value . transform . rotation . y ) ;
1535+ writer . Write ( pair . Value . transform . rotation . z ) ;
15071536 }
15081537 }
15091538 }
0 commit comments