/// <summary> /// Shows a list of previously hidden objects to a client /// </summary> /// <param name="networkObjects">The objects to show</param> /// <param name="clientId">The client to show the objects to</param> /// <param name="payload">An optional payload to send as part of the spawns</param> public static void NetworkShow(List <NetworkObject> networkObjects, ulong clientId, Stream payload = null) { if (!NetworkManager.Singleton.IsServer) { throw new NotServerException("Only server can change visibility"); } // Do the safety loop first to prevent putting the MLAPI in an invalid state. for (int i = 0; i < networkObjects.Count; i++) { if (!networkObjects[i].IsSpawned) { throw new SpawnStateException("Object is not spawned"); } if (networkObjects[i].m_Observers.Contains(clientId)) { throw new VisibilityChangeException($"{nameof(NetworkObject)} with NetworkId: {networkObjects[i].NetworkObjectId} is already visible"); } } using (var buffer = PooledNetworkBuffer.Get()) using (var writer = PooledNetworkWriter.Get(buffer)) { writer.WriteUInt16Packed((ushort)networkObjects.Count); for (int i = 0; i < networkObjects.Count; i++) { // Send spawn call networkObjects[i].m_Observers.Add(clientId); NetworkSpawnManager.WriteSpawnCallForObject(buffer, clientId, networkObjects[i], payload); } InternalMessageSender.Send(clientId, NetworkConstants.ADD_OBJECTS, NetworkChannel.Internal, buffer); } }