@@ -384,6 +384,7 @@ private ConnectionConfig Init(bool server)
384384 MessageManager . messageTypes . Add ( "MLAPI_COMMAND" , 12 ) ;
385385 MessageManager . messageTypes . Add ( "MLAPI_RPC" , 13 ) ;
386386 MessageManager . messageTypes . Add ( "MLAPI_TARGET" , 14 ) ;
387+ MessageManager . messageTypes . Add ( "MLAPI_SET_VISIBILITY" , 15 ) ;
387388
388389 List < MessageType > messageTypes = new List < MessageType > ( NetworkConfig . MessageTypes )
389390 {
@@ -761,7 +762,7 @@ private void Update()
761762 if ( NetworkConfig . ConnectionApproval )
762763 writer . WriteByteArray ( NetworkConfig . ConnectionData ) ;
763764
764- InternalMessageHandler . Send ( netId . GetClientId ( ) , "MLAPI_CONNECTION_REQUEST" , "MLAPI_INTERNAL" , writer . Finalize ( ) , null , null , true ) ;
765+ InternalMessageHandler . Send ( netId . GetClientId ( ) , "MLAPI_CONNECTION_REQUEST" , "MLAPI_INTERNAL" , writer . Finalize ( ) , null , null , null , true ) ;
765766 }
766767 }
767768 break ;
@@ -1032,6 +1033,12 @@ private void HandleIncomingData(uint clientId, byte[] data, int channelId)
10321033 InternalMessageHandler . HandleTargetRpc ( clientId , incommingData , channelId ) ;
10331034 }
10341035 break ;
1036+ case 15 :
1037+ if ( isClient )
1038+ {
1039+ InternalMessageHandler . HandleSetVisibility ( clientId , incommingData , channelId ) ;
1040+ }
1041+ break ;
10351042 }
10361043 #endregion
10371044 }
@@ -1051,6 +1058,9 @@ internal void DisconnectClient(uint clientId)
10511058 if ( diffieHellmanPublicKeys . ContainsKey ( clientId ) )
10521059 diffieHellmanPublicKeys . Remove ( clientId ) ;
10531060
1061+ foreach ( KeyValuePair < uint , NetworkedObject > pair in SpawnManager . spawnedObjects )
1062+ pair . Value . observers . Remove ( clientId ) ;
1063+
10541064 NetId netId = new NetId ( clientId ) ;
10551065 if ( netId . IsHost ( ) || netId . IsInvalid ( ) )
10561066 return ;
@@ -1080,10 +1090,13 @@ internal void OnClientDisconnect(uint clientId)
10801090
10811091 if ( isServer )
10821092 {
1093+ foreach ( KeyValuePair < uint , NetworkedObject > pair in SpawnManager . spawnedObjects )
1094+ pair . Value . observers . Remove ( clientId ) ;
1095+
10831096 using ( BitWriter writer = new BitWriter ( ) )
10841097 {
10851098 writer . WriteUInt ( clientId ) ;
1086- InternalMessageHandler . Send ( "MLAPI_CLIENT_DISCONNECT" , "MLAPI_INTERNAL" , writer . Finalize ( ) , clientId ) ;
1099+ InternalMessageHandler . Send ( "MLAPI_CLIENT_DISCONNECT" , "MLAPI_INTERNAL" , writer . Finalize ( ) , clientId , null ) ;
10871100 }
10881101 }
10891102 }
@@ -1098,7 +1111,7 @@ private void SyncTime()
10981111
10991112 byte [ ] buffer = writer . Finalize ( ) ;
11001113 foreach ( KeyValuePair < uint , NetworkedClient > pair in connectedClients )
1101- InternalMessageHandler . Send ( "MLAPI_TIME_SYNC" , "MLAPI_TIME_SYNC" , buffer ) ;
1114+ InternalMessageHandler . Send ( "MLAPI_TIME_SYNC" , "MLAPI_TIME_SYNC" , buffer , null ) ;
11021115 }
11031116 }
11041117
@@ -1147,7 +1160,7 @@ internal void HandleApproval(uint clientId, bool approved, Vector3 position, Qua
11471160 connectedClients [ clientId ] . PlayerObject = go ;
11481161 }
11491162
1150- int amountOfObjectsToSend = SpawnManager . spawnedObjects . Values . Count ( ) ;
1163+ int amountOfObjectsToSend = SpawnManager . spawnedObjects . Values . Count ;
11511164
11521165 using ( BitWriter writer = new BitWriter ( ) )
11531166 {
@@ -1179,12 +1192,15 @@ internal void HandleApproval(uint clientId, bool approved, Vector3 position, Qua
11791192
11801193 foreach ( KeyValuePair < uint , NetworkedObject > pair in SpawnManager . spawnedObjects )
11811194 {
1195+ pair . Value . RebuildObservers ( clientId ) ; //Rebuilds observers for the new client
1196+
11821197 writer . WriteBool ( pair . Value . isPlayerObject ) ;
11831198 writer . WriteUInt ( pair . Value . NetworkId ) ;
11841199 writer . WriteUInt ( pair . Value . OwnerClientId ) ;
11851200 writer . WriteInt ( NetworkConfig . NetworkPrefabIds [ pair . Value . NetworkedPrefabName ] ) ;
11861201 writer . WriteBool ( pair . Value . gameObject . activeInHierarchy ) ;
11871202 writer . WriteBool ( pair . Value . sceneObject == null ? true : pair . Value . sceneObject . Value ) ;
1203+ writer . WriteBool ( pair . Value . observers . Contains ( clientId ) ) ;
11881204
11891205 writer . WriteFloat ( pair . Value . transform . position . x ) ;
11901206 writer . WriteFloat ( pair . Value . transform . position . y ) ;
@@ -1196,7 +1212,7 @@ internal void HandleApproval(uint clientId, bool approved, Vector3 position, Qua
11961212 }
11971213 }
11981214
1199- InternalMessageHandler . Send ( clientId , "MLAPI_CONNECTION_APPROVED" , "MLAPI_INTERNAL" , writer . Finalize ( ) , null , null , true ) ;
1215+ InternalMessageHandler . Send ( clientId , "MLAPI_CONNECTION_APPROVED" , "MLAPI_INTERNAL" , writer . Finalize ( ) , null , null , null , true ) ;
12001216
12011217 if ( OnClientConnectedCallback != null )
12021218 OnClientConnectedCallback . Invoke ( clientId ) ;
@@ -1213,6 +1229,7 @@ internal void HandleApproval(uint clientId, bool approved, Vector3 position, Qua
12131229 writer . WriteUInt ( clientId ) ;
12141230 writer . WriteInt ( - 1 ) ;
12151231 writer . WriteBool ( false ) ;
1232+ writer . WriteBool ( connectedClients [ clientId ] . PlayerObject . GetComponent < NetworkedObject > ( ) . observers . Contains ( clientId ) ) ;
12161233
12171234 writer . WriteFloat ( connectedClients [ clientId ] . PlayerObject . transform . position . x ) ;
12181235 writer . WriteFloat ( connectedClients [ clientId ] . PlayerObject . transform . position . y ) ;
@@ -1227,7 +1244,7 @@ internal void HandleApproval(uint clientId, bool approved, Vector3 position, Qua
12271244 writer . WriteUInt ( clientId ) ;
12281245 }
12291246
1230- InternalMessageHandler . Send ( "MLAPI_ADD_OBJECT" , "MLAPI_INTERNAL" , writer . Finalize ( ) , clientId ) ;
1247+ InternalMessageHandler . Send ( "MLAPI_ADD_OBJECT" , "MLAPI_INTERNAL" , writer . Finalize ( ) , clientId , null ) ;
12311248 }
12321249 //Flush syncvars:
12331250 foreach ( KeyValuePair < uint , NetworkedObject > networkedObject in SpawnManager . spawnedObjects )
0 commit comments