@@ -384,6 +384,7 @@ private ConnectionConfig Init(bool server)
384
384
MessageManager . messageTypes . Add ( "MLAPI_COMMAND" , 12 ) ;
385
385
MessageManager . messageTypes . Add ( "MLAPI_RPC" , 13 ) ;
386
386
MessageManager . messageTypes . Add ( "MLAPI_TARGET" , 14 ) ;
387
+ MessageManager . messageTypes . Add ( "MLAPI_SET_VISIBILITY" , 15 ) ;
387
388
388
389
List < MessageType > messageTypes = new List < MessageType > ( NetworkConfig . MessageTypes )
389
390
{
@@ -761,7 +762,7 @@ private void Update()
761
762
if ( NetworkConfig . ConnectionApproval )
762
763
writer . WriteByteArray ( NetworkConfig . ConnectionData ) ;
763
764
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 ) ;
765
766
}
766
767
}
767
768
break ;
@@ -1032,6 +1033,12 @@ private void HandleIncomingData(uint clientId, byte[] data, int channelId)
1032
1033
InternalMessageHandler . HandleTargetRpc ( clientId , incommingData , channelId ) ;
1033
1034
}
1034
1035
break ;
1036
+ case 15 :
1037
+ if ( isClient )
1038
+ {
1039
+ InternalMessageHandler . HandleSetVisibility ( clientId , incommingData , channelId ) ;
1040
+ }
1041
+ break ;
1035
1042
}
1036
1043
#endregion
1037
1044
}
@@ -1051,6 +1058,9 @@ internal void DisconnectClient(uint clientId)
1051
1058
if ( diffieHellmanPublicKeys . ContainsKey ( clientId ) )
1052
1059
diffieHellmanPublicKeys . Remove ( clientId ) ;
1053
1060
1061
+ foreach ( KeyValuePair < uint , NetworkedObject > pair in SpawnManager . spawnedObjects )
1062
+ pair . Value . observers . Remove ( clientId ) ;
1063
+
1054
1064
NetId netId = new NetId ( clientId ) ;
1055
1065
if ( netId . IsHost ( ) || netId . IsInvalid ( ) )
1056
1066
return ;
@@ -1080,10 +1090,13 @@ internal void OnClientDisconnect(uint clientId)
1080
1090
1081
1091
if ( isServer )
1082
1092
{
1093
+ foreach ( KeyValuePair < uint , NetworkedObject > pair in SpawnManager . spawnedObjects )
1094
+ pair . Value . observers . Remove ( clientId ) ;
1095
+
1083
1096
using ( BitWriter writer = new BitWriter ( ) )
1084
1097
{
1085
1098
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 ) ;
1087
1100
}
1088
1101
}
1089
1102
}
@@ -1098,7 +1111,7 @@ private void SyncTime()
1098
1111
1099
1112
byte [ ] buffer = writer . Finalize ( ) ;
1100
1113
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 ) ;
1102
1115
}
1103
1116
}
1104
1117
@@ -1147,7 +1160,7 @@ internal void HandleApproval(uint clientId, bool approved, Vector3 position, Qua
1147
1160
connectedClients [ clientId ] . PlayerObject = go ;
1148
1161
}
1149
1162
1150
- int amountOfObjectsToSend = SpawnManager . spawnedObjects . Values . Count ( ) ;
1163
+ int amountOfObjectsToSend = SpawnManager . spawnedObjects . Values . Count ;
1151
1164
1152
1165
using ( BitWriter writer = new BitWriter ( ) )
1153
1166
{
@@ -1179,12 +1192,15 @@ internal void HandleApproval(uint clientId, bool approved, Vector3 position, Qua
1179
1192
1180
1193
foreach ( KeyValuePair < uint , NetworkedObject > pair in SpawnManager . spawnedObjects )
1181
1194
{
1195
+ pair . Value . RebuildObservers ( clientId ) ; //Rebuilds observers for the new client
1196
+
1182
1197
writer . WriteBool ( pair . Value . isPlayerObject ) ;
1183
1198
writer . WriteUInt ( pair . Value . NetworkId ) ;
1184
1199
writer . WriteUInt ( pair . Value . OwnerClientId ) ;
1185
1200
writer . WriteInt ( NetworkConfig . NetworkPrefabIds [ pair . Value . NetworkedPrefabName ] ) ;
1186
1201
writer . WriteBool ( pair . Value . gameObject . activeInHierarchy ) ;
1187
1202
writer . WriteBool ( pair . Value . sceneObject == null ? true : pair . Value . sceneObject . Value ) ;
1203
+ writer . WriteBool ( pair . Value . observers . Contains ( clientId ) ) ;
1188
1204
1189
1205
writer . WriteFloat ( pair . Value . transform . position . x ) ;
1190
1206
writer . WriteFloat ( pair . Value . transform . position . y ) ;
@@ -1196,7 +1212,7 @@ internal void HandleApproval(uint clientId, bool approved, Vector3 position, Qua
1196
1212
}
1197
1213
}
1198
1214
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 ) ;
1200
1216
1201
1217
if ( OnClientConnectedCallback != null )
1202
1218
OnClientConnectedCallback . Invoke ( clientId ) ;
@@ -1213,6 +1229,7 @@ internal void HandleApproval(uint clientId, bool approved, Vector3 position, Qua
1213
1229
writer . WriteUInt ( clientId ) ;
1214
1230
writer . WriteInt ( - 1 ) ;
1215
1231
writer . WriteBool ( false ) ;
1232
+ writer . WriteBool ( connectedClients [ clientId ] . PlayerObject . GetComponent < NetworkedObject > ( ) . observers . Contains ( clientId ) ) ;
1216
1233
1217
1234
writer . WriteFloat ( connectedClients [ clientId ] . PlayerObject . transform . position . x ) ;
1218
1235
writer . WriteFloat ( connectedClients [ clientId ] . PlayerObject . transform . position . y ) ;
@@ -1227,7 +1244,7 @@ internal void HandleApproval(uint clientId, bool approved, Vector3 position, Qua
1227
1244
writer . WriteUInt ( clientId ) ;
1228
1245
}
1229
1246
1230
- InternalMessageHandler . Send ( "MLAPI_ADD_OBJECT" , "MLAPI_INTERNAL" , writer . Finalize ( ) , clientId ) ;
1247
+ InternalMessageHandler . Send ( "MLAPI_ADD_OBJECT" , "MLAPI_INTERNAL" , writer . Finalize ( ) , clientId , null ) ;
1231
1248
}
1232
1249
//Flush syncvars:
1233
1250
foreach ( KeyValuePair < uint , NetworkedObject > networkedObject in SpawnManager . spawnedObjects )
0 commit comments