IEnumerator WaitForResults() { yield return(new WaitUntil(delegate() { return Resources.FindObjectsOfTypeAll <ResultsViewController>().Count() > 0; })); ResultsViewController results = Resources.FindObjectsOfTypeAll <ResultsViewController>().First(); results.GetComponentsInChildren <Button>().First(x => x.name == "RestartButton").interactable = false; results.resultsViewControllerDidPressContinueButtonEvent += delegate(ResultsViewController viewController) { try { MultiplayerServerHubViewController hub = ui.CreateViewController <MultiplayerServerHubViewController>(); MultiplayerLobbyViewController lobby = ui.CreateViewController <MultiplayerLobbyViewController>(); viewController.DismissModalViewController(null, true); FindObjectOfType <SongSelectionMasterViewController>().DismissModalViewController(null, true); FindObjectOfType <SoloModeSelectionViewController>().DismissModalViewController(null, true); hub.doNotUpdate = true; FindObjectOfType <MainMenuViewController>().PresentModalViewController(hub, null, true); lobby.selectedServerIP = lastServerIP; lobby.selectedServerPort = lastServerPort; hub.PresentModalViewController(lobby, null, true); } catch (Exception e) { Console.WriteLine($"RESULTS EXCEPTION: {e}"); } }; }
IEnumerator WaitForMenu() { yield return(new WaitUntil(delegate() { return Resources.FindObjectsOfTypeAll <VRUIScreenSystem>().Any(); })); VRUIScreenSystem screenSystem = Resources.FindObjectsOfTypeAll <VRUIScreenSystem>().First(); yield return(new WaitWhile(delegate() { Console.WriteLine("Waiting for mainScreen"); return screenSystem.mainScreen == null; })); yield return(new WaitWhile(delegate() { Console.WriteLine("Waiting for rootViewController"); return screenSystem.mainScreen.rootViewController == null; })); try { VRUIViewController root = screenSystem.mainScreen.rootViewController; List <VRUIViewController> children = new List <VRUIViewController>(); children.Add(root); while (children.Last().childViewController != null) { children.Add(children.Last().childViewController); } children.Reverse(); children.Remove(root); children.ForEach(x => { Console.WriteLine($"Dismissing {x.name}..."); x.DismissModalViewController(null, true); }); MultiplayerServerHubViewController hub = ui.CreateViewController <MultiplayerServerHubViewController>(); MultiplayerLobbyViewController lobby = ui.CreateViewController <MultiplayerLobbyViewController>(); bool serverClosed = (lastCommands != null) ? lastCommands.Any(x => x.commandType == ServerCommandType.Kicked && x.kickReason == "Server closed") : false; hub.doNotUpdate = !serverClosed; FindObjectOfType <MainMenuViewController>().PresentModalViewController(hub, null, true); if (!serverClosed) { lobby.selectedServerIP = lastServerIP; lobby.selectedServerPort = lastServerPort; hub.PresentModalViewController(lobby, null, true); } } catch (Exception e) { Console.WriteLine($"MENU EXCEPTION: {e}"); } }
public void ConnectToServer(string serverIP, int serverPort) { MultiplayerLobbyViewController lobby = ui.CreateViewController <MultiplayerLobbyViewController>(); lobby.selectedServerIP = serverIP; lobby.selectedServerPort = serverPort; PresentModalViewController(lobby, null); }
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() { 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(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; } }