private void CreateLeaderboard()
 {
     if (_multiplayerLeaderboard == null)
     {
         _multiplayerLeaderboard = ui.CreateViewController <MultiplayerLeaderboardViewController>();
         _multiplayerLeaderboard.rectTransform.anchorMin = new Vector2(0.3f, 0f);
         _multiplayerLeaderboard.rectTransform.anchorMax = new Vector2(0.7f, 1f);
     }
 }
        protected override void DidActivate(bool firstActivation, ActivationType type)
        {
            if (_multiplayerLeaderboard == null)
            {
                _multiplayerLeaderboard = BSMultiplayerUI._instance.CreateViewController <MultiplayerLeaderboardViewController>();
                _multiplayerLeaderboard.rectTransform.anchorMin = new Vector2(0.1f, 0f);
                _multiplayerLeaderboard.rectTransform.anchorMax = new Vector2(0.9f, 1f);

                PushViewController(_multiplayerLeaderboard, true);
            }
        }
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);
            }
        }