Beispiel #1
0
        void OnMessageNetworkBehaviourInitialized(byte[] data, ulong steamID)
        {
            MessageNetworkBehaviourInitialized message = ByteSerializer.FromBytes <MessageNetworkBehaviourInitialized>(data);

            if (objectsFromServer.TryGetValue(message.networkID, out NetworkObject networkObject))
            {
                networkObject.HandleNetworkBehaviourInitializedMessage(message.index, steamID);
            }
            else
            {
                Debug.LogError(nameof(GameClient) + " does not have " + nameof(NetworkBehaviour) + " " + message.networkID + "[" + message.index + "] and therefore cannot be initialized!");
            }
        }
        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();
                }
            }
        }
Beispiel #4
0
        void OnMessageNetworkBehaviourInitialized(byte[] data, ulong steamID)
        {
            MessageNetworkBehaviourInitialized message = ByteSerializer.FromBytes <MessageNetworkBehaviourInitialized>(data);

            networkObjects[message.networkID].HandleNetworkBehaviourInitializedMessage(message.index, steamID);
        }