Exemplo n.º 1
0
        /// <summary>
        /// Called on the server when a client disconnects.
        /// <para>This is called on the Server when a Client disconnects from the Server. Use an override to decide what should happen when a disconnection is detected.</para>
        /// </summary>
        /// <param name="conn">Connection from client.</param>
        public override void OnServerDisconnect(NetworkConnection conn)
        {
            if (conn.identity != null)
            {
                NobleRoomPlayer roomPlayer = conn.identity.GetComponent <NobleRoomPlayer>();

                if (roomPlayer != null)
                {
                    roomSlots.Remove(roomPlayer);
                }

                foreach (NetworkIdentity clientOwnedObject in conn.clientOwnedObjects)
                {
                    roomPlayer = clientOwnedObject.GetComponent <NobleRoomPlayer>();
                    if (roomPlayer != null)
                    {
                        roomSlots.Remove(roomPlayer);
                    }
                }
            }

            allPlayersReady = false;

            foreach (NobleRoomPlayer player in roomSlots)
            {
                if (player != null)
                {
                    player.GetComponent <NobleRoomPlayer>().readyToBegin = false;
                }
            }

            if (IsSceneActive(RoomScene))
            {
                RecalculateRoomPlayerIndices();
            }

            OnRoomServerDisconnect(conn);
            base.OnServerDisconnect(conn);
        }
Exemplo n.º 2
0
        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 (roomPlayerPrefab != null)
            {
                NetworkIdentity identity = roomPlayerPrefab.GetComponent <NetworkIdentity>();
                if (identity == null)
                {
                    roomPlayerPrefab = null;
                    Debug.LogError("RoomPlayer prefab must have a NetworkIdentity component.");
                }
            }

            base.OnValidate();
        }