// Is responsible for rendering the available servers given // Limits the output to n servers // Displays state such as: currently joining game // Allows players to cancel the join private void SetState(ServerBrowserViewState state) { for (int i = 0; i < _hostEntryViews.Count; i++) { _hostEntryViews[i].gameObject.SetActive(false); } var isJoinAllowed = !state.IsBusy; Debug.Log("host count " + state.Hosts.Count); for (int i = 0; i < state.Hosts.Count; i++) { var hostEntry = state.Hosts[i]; var hostEntryView = _hostEntryViews[i]; hostEntryView.gameObject.SetActive(true); hostEntryView.SetState(hostEntry, isJoinAllowed); var joinButton = hostEntryView.JoinButton.Button; Selectable prev; var hasPreviousHost = i > 0; if (hasPreviousHost) { prev = _hostEntryViews[i - 1].JoinButton.Button; } else { prev = _refreshButton.Button; } Selectable next; var hasNextHost = i + 1 < state.Hosts.Count; if (hasNextHost) { next = _hostEntryViews[i + 1].JoinButton.Button; } else { next = _refreshButton.Button; } joinButton.navigation = new Navigation { mode = Navigation.Mode.Explicit, selectOnUp = prev, selectOnDown = next, }; } Debug.Log("MS status " + state.MasterServerStatus); _masterServerStatusStr.Clear() .Append("Master server status: <b>") .Append(state.MasterServerStatus == MasterServerStatus.Online ? "Online" : "Offline") .Append("</b>"); // TODO Factor this into a single re-usable method _masterServerStatus.SetMutableString(_masterServerStatusStr); var firstSelectableJoinButton = state.Hosts.Count > 0 ? _hostEntryViews[0].JoinButton.Button : null; var lastSelectableJoinButton = state.Hosts.Count > 0 ? _hostEntryViews[state.Hosts.Count - 1].JoinButton.Button : null; _hideFull.SetEnabled(isJoinAllowed); _hideFull.SetChecked(state.HideFull); _hideFull.NavigationElement.navigation = new Navigation { mode = Navigation.Mode.Explicit, selectOnUp = lastSelectableJoinButton ?? _refreshButton.Button, selectOnDown = _refreshButton.Button, }; _refreshButton.Button.interactable = !state.IsBusy; _refreshButton.Button.navigation = new Navigation { mode = Navigation.Mode.Explicit, selectOnUp = _hideFull.NavigationElement, selectOnDown = firstSelectableJoinButton ?? _hideFull.NavigationElement, }; }
void Awake() { _viewState = new ServerBrowserViewState(); }