Inheritance: NetworkBehaviour
 private void OnValidate()
 {
     if (this.m_MaxPlayers <= 0)
     {
         this.m_MaxPlayers = 1;
     }
     if (this.m_MaxPlayersPerConnection <= 0)
     {
         this.m_MaxPlayersPerConnection = 1;
     }
     if (this.m_MaxPlayersPerConnection > this.maxPlayers)
     {
         this.m_MaxPlayersPerConnection = this.maxPlayers;
     }
     if (this.m_MinPlayers < 0)
     {
         this.m_MinPlayers = 0;
     }
     if (this.m_MinPlayers > this.m_MaxPlayers)
     {
         this.m_MinPlayers = this.m_MaxPlayers;
     }
     if ((Object)this.m_LobbyPlayerPrefab != (Object)null && (Object)this.m_LobbyPlayerPrefab.GetComponent <NetworkIdentity>() == (Object)null)
     {
         this.m_LobbyPlayerPrefab = (NetworkLobbyPlayer)null;
         Debug.LogWarning((object)"LobbyPlayer prefab must have a NetworkIdentity component.");
     }
     if (!((Object)this.m_GamePlayerPrefab != (Object)null) || !((Object)this.m_GamePlayerPrefab.GetComponent <NetworkIdentity>() == (Object)null))
     {
         return;
     }
     this.m_GamePlayerPrefab = (GameObject)null;
     Debug.LogWarning((object)"GamePlayer prefab must have a NetworkIdentity component.");
 }
Beispiel #2
0
        private void OnServerReadyToBeginMessage(NetworkMessage netMsg)
        {
            if (LogFilter.logDebug)
            {
                Debug.Log("NetworkLobbyManager OnServerReadyToBeginMessage");
            }
            netMsg.ReadMessage(s_ReadyToBeginMessage);
            if (!netMsg.conn.GetPlayerController(s_ReadyToBeginMessage.slotId, out PlayerController playerController))
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("NetworkLobbyManager OnServerReadyToBeginMessage invalid playerControllerId " + s_ReadyToBeginMessage.slotId);
                }
                return;
            }
            NetworkLobbyPlayer component = playerController.gameObject.GetComponent <NetworkLobbyPlayer>();

            component.readyToBegin = s_ReadyToBeginMessage.readyState;
            LobbyReadyToBeginMessage lobbyReadyToBeginMessage = new LobbyReadyToBeginMessage();

            lobbyReadyToBeginMessage.slotId     = component.slot;
            lobbyReadyToBeginMessage.readyState = s_ReadyToBeginMessage.readyState;
            NetworkServer.SendToReady(null, 43, lobbyReadyToBeginMessage);
            CheckReadyToBegin();
        }
Beispiel #3
0
        private void OnClientReadyToBegin(NetworkMessage netMsg)
        {
            netMsg.ReadMessage(s_LobbyReadyToBeginMessage);
            if (s_LobbyReadyToBeginMessage.slotId >= lobbySlots.Count())
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("NetworkLobbyManager OnClientReadyToBegin invalid lobby slot " + s_LobbyReadyToBeginMessage.slotId);
                }
                return;
            }
            NetworkLobbyPlayer networkLobbyPlayer = lobbySlots[s_LobbyReadyToBeginMessage.slotId];

            if (networkLobbyPlayer == null || networkLobbyPlayer.gameObject == null)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("NetworkLobbyManager OnClientReadyToBegin no player at lobby slot " + s_LobbyReadyToBeginMessage.slotId);
                }
            }
            else
            {
                networkLobbyPlayer.readyToBegin = s_LobbyReadyToBeginMessage.readyState;
                networkLobbyPlayer.OnClientReady(s_LobbyReadyToBeginMessage.readyState);
            }
        }
