public override void OnServerDisconnect(NetworkConnection conn)
        {
            if (conn.playerController != null)
            {
                NetworkLobbyPlayer player = conn.playerController.GetComponent <NetworkLobbyPlayer>();

                if (player != null)
                {
                    lobbySlots.Remove(player);
                }
            }

            allPlayersReady = false;

            foreach (NetworkLobbyPlayer player in lobbySlots)
            {
                if (player != null)
                {
                    player.GetComponent <NetworkLobbyPlayer>().ReadyToBegin = false;
                }
            }

            if (SceneManager.GetActiveScene().name == LobbyScene)
            {
                RecalculateLobbyPlayerIndices();
            }

            base.OnServerDisconnect(conn);
            OnLobbyServerDisconnect(conn);
        }
        public override void OnServerAddPlayer(NetworkConnection conn, AddPlayerMessage extraMessage)
        {
            if (SceneManager.GetActiveScene().name != LobbyScene)
            {
                return;
            }

            if (lobbySlots.Count == maxConnections)
            {
                return;
            }

            allPlayersReady = false;

            if (LogFilter.Debug)
            {
                Debug.LogFormat("NetworkLobbyManager.OnServerAddPlayer playerPrefab:{0}", lobbyPlayerPrefab.name);
            }

            GameObject newLobbyGameObject = OnLobbyServerCreateLobbyPlayer(conn);

            if (newLobbyGameObject == null)
            {
                newLobbyGameObject = (GameObject)Instantiate(lobbyPlayerPrefab.gameObject, Vector3.zero, Quaternion.identity);
            }

            NetworkLobbyPlayer newLobbyPlayer = newLobbyGameObject.GetComponent <NetworkLobbyPlayer>();

            lobbySlots.Add(newLobbyPlayer);

            RecalculateLobbyPlayerIndices();

            NetworkServer.AddPlayerForConnection(conn, newLobbyGameObject);
        }
Ejemplo n.º 3
0
        void OnValidate()
        {
            if (m_MaxPlayers <= 0)
            {
                m_MaxPlayers = 1;
            }

            if (m_MaxPlayersPerConnection <= 0)
            {
                m_MaxPlayersPerConnection = 1;
            }

            if (m_MaxPlayersPerConnection > maxPlayers)
            {
                m_MaxPlayersPerConnection = maxPlayers;
            }

            if (m_MinPlayers < 0)
            {
                m_MinPlayers = 0;
            }

            if (m_MinPlayers > m_MaxPlayers)
            {
                m_MinPlayers = m_MaxPlayers;
            }

            if (m_LobbyPlayerPrefab != null)
            {
                var uv = m_LobbyPlayerPrefab.GetComponent <NetworkIdentity>();
                if (uv == null)
                {
                    m_LobbyPlayerPrefab = null;
                    Debug.LogWarning("LobbyPlayer prefab must have a NetworkIdentity component.");
                }
            }

            if (m_GamePlayerPrefab != null)
            {
                var uv = m_GamePlayerPrefab.GetComponent <NetworkIdentity>();
                if (uv == null)
                {
                    m_GamePlayerPrefab = null;
                    Debug.LogWarning("GamePlayer prefab must have a NetworkIdentity component.");
                }
            }
        }
        public override void OnValidate()
        {
            // always >= 0
            maxConnections = Mathf.Max(maxConnections, 0);

            // always <= maxConnections
            minPlayers = Mathf.Min(minPlayers, maxConnections);

            // always >= 0
            minPlayers = Mathf.Max(minPlayers, 0);

            if (lobbyPlayerPrefab != null)
            {
                NetworkIdentity identity = lobbyPlayerPrefab.GetComponent <NetworkIdentity>();
                if (identity == null)
                {
                    lobbyPlayerPrefab = null;
                    Debug.LogError("LobbyPlayer prefab must have a NetworkIdentity component.");
                }
            }

            base.OnValidate();
        }