IEnumerator SendNetworkBehaviourInitializedMessage() { while (!GameClient.Instance.IsInitialized()) { // Wait until all objects from the server spawned before sending the initialized message // The NetworkBehaviour could otherwise try to access objects that did not spawn yet yield return(new WaitForEndOfFrame()); } // The NetworkBehaviour on the server has to be sure that this object spawned and listens to messages from the server MessageNetworkBehaviourInitialized message = new MessageNetworkBehaviourInitialized(networkObject.networkID, index); NetworkManager.Instance.SendToServer(ByteSerializer.GetBytes(message), NetworkMessageType.NetworkBehaviourInitialized, SendType.Reliable); }
private void OnNetworkBehaviourInitialized(ulong steamID) { if (!initialized) { if (networkObject.onServer) { // Only initialize if all clients are ready bool allClientsReady = true; clientsReadyForInitialization.Add(steamID); ulong[] lobbyMemberIDs = NetworkManager.Instance.GetLobbyMemberIDs(); foreach (ulong id in lobbyMemberIDs) { if (!clientsReadyForInitialization.Contains(id)) { allClientsReady = false; break; } } if (allClientsReady) { // All clients are ready to be initialized, send a message to initialize all of them at the same time initialized = true; MessageNetworkBehaviourInitialized message = new MessageNetworkBehaviourInitialized(networkObject.networkID, index); NetworkManager.Instance.SendToAllClients(ByteSerializer.GetBytes(message), NetworkMessageType.NetworkBehaviourInitialized, SendType.Reliable); StartServer(); } } else { initialized = true; StartClient(); } } }