Beispiel #4
0
 private void OnClientReadyToBegin(NetworkMessage netMsg)
 {
     netMsg.ReadMessage <LobbyReadyToBeginMessage>(NetworkLobbyManager.s_LobbyReadyToBeginMessage);
     if ((int)NetworkLobbyManager.s_LobbyReadyToBeginMessage.slotId >= this.lobbySlots.Count <NetworkLobbyPlayer>())
     {
         if (LogFilter.logError)
         {
             Debug.LogError("NetworkLobbyManager OnClientReadyToBegin invalid lobby slot " + NetworkLobbyManager.s_LobbyReadyToBeginMessage.slotId);
         }
     }
     else
     {
         NetworkLobbyPlayer networkLobbyPlayer = this.lobbySlots[(int)NetworkLobbyManager.s_LobbyReadyToBeginMessage.slotId];
         if (networkLobbyPlayer == null || networkLobbyPlayer.gameObject == null)
         {
             if (LogFilter.logError)
             {
                 Debug.LogError("NetworkLobbyManager OnClientReadyToBegin no player at lobby slot " + NetworkLobbyManager.s_LobbyReadyToBeginMessage.slotId);
             }
         }
         else
         {
             networkLobbyPlayer.readyToBegin = NetworkLobbyManager.s_LobbyReadyToBeginMessage.readyState;
             networkLobbyPlayer.OnClientReady(NetworkLobbyManager.s_LobbyReadyToBeginMessage.readyState);
         }
     }
 }
        private void OnServerReadyToBeginMessage(NetworkMessage netMsg)
        {
            if (LogFilter.logDebug)
            {
                Debug.Log((object)"NetworkLobbyManager OnServerReadyToBeginMessage");
            }
            netMsg.ReadMessage <LobbyReadyToBeginMessage>(NetworkLobbyManager.s_ReadyToBeginMessage);
            PlayerController playerController;

            if (!netMsg.conn.GetPlayerController((short)NetworkLobbyManager.s_ReadyToBeginMessage.slotId, out playerController))
            {
                if (!LogFilter.logError)
                {
                    return;
                }
                Debug.LogError((object)("NetworkLobbyManager OnServerReadyToBeginMessage invalid playerControllerId " + (object)NetworkLobbyManager.s_ReadyToBeginMessage.slotId));
            }
            else
            {
                NetworkLobbyPlayer component = playerController.gameObject.GetComponent <NetworkLobbyPlayer>();
                component.readyToBegin = NetworkLobbyManager.s_ReadyToBeginMessage.readyState;
                NetworkServer.SendToReady((GameObject)null, (short)43, (MessageBase) new LobbyReadyToBeginMessage()
                {
                    slotId     = component.slot,
                    readyState = NetworkLobbyManager.s_ReadyToBeginMessage.readyState
                });
                this.CheckReadyToBegin();
            }
        }
Beispiel #6
0
        private void SceneLoadedForPlayer(NetworkConnection conn, GameObject lobbyPlayerGameObject)
        {
            NetworkLobbyPlayer component = lobbyPlayerGameObject.GetComponent <NetworkLobbyPlayer>();

            if (component == null)
            {
                return;
            }
            string name = SceneManager.GetSceneAt(0).name;

            if (LogFilter.logDebug)
            {
                Debug.Log("NetworkLobby SceneLoadedForPlayer scene:" + name + " " + conn);
            }
            if (name == m_LobbyScene)
            {
                PendingPlayer item = default(PendingPlayer);
                item.conn        = conn;
                item.lobbyPlayer = lobbyPlayerGameObject;
                m_PendingPlayers.Add(item);
                return;
            }
            short      playerControllerId = lobbyPlayerGameObject.GetComponent <NetworkIdentity>().playerControllerId;
            GameObject gameObject         = OnLobbyServerCreateGamePlayer(conn, playerControllerId);

            if (gameObject == null)
            {
                Transform startPosition = GetStartPosition();
                gameObject = ((!(startPosition != null)) ? Object.Instantiate(gamePlayerPrefab, Vector3.zero, Quaternion.identity) : Object.Instantiate(gamePlayerPrefab, startPosition.position, startPosition.rotation));
            }
            if (OnLobbyServerSceneLoadedForPlayer(lobbyPlayerGameObject, gameObject))
            {
                NetworkServer.ReplacePlayerForConnection(conn, gameObject, playerControllerId);
            }
        }
 private void OnClientReadyToBegin(NetworkMessage netMsg)
 {
     netMsg.ReadMessage <LobbyReadyToBeginMessage>(NetworkLobbyManager.s_LobbyReadyToBeginMessage);
     if ((int)NetworkLobbyManager.s_LobbyReadyToBeginMessage.slotId >= ((IEnumerable <NetworkLobbyPlayer>) this.lobbySlots).Count <NetworkLobbyPlayer>())
     {
         if (!LogFilter.logError)
         {
             return;
         }
         Debug.LogError((object)("NetworkLobbyManager OnClientReadyToBegin invalid lobby slot " + (object)NetworkLobbyManager.s_LobbyReadyToBeginMessage.slotId));
     }
     else
     {
         NetworkLobbyPlayer lobbySlot = this.lobbySlots[(int)NetworkLobbyManager.s_LobbyReadyToBeginMessage.slotId];
         if ((Object)lobbySlot == (Object)null || (Object)lobbySlot.gameObject == (Object)null)
         {
             if (!LogFilter.logError)
             {
                 return;
             }
             Debug.LogError((object)("NetworkLobbyManager OnClientReadyToBegin no player at lobby slot " + (object)NetworkLobbyManager.s_LobbyReadyToBeginMessage.slotId));
         }
         else
         {
             lobbySlot.readyToBegin = NetworkLobbyManager.s_LobbyReadyToBeginMessage.readyState;
             lobbySlot.OnClientReady(NetworkLobbyManager.s_LobbyReadyToBeginMessage.readyState);
         }
     }
 }
