private void Awake() { _instance = this; DontDestroyOnLoad(this); Console.ForegroundColor = ConsoleColor.Gray; try { _buttonInstance = Resources.FindObjectsOfTypeAll <Button>().First(x => (x.name == "QuitButton")); _backButtonInstance = Resources.FindObjectsOfTypeAll <Button>().First(x => (x.name == "BackArrowButton")); _mainMenuViewController = Resources.FindObjectsOfTypeAll <MainMenuViewController>().First(); _mainMenuRectTransform = _buttonInstance.transform.parent as RectTransform; _loadingIndicatorInstance = Resources.FindObjectsOfTypeAll <GameObject>().Where(x => x.name == "LoadingIndicator").First(); Console.WriteLine("Buttons and main menu found!"); } catch (Exception e) { Console.WriteLine("EXCEPTION ON AWAKE(TRY FIND BUTTONS): " + e); } try { CreateMultiplayerButton(); Console.WriteLine("Online button created!"); } catch (Exception e) { Console.WriteLine("EXCEPTION ON AWAKE(TRY CREATE BUTTON): " + e); } }
protected override void DidActivate(bool firstActivation, ActivationType type) { ui = BSMultiplayerUI._instance; _parentMasterViewController = transform.parent.GetComponent <MultiplayerLobbyViewController>(); _leaderboardTableCellInstance = Resources.FindObjectsOfTypeAll <LeaderboardTableCell>().First(x => (x.name == "LeaderboardTableCell")); if (_leaderboardTableView == null) { _leaderboardTableView = new GameObject().AddComponent <TableView>(); _leaderboardTableView.transform.SetParent(rectTransform, false); Mask viewportMask = Instantiate(Resources.FindObjectsOfTypeAll <Mask>().First(), _leaderboardTableView.transform, false); viewportMask.transform.DetachChildren(); _leaderboardTableView.GetComponentsInChildren <RectTransform>().First(x => x.name == "Content").transform.SetParent(viewportMask.rectTransform, false); (_leaderboardTableView.transform as RectTransform).anchorMin = new Vector2(0f, 0.5f); (_leaderboardTableView.transform as RectTransform).anchorMax = new Vector2(1f, 0.5f); (_leaderboardTableView.transform as RectTransform).sizeDelta = new Vector2(0f, 60f); (_leaderboardTableView.transform as RectTransform).anchoredPosition = new Vector3(0f, -3f); } }
private void Awake() { _instance = this; DontDestroyOnLoad(this); StartCoroutine(WaitForGameData()); ui = BSMultiplayerUI._instance; }
public void OnLevelWasLoaded(int level) { Console.WriteLine("Loading scene " + level); if (level == 1) { BSMultiplayerUI.OnLoad(); BSMultiplayerMain.OnLoad(level); } else if (level > 1) { BSMultiplayerMain.OnLoad(level); } }
public void OnLevelWasLoaded(int level) { Console.WriteLine("Loading scene " + level); if (level == 1) { Config.Instance.Save(); BSMultiplayerUI.OnLoad(); BSMultiplayerClient.OnLoad(level, Version); } else if (level > 1) { BSMultiplayerClient.OnLoad(level, Version); } }
void Awake() { BSMultiplayerUI ui = BSMultiplayerUI._instance; playerPlaceText = ui.CreateWorldText(transform, ""); playerPlaceText.rectTransform.anchoredPosition = new Vector2(2.5f, 0f); playerPlaceText.fontSize = 8f; playerNameText = ui.CreateWorldText(transform, ""); playerNameText.rectTransform.anchoredPosition = new Vector2(4f, 0f); playerNameText.fontSize = 7f; playerScoreText = ui.CreateWorldText(transform, ""); playerScoreText.rectTransform.anchoredPosition = new Vector2(15f, 0f); playerScoreText.fontSize = 8f; }
private void Awake() { _instance = this; DontDestroyOnLoad(this); StartCoroutine(WaitForGameData()); ui = BSMultiplayerUI._instance; if (playerID == 0 || playerInfo == null) { Users.GetLoggedInUser().OnComplete((Message <User> msg) => { playerID = msg.Data.ID; playerName = msg.Data.OculusID; }); } }
protected override void DidActivate() { ui = BSMultiplayerUI._instance; _parentMasterViewController = transform.parent.GetComponent <MultiplayerServerHubViewController>(); _serverTableCellInstance = Resources.FindObjectsOfTypeAll <SongListTableCell>().First(x => (x.name == "SongListTableCell")); if (_pageUpButton == null) { _pageUpButton = Instantiate(Resources.FindObjectsOfTypeAll <Button>().First(x => (x.name == "PageUpButton")), rectTransform, false); (_pageUpButton.transform as RectTransform).anchorMin = new Vector2(0.5f, 1f); (_pageUpButton.transform as RectTransform).anchorMax = new Vector2(0.5f, 1f); (_pageUpButton.transform as RectTransform).anchoredPosition = new Vector2(0f, -14f); _pageUpButton.interactable = true; _pageUpButton.onClick.AddListener(delegate() { if (_currentPage > 0) { if (!_parentMasterViewController._loading) { _currentPage -= 1; _parentMasterViewController.GetPage(_currentPage); } } }); _pageUpButton.interactable = false; } if (_pageDownButton == null) { _pageDownButton = Instantiate(Resources.FindObjectsOfTypeAll <Button>().First(x => (x.name == "PageDownButton")), rectTransform, false); (_pageDownButton.transform as RectTransform).anchorMin = new Vector2(0.5f, 0f); (_pageDownButton.transform as RectTransform).anchorMax = new Vector2(0.5f, 0f); (_pageDownButton.transform as RectTransform).anchoredPosition = new Vector2(0f, 8f); _pageDownButton.interactable = true; _pageDownButton.onClick.AddListener(delegate() { if (!_parentMasterViewController._loading) { _currentPage += 1; Console.WriteLine("Page down"); _parentMasterViewController.GetPage(_currentPage); } }); _pageDownButton.interactable = false; } if (_serverTableView == null) { _serverTableView = new GameObject().AddComponent <TableView>(); _serverTableView.transform.SetParent(rectTransform, false); Mask viewportMask = Instantiate(Resources.FindObjectsOfTypeAll <Mask>().First(), _serverTableView.transform, false); viewportMask.transform.DetachChildren(); _serverTableView.GetComponentsInChildren <RectTransform>().First(x => x.name == "Content").transform.SetParent(viewportMask.rectTransform, false); (_serverTableView.transform as RectTransform).anchorMin = new Vector2(0f, 0.5f); (_serverTableView.transform as RectTransform).anchorMax = new Vector2(1f, 0.5f); (_serverTableView.transform as RectTransform).sizeDelta = new Vector2(0f, 60f); (_serverTableView.transform as RectTransform).position = new Vector3(0f, 0f, 2.4f); (_serverTableView.transform as RectTransform).anchoredPosition = new Vector3(0f, -3f); _serverTableView.DidSelectRowEvent += ServerTableView_DidSelectRow; _serverTableView.dataSource = this; } else { _serverTableView.ReloadData(); } }
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; } }
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); } }
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); } }
protected override void DidActivate(bool firstActivation, ActivationType type) { ui = BSMultiplayerUI._instance; _parentMasterViewController = transform.parent.GetComponent <MultiplayerServerHubViewController>(); _serverTableCellInstance = Resources.FindObjectsOfTypeAll <StandardLevelListTableCell>().First(x => (x.name == "StandardLevelListTableCell")); if (_pageUpButton == null) { _pageUpButton = Instantiate(Resources.FindObjectsOfTypeAll <Button>().First(x => (x.name == "PageUpButton")), rectTransform, false); (_pageUpButton.transform as RectTransform).anchorMin = new Vector2(0.5f, 1f); (_pageUpButton.transform as RectTransform).anchorMax = new Vector2(0.5f, 1f); (_pageUpButton.transform as RectTransform).anchoredPosition = new Vector2(0f, -14f); _pageUpButton.interactable = true; _pageUpButton.onClick.AddListener(delegate() { _serverTableView.PageScrollUp(); }); _pageUpButton.interactable = false; } if (_pageDownButton == null) { _pageDownButton = Instantiate(Resources.FindObjectsOfTypeAll <Button>().First(x => (x.name == "PageDownButton")), rectTransform, false); (_pageDownButton.transform as RectTransform).anchorMin = new Vector2(0.5f, 0f); (_pageDownButton.transform as RectTransform).anchorMax = new Vector2(0.5f, 0f); (_pageDownButton.transform as RectTransform).anchoredPosition = new Vector2(0f, 8f); _pageDownButton.interactable = true; _pageDownButton.onClick.AddListener(delegate() { _serverTableView.PageScrollDown(); }); _pageDownButton.interactable = false; } if (_serverTableView == null) { _serverTableView = new GameObject().AddComponent <TableView>(); _serverTableView.transform.SetParent(rectTransform, false); Mask viewportMask = Instantiate(Resources.FindObjectsOfTypeAll <Mask>().First(), _serverTableView.transform, false); viewportMask.transform.DetachChildren(); _serverTableView.GetComponentsInChildren <RectTransform>().First(x => x.name == "Content").transform.SetParent(viewportMask.rectTransform, false); (_serverTableView.transform as RectTransform).anchorMin = new Vector2(0f, 0.5f); (_serverTableView.transform as RectTransform).anchorMax = new Vector2(1f, 0.5f); (_serverTableView.transform as RectTransform).sizeDelta = new Vector2(0f, 60f); (_serverTableView.transform as RectTransform).position = new Vector3(0f, 0f, 2.4f); (_serverTableView.transform as RectTransform).anchoredPosition = new Vector3(0f, -3f); ReflectionUtil.SetPrivateField(_serverTableView, "_pageUpButton", _pageUpButton); ReflectionUtil.SetPrivateField(_serverTableView, "_pageDownButton", _pageDownButton); _serverTableView.didSelectRowEvent += ServerTableView_DidSelectRow; _serverTableView.dataSource = this; } else { _serverTableView.ReloadData(); } }
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; } }