Ejemplo n.º 1
0
        /// <summary>
        /// Starts the <see cref="LobbyState"/>.
        /// </summary>
        public override void Start()
        {
            connectingPanel = Auxiliary.FindGameObject("ConnectingPanel");
            startButton     = Auxiliary.FindGameObject("StartButton");
            fieldButton     = GameObject.Find("FieldButton").GetComponent <Button>();
            lobbyCodeText   = GameObject.Find("LobbyCodeText").GetComponent <Text>();
            fieldText       = GameObject.Find("FieldButton").GetComponent <Text>();
            readyText       = GameObject.Find("ReadyText").GetComponent <Text>();

            connectingPanel.SetActive(false);
            startButton.SetActive(false);

            MultiplayerNetwork network = MultiplayerNetwork.Instance;

            if (host)
            {
                lobbyCodeText.text = "Lobby Code: " + (lobbyCode = IPCrypt.Encrypt(network.networkAddress = GetLocalIP()));

                if (network.StartHost(null, network.maxConnections) == null)
                {
                    UserMessageManager.Dispatch("Could not host a lobby on this network!", 5f);
                    StateMachine.ChangeState(new HostJoinState());
                    return;
                }

                GameObject matchManager = (GameObject)UnityEngine.Object.Instantiate(Resources.Load("Prefabs/MatchManager"));
                NetworkServer.Spawn(matchManager);
            }
            else
            {
                lobbyCodeText.text  = "Lobby Code: " + lobbyCode;
                fieldButton.enabled = false;
                connectingPanel.SetActive(true);

                network.networkAddress           = IPCrypt.Decrypt(lobbyCode);
                network.ClientConnectionChanged += OnClientConnectionChanged;
                network.StartClient();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Joins the lobby with the given code and player tag when the join button
        /// is pressed.
        /// </summary>
        public void OnJoinButtonPressed()
        {
            string playerTag = GameObject.Find("PlayerTagText").GetComponent <Text>().text;

            if (playerTag.Length == 0)
            {
                UserMessageManager.Dispatch("Please enter a player tag.", 5f);
                return;
            }

            PlayerIdentity.DefaultLocalPlayerTag = playerTag;

            string lobbyCode = GameObject.Find("LobbyCodeText").GetComponent <Text>().text;

            if (IPCrypt.Decrypt(lobbyCode).Equals(string.Empty))
            {
                UserMessageManager.Dispatch("Invalid lobby code!", 5f);
            }
            else
            {
                StateMachine.PushState(new LoadRobotState(
                                           new LobbyState(lobbyCode)));
            }
        }