Beispiel #8
0
 private void OnValidate()
 {
     if (this.m_MaxPlayers <= 0)
     {
         this.m_MaxPlayers = 1;
     }
     if (this.m_MaxPlayersPerConnection <= 0)
     {
         this.m_MaxPlayersPerConnection = 1;
     }
     if (this.m_MaxPlayersPerConnection > this.maxPlayers)
     {
         this.m_MaxPlayersPerConnection = this.maxPlayers;
     }
     if (this.m_MinPlayers < 0)
     {
         this.m_MinPlayers = 0;
     }
     if (this.m_MinPlayers > this.m_MaxPlayers)
     {
         this.m_MinPlayers = this.m_MaxPlayers;
     }
     if ((this.m_LobbyPlayerPrefab != null) && (this.m_LobbyPlayerPrefab.GetComponent <NetworkIdentity>() == null))
     {
         this.m_LobbyPlayerPrefab = null;
         Debug.LogWarning("LobbyPlayer prefab must have a NetworkIdentity component.");
     }
     if ((this.m_GamePlayerPrefab != null) && (this.m_GamePlayerPrefab.GetComponent <NetworkIdentity>() == null))
     {
         this.m_GamePlayerPrefab = null;
         Debug.LogWarning("GamePlayer prefab must have a NetworkIdentity component.");
     }
 }
Beispiel #9
0
        private void OnServerReadyToBeginMessage(NetworkMessage netMsg)
        {
            PlayerController controller;

            if (LogFilter.logDebug)
            {
                Debug.Log("NetworkLobbyManager OnServerReadyToBeginMessage");
            }
            netMsg.ReadMessage <LobbyReadyToBeginMessage>(s_ReadyToBeginMessage);
            if (!netMsg.conn.GetPlayerController(s_ReadyToBeginMessage.slotId, out controller))
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("NetworkLobbyManager OnServerReadyToBeginMessage invalid playerControllerId " + s_ReadyToBeginMessage.slotId);
                }
            }
            else
            {
                NetworkLobbyPlayer component = controller.gameObject.GetComponent <NetworkLobbyPlayer>();
                component.readyToBegin = s_ReadyToBeginMessage.readyState;
                LobbyReadyToBeginMessage msg = new LobbyReadyToBeginMessage {
                    slotId     = component.slot,
                    readyState = s_ReadyToBeginMessage.readyState
                };
                NetworkServer.SendToReady(null, 0x2b, msg);
                this.CheckReadyToBegin();
            }
        }
 public override void ServerChangeScene(string sceneName)
 {
     if (sceneName == this.m_LobbyScene)
     {
         NetworkLobbyPlayer[] array = this.lobbySlots;
         for (int i = 0; i < array.Length; i++)
         {
             NetworkLobbyPlayer networkLobbyPlayer = array[i];
             if (!(networkLobbyPlayer == null))
             {
                 NetworkIdentity  component = networkLobbyPlayer.GetComponent <NetworkIdentity>();
                 PlayerController playerController;
                 if (component.connectionToClient.GetPlayerController(component.playerControllerId, out playerController))
                 {
                     NetworkServer.Destroy(playerController.gameObject);
                 }
                 if (NetworkServer.active)
                 {
                     networkLobbyPlayer.GetComponent <NetworkLobbyPlayer>().readyToBegin = false;
                     NetworkServer.ReplacePlayerForConnection(component.connectionToClient, networkLobbyPlayer.gameObject, component.playerControllerId);
                 }
             }
         }
     }
     base.ServerChangeScene(sceneName);
 }
	public void Update()
	{
		CurrentLocalPlayer = UILobbyManager.LocalLobbyPlayer;

		if(SyncEveryFrame) {
			SyncReadyState();
		}
	}
