protected override void DidActivate()
        {
            ui = BSMultiplayerUI._instance;

            if (_backButton == null)
            {
                _backButton = ui.CreateBackButton(rectTransform);

                _backButton.onClick.AddListener(delegate()
                {
                    if (_serverHubConnection != null && _serverHubConnection.Connected)
                    {
                        _serverHubConnection.Close();
                        _loading = false;
                    }
                    DismissModalViewController(null, false);
                });
            }

            if (_enterIPButton == null)
            {
                _enterIPButton = ui.CreateUIButton(rectTransform, "ApplyButton");
                ui.SetButtonText(ref _enterIPButton, "Connect to 127.0.0.1:3701");
                ui.SetButtonTextSize(ref _enterIPButton, 3f);
                (_enterIPButton.transform as RectTransform).sizeDelta        = new Vector2(38f, 6f);
                (_enterIPButton.transform as RectTransform).anchoredPosition = new Vector2(-19f, 73f);
                _enterIPButton.onClick.RemoveAllListeners();
                _enterIPButton.onClick.AddListener(delegate()
                {
                    ConnectToServer("127.0.0.1", 3701);
                });
            }

            if (_loadingIndicator == null)
            {
                try
                {
                    _loadingIndicator = ui.CreateLoadingIndicator(rectTransform);
                    (_loadingIndicator.transform as RectTransform).anchorMin        = new Vector2(0.5f, 0.5f);
                    (_loadingIndicator.transform as RectTransform).anchorMax        = new Vector2(0.5f, 0.5f);
                    (_loadingIndicator.transform as RectTransform).anchoredPosition = new Vector2(0f, 0f);
                    _loadingIndicator.SetActive(true);
                }
                catch (Exception e)
                {
                    Console.WriteLine("EXCEPTION: " + e);
                }
            }

            if (_multiplayerServerList == null)
            {
                _multiplayerServerList = ui.CreateViewController <MultiplayerServerListViewController>();
                _multiplayerServerList.rectTransform.anchorMin = new Vector2(0.3f, 0f);
                _multiplayerServerList.rectTransform.anchorMax = new Vector2(0.7f, 1f);

                PushViewController(_multiplayerServerList, true);
            }
            else
            {
                if (_viewControllers.IndexOf(_multiplayerServerList) < 0)
                {
                    PushViewController(_multiplayerServerList, true);
                }
            }


            _multiplayerServerList._currentPage = 0;
            if (!doNotUpdate)
            {
                GetPage(_multiplayerServerList._currentPage);
            }
            else
            {
                doNotUpdate = false;
            }
        }
Esempio n. 2
0
        protected override void DidActivate(bool firstActivation, ActivationType type)
        {
            ui = BSMultiplayerUI._instance;

            if (_backButton == null)
            {
                _backButton = ui.CreateBackButton(rectTransform);

                _backButton.onClick.AddListener(delegate()
                {
                    try
                    {
                        if (_serverHubs != null && _serverHubs.Count > 0)
                        {
                            _serverHubs.ForEach(x =>
                            {
                                x.Disconnect();

                                x.ReceivedServerList -= MultiplayerServerHubViewController_receivedServerList;
                                x.ServerHubException -= MultiplayerServerHubViewController_serverHubException;
                            });
                            _loading = false;
                        }
                    }catch (Exception e)
                    {
                        Console.WriteLine($"Can't disconnect from ServerHubs. Exception: {e}");
                    }
                    DismissModalViewController(null, false);
                });
            }

            if (_enterIPButton == null)
            {
                _enterIPButton = ui.CreateUIButton(rectTransform, "ApplyButton");
                ui.SetButtonText(ref _enterIPButton, "Connect to 127.0.0.1:3701");
                ui.SetButtonTextSize(ref _enterIPButton, 3f);
                (_enterIPButton.transform as RectTransform).sizeDelta        = new Vector2(38f, 6f);
                (_enterIPButton.transform as RectTransform).anchoredPosition = new Vector2(-19f, 73f);
                _enterIPButton.onClick.RemoveAllListeners();
                _enterIPButton.onClick.AddListener(delegate()
                {
                    ConnectToServer("127.0.0.1", 3701);
                });
            }

            if (_loadingIndicator == null)
            {
                try
                {
                    _loadingIndicator = ui.CreateLoadingIndicator(rectTransform);
                    (_loadingIndicator.transform as RectTransform).anchorMin        = new Vector2(0.5f, 0.5f);
                    (_loadingIndicator.transform as RectTransform).anchorMax        = new Vector2(0.5f, 0.5f);
                    (_loadingIndicator.transform as RectTransform).anchoredPosition = new Vector2(0f, 0f);
                    _loadingIndicator.SetActive(true);
                }
                catch (Exception e)
                {
                    Console.WriteLine("EXCEPTION: " + e);
                }
            }

            if (_multiplayerServerList == null)
            {
                _multiplayerServerList = ui.CreateViewController <MultiplayerServerListViewController>();
                _multiplayerServerList.rectTransform.anchorMin = new Vector2(0.3f, 0f);
                _multiplayerServerList.rectTransform.anchorMax = new Vector2(0.7f, 1f);

                PushViewController(_multiplayerServerList, true);
            }
            else
            {
                if (_viewControllers.IndexOf(_multiplayerServerList) < 0)
                {
                    PushViewController(_multiplayerServerList, true);
                }
            }

            _serverHubs.Clear();
            for (int i = 0; i < Config.Instance.ServerHubIPs.Length; i++)
            {
                ServerHubClient client = new GameObject($"ServerHubClient-{i}").AddComponent <ServerHubClient>();
                client.ip = Config.Instance.ServerHubIPs[i];
                if (Config.Instance.ServerHubPorts.Length <= i)
                {
                    client.port = 3700;
                }
                else
                {
                    client.port = Config.Instance.ServerHubPorts[i];
                }
                _serverHubs.Add(client);
            }

            if (!doNotUpdate)
            {
                _serverHubs.ForEach(x =>
                {
                    x.ReceivedServerList += MultiplayerServerHubViewController_receivedServerList;
                    x.ServerHubException += MultiplayerServerHubViewController_serverHubException;
                });
                GetServers();
            }
            else
            {
                doNotUpdate = false;
            }
        }