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;
            }
        }
Exemplo n.º 2
0
        protected override void DidActivate()
        {
            ui          = BSMultiplayerUI._instance;
            _songLoader = FindObjectOfType <SongLoader>();

            if (_songPreviewPlayer == null)
            {
                ObjectProvider[] providers = Resources.FindObjectsOfTypeAll <ObjectProvider>().Where(x => x.name == "SongPreviewPlayerProvider").ToArray();

                if (providers.Length > 0)
                {
                    _songPreviewPlayer = providers[0].GetProvidedObject <SongPreviewPlayer>();
                }
            }

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

                _backButton.onClick.AddListener(delegate()
                {
                    BSMultiplayerMain._instance.DataReceived -= DataReceived;
                    BSMultiplayerMain._instance.DisconnectFromServer();
                    DismissModalViewController(null, false);
                });
            }

            if (_timerText == null)
            {
                _timerText           = ui.CreateText(rectTransform, "", new Vector2(0f, -5f));
                _timerText.fontSize  = 8f;
                _timerText.alignment = TextAlignmentOptions.Center;
                _timerText.rectTransform.sizeDelta = new Vector2(20f, 6f);
            }

            if (_selectText == null)
            {
                _selectText           = ui.CreateText(rectTransform, "", new Vector2(0f, -36f));
                _selectText.fontSize  = 7f;
                _selectText.alignment = TextAlignmentOptions.Center;
                _selectText.rectTransform.sizeDelta = new Vector2(40f, 6f);
            }

            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 (_selectedSongCell == null)
            {
                _selectedSongCell = Instantiate(Resources.FindObjectsOfTypeAll <SongListTableCell>().First(x => x.name == "SongListTableCell"), rectTransform, false);

                (_selectedSongCell.transform as RectTransform).anchorMin        = new Vector2(0.5f, 0.5f);
                (_selectedSongCell.transform as RectTransform).anchorMax        = new Vector2(0.5f, 0.5f);
                (_selectedSongCell.transform as RectTransform).anchoredPosition = new Vector2(-25f, 0);

                _selectedSongCell.gameObject.SetActive(false);
            }
            else
            {
                _selectedSongCell.gameObject.SetActive(false);
            }



            if (BSMultiplayerMain._instance.ConnectToServer())
            {
                BSMultiplayerMain._instance.SendString(JsonUtility.ToJson(new ClientCommand(ClientCommandType.GetServerState)));
                BSMultiplayerMain._instance.SendString(JsonUtility.ToJson(new ClientCommand(ClientCommandType.GetAvailableSongs)));
                StartCoroutine(BSMultiplayerMain._instance.ReceiveFromServerCoroutine());
                BSMultiplayerMain._instance.DataReceived += DataReceived;
            }
            else
            {
                _loading = false;
                TextMeshProUGUI _errorText = ui.CreateText(rectTransform, String.Format("Can't connect to server!"), new Vector2(0f, -48f));
                _errorText.alignment = TextAlignmentOptions.Center;
                Destroy(_errorText.gameObject, 5f);
            }
        }
Exemplo n.º 3
0
        protected override void DidActivate()
        {
            ui              = BSMultiplayerUI._instance;
            _songLoader     = FindObjectOfType <SongLoader>();
            localPlayerInfo = new PlayerInfo(GetUserInfo.GetUserName(), GetUserInfo.GetUserID());

            if (_songPreviewPlayer == null)
            {
                ObjectProvider[] providers = Resources.FindObjectsOfTypeAll <ObjectProvider>().Where(x => x.name == "SongPreviewPlayerProvider").ToArray();

                if (providers.Length > 0)
                {
                    _songPreviewPlayer = providers[0].GetProvidedObject <SongPreviewPlayer>();
                }
            }

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

                _backButton.onClick.AddListener(delegate()
                {
                    BSMultiplayerClient._instance.DataReceived -= DataReceived;
                    BSMultiplayerClient._instance.DisconnectFromServer();
                    _songPreviewPlayer.CrossfadeToDefault();
                    try
                    {
                        transform.parent.GetComponent <MultiplayerServerHubViewController>().UpdatePage();
                    } catch (Exception e)
                    {
                        Console.WriteLine($"ServerHub exception: {e}");
                    }
                    foreach (AvatarController avatar in _avatars)
                    {
                        Destroy(avatar.gameObject);
                    }
                    DismissModalViewController(null, false);
                });
            }

            if (_timerText == null)
            {
                _timerText           = ui.CreateText(rectTransform, "", new Vector2(0f, -5f));
                _timerText.fontSize  = 8f;
                _timerText.alignment = TextAlignmentOptions.Center;
                _timerText.rectTransform.sizeDelta = new Vector2(20f, 6f);
            }

            if (_selectText == null)
            {
                _selectText           = ui.CreateText(rectTransform, "", new Vector2(0f, -36f));
                _selectText.fontSize  = 7f;
                _selectText.alignment = TextAlignmentOptions.Center;
                _selectText.rectTransform.sizeDelta = new Vector2(120f, 6f);
            }

            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 (_selectedSongCell == null)
            {
                _selectedSongCell = Instantiate(Resources.FindObjectsOfTypeAll <SongListTableCell>().First(x => x.name == "SongListTableCell"), rectTransform, false);

                (_selectedSongCell.transform as RectTransform).anchorMin        = new Vector2(0.5f, 0.5f);
                (_selectedSongCell.transform as RectTransform).anchorMax        = new Vector2(0.5f, 0.5f);
                (_selectedSongCell.transform as RectTransform).anchoredPosition = new Vector2(-25f, 0);

                _selectedSongCell.gameObject.SetActive(false);
            }
            else
            {
                _selectedSongCell.gameObject.SetActive(false);
            }

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

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

            Console.WriteLine($"Connecting to {selectedServerIP}:{selectedServerPort}");
            if (BSMultiplayerClient._instance.ConnectToServer(selectedServerIP, selectedServerPort))
            {
                BSMultiplayerClient._instance.SendString(JsonUtility.ToJson(new ClientCommand(ClientCommandType.GetServerState)));
                BSMultiplayerClient._instance.SendString(JsonUtility.ToJson(new ClientCommand(ClientCommandType.GetAvailableSongs)));
                StartCoroutine(BSMultiplayerClient._instance.ReceiveFromServerCoroutine());
                BSMultiplayerClient._instance.DataReceived += DataReceived;
            }
            else
            {
                _loading = false;
                TextMeshProUGUI _errorText = ui.CreateText(rectTransform, String.Format("Can't connect to server!"), new Vector2(0f, -48f));
                _errorText.alignment = TextAlignmentOptions.Center;
                Destroy(_errorText.gameObject, 5f);
            }
        }
Exemplo n.º 4
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;
            }
        }