Beispiel #12
0
 private void CallOnClientExitLobby()
 {
     this.OnLobbyClientExit();
     for (int i = 0; i < this.lobbySlots.Length; i++)
     {
         NetworkLobbyPlayer networkLobbyPlayer = this.lobbySlots[i];
         if (!(networkLobbyPlayer == null))
         {
             networkLobbyPlayer.OnClientExitLobby();
         }
     }
 }
        public override void OnServerAddPlayer(NetworkConnection conn, short playerControllerId)
        {
            if (SceneManager.GetSceneAt(0).name != this.m_LobbyScene)
            {
                return;
            }
            int num = 0;

            using (List <PlayerController> .Enumerator enumerator = conn.playerControllers.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    if (enumerator.Current.IsValid)
                    {
                        ++num;
                    }
                }
            }
            if (num >= this.maxPlayersPerConnection)
            {
                if (LogFilter.logWarn)
                {
                    Debug.LogWarning((object)"NetworkLobbyManager no more players for this connection.");
                }
                EmptyMessage emptyMessage = new EmptyMessage();
                conn.Send((short)45, (MessageBase)emptyMessage);
            }
            else
            {
                byte slot = this.FindSlot();
                if ((int)slot == (int)byte.MaxValue)
                {
                    if (LogFilter.logWarn)
                    {
                        Debug.LogWarning((object)"NetworkLobbyManager no space for more players");
                    }
                    EmptyMessage emptyMessage = new EmptyMessage();
                    conn.Send((short)45, (MessageBase)emptyMessage);
                }
                else
                {
                    GameObject player = this.OnLobbyServerCreateLobbyPlayer(conn, playerControllerId);
                    if ((Object)player == (Object)null)
                    {
                        player = (GameObject)Object.Instantiate((Object)this.lobbyPlayerPrefab.gameObject, Vector3.zero, Quaternion.identity);
                    }
                    NetworkLobbyPlayer component = player.GetComponent <NetworkLobbyPlayer>();
                    component.slot             = slot;
                    this.lobbySlots[(int)slot] = component;
                    NetworkServer.AddPlayerForConnection(conn, player, playerControllerId);
                }
            }
        }
Beispiel #14
0
 private void CallOnClientEnterLobby()
 {
     this.OnLobbyClientEnter();
     for (int i = 0; i < this.lobbySlots.Length; i++)
     {
         NetworkLobbyPlayer networkLobbyPlayer = this.lobbySlots[i];
         if (!(networkLobbyPlayer == null))
         {
             networkLobbyPlayer.readyToBegin = false;
             networkLobbyPlayer.OnClientEnterLobby();
         }
     }
 }
Beispiel #15
0
        public override void OnServerAddPlayer(NetworkConnection conn, short playerControllerId)
        {
            string name = SceneManager.GetSceneAt(0).name;

            if (name != m_LobbyScene)
            {
                return;
            }
            int num = 0;

            for (int i = 0; i < conn.playerControllers.Count; i++)
            {
                if (conn.playerControllers[i].IsValid)
                {
                    num++;
                }
            }
            if (num >= maxPlayersPerConnection)
            {
                if (LogFilter.logWarn)
                {
                    Debug.LogWarning("NetworkLobbyManager no more players for this connection.");
                }
                EmptyMessage msg = new EmptyMessage();
                conn.Send(45, msg);
                return;
            }
            byte b = FindSlot();

            if (b == byte.MaxValue)
            {
                if (LogFilter.logWarn)
                {
                    Debug.LogWarning("NetworkLobbyManager no space for more players");
                }
                EmptyMessage msg2 = new EmptyMessage();
                conn.Send(45, msg2);
                return;
            }
            GameObject gameObject = OnLobbyServerCreateLobbyPlayer(conn, playerControllerId);

            if (gameObject == null)
            {
                gameObject = Object.Instantiate(lobbyPlayerPrefab.gameObject, Vector3.zero, Quaternion.identity);
            }
            NetworkLobbyPlayer component = gameObject.GetComponent <NetworkLobbyPlayer>();

            component.slot = b;
            lobbySlots[b]  = component;
            NetworkServer.AddPlayerForConnection(conn, gameObject, playerControllerId);
        }
