private void SpawnInternal(Stream spawnPayload, bool destroyWithScene, ulong?ownerClientId, bool playerObject) { if (!NetworkManager.Singleton.IsListening) { throw new NotListeningException($"{nameof(NetworkManager)} isn't listening, start a server or host before spawning objects."); } if (!NetworkManager.Singleton.IsServer) { throw new NotServerException($"Only server can spawn {nameof(NetworkObject)}s"); } if (spawnPayload != null) { spawnPayload.Position = 0; } NetworkSpawnManager.SpawnNetworkObjectLocally(this, NetworkSpawnManager.GetNetworkObjectId(), false, playerObject, ownerClientId, spawnPayload, spawnPayload != null, spawnPayload == null ? 0 : (int)spawnPayload.Length, false, destroyWithScene); for (int i = 0; i < NetworkManager.Singleton.ConnectedClientsList.Count; i++) { if (m_Observers.Contains(NetworkManager.Singleton.ConnectedClientsList[i].ClientId)) { NetworkSpawnManager.SendSpawnCallForObject(NetworkManager.Singleton.ConnectedClientsList[i].ClientId, this, spawnPayload); } } }
/// <summary> /// Shows a previously hidden object to a client /// </summary> /// <param name="clientId">The client to show the object to</param> /// <param name="payload">An optional payload to send as part of the spawn</param> public void NetworkShow(ulong clientId, Stream payload = null) { if (!IsSpawned) { throw new SpawnStateException("Object is not spawned"); } if (!NetworkManager.Singleton.IsServer) { throw new NotServerException("Only server can change visibility"); } if (m_Observers.Contains(clientId)) { throw new VisibilityChangeException("The object is already visible"); } // Send spawn call m_Observers.Add(clientId); NetworkSpawnManager.SendSpawnCallForObject(clientId, this, payload); }