Beispiel #16
0
 public override void OnServerDisconnect(NetworkConnection conn)
 {
     base.OnServerDisconnect(conn);
     for (int i = 0; i < this.lobbySlots.Length; i++)
     {
         NetworkLobbyPlayer player = this.lobbySlots[i];
         if ((player != null) && (player.connectionToClient == conn))
         {
             this.lobbySlots[i] = null;
             NetworkServer.Destroy(player.gameObject);
         }
     }
     this.OnLobbyServerDisconnect(conn);
 }
 public override void OnServerDisconnect(NetworkConnection conn)
 {
     base.OnServerDisconnect(conn);
     for (int index = 0; index < this.lobbySlots.Length; ++index)
     {
         NetworkLobbyPlayer lobbySlot = this.lobbySlots[index];
         if (!((Object)lobbySlot == (Object)null) && lobbySlot.connectionToClient == conn)
         {
             this.lobbySlots[index] = (NetworkLobbyPlayer)null;
             NetworkServer.Destroy(lobbySlot.gameObject);
         }
     }
     this.OnLobbyServerDisconnect(conn);
 }
Beispiel #18
0
 public override void OnServerDisconnect(NetworkConnection conn)
 {
     base.OnServerDisconnect(conn);
     for (int i = 0; i < lobbySlots.Length; i++)
     {
         NetworkLobbyPlayer networkLobbyPlayer = lobbySlots[i];
         if (!(networkLobbyPlayer == null) && networkLobbyPlayer.connectionToClient == conn)
         {
             lobbySlots[i] = null;
             NetworkServer.Destroy(networkLobbyPlayer.gameObject);
         }
     }
     OnLobbyServerDisconnect(conn);
 }
        public override void OnServerAddPlayer(NetworkConnection conn, short playerControllerId)
        {
            if (Application.loadedLevelName != this.m_LobbyScene)
            {
                return;
            }
            int num = 0;

            foreach (PlayerController current in conn.playerControllers)
            {
                if (current.IsValid)
                {
                    num++;
                }
            }
            if (num >= this.maxPlayersPerConnection)
            {
                if (LogFilter.logWarn)
                {
                    Debug.LogWarning("NetworkLobbyManager no more players for this connection.");
                }
                EmptyMessage msg = new EmptyMessage();
                conn.Send(45, msg);
                return;
            }
            byte b = this.FindSlot();

            if (b == 255)
            {
                if (LogFilter.logWarn)
                {
                    Debug.LogWarning("NetworkLobbyManager no space for more players");
                }
                EmptyMessage msg2 = new EmptyMessage();
                conn.Send(45, msg2);
                return;
            }
            GameObject gameObject = this.OnLobbyServerCreateLobbyPlayer(conn, playerControllerId);

            if (gameObject == null)
            {
                gameObject = (GameObject)UnityEngine.Object.Instantiate(this.lobbyPlayerPrefab.gameObject, Vector3.zero, Quaternion.identity);
            }
            NetworkLobbyPlayer component = gameObject.GetComponent <NetworkLobbyPlayer>();

            component.slot          = b;
            this.lobbySlots[(int)b] = component;
            NetworkServer.AddPlayerForConnection(conn, gameObject, playerControllerId);
        }
 private static bool CheckConnectionIsReadyToBegin(NetworkConnection conn)
 {
     foreach (PlayerController current in conn.playerControllers)
     {
         if (current.IsValid)
         {
             NetworkLobbyPlayer component = current.gameObject.GetComponent <NetworkLobbyPlayer>();
             if (!component.readyToBegin)
             {
                 return(false);
             }
         }
     }
     return(true);
 }
Beispiel #21
0
 public override void OnServerAddPlayer(NetworkConnection conn, short playerControllerId)
 {
     if (Application.loadedLevelName == this.m_LobbyScene)
     {
         int num = 0;
         foreach (PlayerController controller in conn.playerControllers)
         {
             if (controller.IsValid)
             {
                 num++;
             }
         }
         if (num >= this.maxPlayersPerConnection)
         {
             if (LogFilter.logWarn)
             {
                 Debug.LogWarning("NetworkLobbyManager no more players for this connection.");
             }
             EmptyMessage msg = new EmptyMessage();
             conn.Send(0x2d, msg);
         }
         else
         {
             byte index = this.FindSlot();
             if (index == 0xff)
             {
                 if (LogFilter.logWarn)
                 {
                     Debug.LogWarning("NetworkLobbyManager no space for more players");
                 }
                 EmptyMessage message2 = new EmptyMessage();
                 conn.Send(0x2d, message2);
             }
             else
             {
                 GameObject obj2 = this.OnLobbyServerCreateLobbyPlayer(conn, playerControllerId);
                 if (obj2 == null)
                 {
                     obj2 = (GameObject)UnityEngine.Object.Instantiate(this.lobbyPlayerPrefab.gameObject, Vector3.zero, Quaternion.identity);
                 }
                 NetworkLobbyPlayer component = obj2.GetComponent <NetworkLobbyPlayer>();
                 component.slot         = index;
                 this.lobbySlots[index] = component;
                 NetworkServer.AddPlayerForConnection(conn, obj2, playerControllerId);
             }
         }
     }
 }
	public static GameObject AddToPlayerList(NetworkLobbyPlayer lobbyPlayer)
	{
		if(singleton && singleton.PlayerListPrefab && singleton.PlayerListContentAnchor) {
			GameObject playerListObject = (GameObject)Instantiate(singleton.PlayerListPrefab, Vector3.zero, Quaternion.identity);

			RectTransform child = playerListObject.GetComponent<RectTransform>();
			child.SetParent(singleton.PlayerListContentAnchor, false);

			UIPlayerListingEntry entry = playerListObject.GetComponent<UIPlayerListingEntry>();
			entry.Player = lobbyPlayer;

			return playerListObject;
		} else {
			return null;
		}
	}
Beispiel #23
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.");
                }
            }
        }
        private void SceneLoadedForPlayer(NetworkConnection conn, GameObject lobbyPlayerGameObject)
        {
            NetworkLobbyPlayer component = lobbyPlayerGameObject.GetComponent <NetworkLobbyPlayer>();

            if (component == null)
            {
                return;
            }
            if (LogFilter.logDebug)
            {
                Debug.Log(string.Concat(new object[]
                {
                    "NetworkLobby SceneLoadedForPlayer scene:",
                    Application.loadedLevelName,
                    " ",
                    conn
                }));
            }
            if (Application.loadedLevelName == this.m_LobbyScene)
            {
                NetworkLobbyManager.PendingPlayer item;
                item.conn        = conn;
                item.lobbyPlayer = lobbyPlayerGameObject;
                this.m_PendingPlayers.Add(item);
                return;
            }
            short      playerControllerId = lobbyPlayerGameObject.GetComponent <NetworkIdentity>().playerControllerId;
            GameObject gameObject         = this.OnLobbyServerCreateGamePlayer(conn, playerControllerId);

            if (gameObject == null)
            {
                Transform startPosition = base.GetStartPosition();
                if (startPosition != null)
                {
                    gameObject = (GameObject)UnityEngine.Object.Instantiate(this.gamePlayerPrefab, startPosition.position, startPosition.rotation);
                }
                else
                {
                    gameObject = (GameObject)UnityEngine.Object.Instantiate(this.gamePlayerPrefab, Vector3.zero, Quaternion.identity);
                }
            }
            if (!this.OnLobbyServerSceneLoadedForPlayer(lobbyPlayerGameObject, gameObject))
            {
                return;
            }
            NetworkServer.ReplacePlayerForConnection(conn, gameObject, playerControllerId);
        }
Beispiel #25
0
        private static int CheckConnectionIsReadyToBegin(NetworkConnection conn)
        {
            int num = 0;

            for (int i = 0; i < conn.playerControllers.Count; i++)
            {
                PlayerController playerController = conn.playerControllers[i];
                if (playerController.IsValid)
                {
                    NetworkLobbyPlayer component = playerController.gameObject.GetComponent <NetworkLobbyPlayer>();
                    if (component.readyToBegin)
                    {
                        num++;
                    }
                }
            }
            return(num);
        }
Beispiel #26
0
        public override void OnServerRemovePlayer(NetworkConnection conn, PlayerController player)
        {
            short playerControllerId = player.playerControllerId;
            byte  slot = player.gameObject.GetComponent <NetworkLobbyPlayer>().slot;

            this.lobbySlots[(int)slot] = null;
            base.OnServerRemovePlayer(conn, player);
            for (int i = 0; i < this.lobbySlots.Length; i++)
            {
                NetworkLobbyPlayer networkLobbyPlayer = this.lobbySlots[i];
                if (networkLobbyPlayer != null)
                {
                    networkLobbyPlayer.GetComponent <NetworkLobbyPlayer>().readyToBegin = false;
                    NetworkLobbyManager.s_LobbyReadyToBeginMessage.slotId     = networkLobbyPlayer.slot;
                    NetworkLobbyManager.s_LobbyReadyToBeginMessage.readyState = false;
                    NetworkServer.SendToReady(null, 43, NetworkLobbyManager.s_LobbyReadyToBeginMessage);
                }
            }
            this.OnLobbyServerPlayerRemoved(conn, playerControllerId);
        }
 void Start ()
 {
     networkLobbyPlayer = GetComponent<NetworkLobbyPlayer>();
     
     switch(networkLobbyPlayer.slot) {
         case 0:
             transform.position = new Vector3(-2,0.5f,2);
             GetComponent<Renderer>().material.color = Color.red;
             break;
         case 1:
             transform.position = new Vector3(2,0.5f,2);
             GetComponent<Renderer>().material.color = Color.green;
             break;
         case 2:
             transform.position = new Vector3(2,0.5f,-2);
             GetComponent<Renderer>().material.color = Color.blue;
             break;
         case 3:
             transform.position = new Vector3(-2,0.5f,-2);
             GetComponent<Renderer>().material.color = Color.yellow;
             break;
     }
 }
 private void OnValidate()
 {
   if (this.m_MaxPlayers <= 0)
     this.m_MaxPlayers = 1;
   if (this.m_MaxPlayersPerConnection <= 0)
     this.m_MaxPlayersPerConnection = 1;
   if (this.m_MaxPlayersPerConnection > this.maxPlayers)
     this.m_MaxPlayersPerConnection = this.maxPlayers;
   if (this.m_MinPlayers < 0)
     this.m_MinPlayers = 0;
   if (this.m_MinPlayers > this.m_MaxPlayers)
     this.m_MinPlayers = this.m_MaxPlayers;
   if ((Object) this.m_LobbyPlayerPrefab != (Object) null && (Object) this.m_LobbyPlayerPrefab.GetComponent<NetworkIdentity>() == (Object) null)
   {
     this.m_LobbyPlayerPrefab = (NetworkLobbyPlayer) null;
     Debug.LogWarning((object) "LobbyPlayer prefab must have a NetworkIdentity component.");
   }
   if (!((Object) this.m_GamePlayerPrefab != (Object) null) || !((Object) this.m_GamePlayerPrefab.GetComponent<NetworkIdentity>() == (Object) null))
     return;
   this.m_GamePlayerPrefab = (GameObject) null;
   Debug.LogWarning((object) "GamePlayer prefab must have a NetworkIdentity component.");
 }
Beispiel #29
0
	void Awake()
	{
		cc = GetComponent<ColorControl>();
		lobbyPlayer = GetComponent<NetworkLobbyPlayer>();
		Debug.Log ("PlayerLobby Awake");
	}
 void Awake()
 {
     lobbyPlayer = GetComponent<NetworkLobbyPlayer>();
 }
 void Awake()
 {
     cc = GetComponent<ColorControl>();
     lobbyPlayer = GetComponent<NetworkLobbyPlayer>();
 }
Beispiel #32
0
	void Awake()
	{
		lobbyPlayer = GetComponent<NetworkLobbyPlayer>();
		playerUI = GetComponent<PlayerLobby>();
	}
    public override void OnStopServer()
    {
        Debug.Log ("Stopping Server...");

        //clean up ports
        PortMapper pmapper = GetComponent<PortMapper> ();

        if (pmapper != null)
        {
            pmapper.Stop();
        }

        //clean up lobby players
        lobbySlots = new NetworkLobbyPlayer[maxPlayers];
    }