Beispiel #1
0
    public void Initialize()
    {
        _buttons = new List <ServerListUIButton>();
        NumActiveServerButtons = 0;
        gc_uiText = new StringBuilder();

        ConnectionManager.Instance.Client_ServerListRefreshFinished += UpdateUI;
        ConnectionManager.Instance.Client_ServerListRefreshStarted  += StartLoadingAnimation;
        ChosenServer = null;
        SetDropDownActiveState(false);

        StartCoroutine(ListRefreshLoop());
    }
Beispiel #2
0
    public void UpdateUI()
    {
        ReadOnlyCollection <ConnectionManager.ServerInfo> activeServers = ConnectionManager.Instance.ActiveServers;

        float effectiveButtonHeight = _buttonHeight + _buttonSpacing;

        for (int i = 0; i < activeServers.Count; ++i)
        {
            //If this is true we need to spawn new buttons
            if (i >= _buttons.Count)
            {
                //spawn new button
                ServerListUIButton newButton = Instantiate(_buttonPrefab, _buttonPane);
                newButton.Initialize(i);
                newButton.ButtonPressed += OnServerSelect;

                //Figure out which yPos to place the button at
                float buttonY = i * -effectiveButtonHeight;
                newButton.GetComponent <RectTransform>().anchoredPosition = new Vector3(0f, buttonY, 0f);

                //add the button to the list
                _buttons.Add(newButton);
            }

            //enable button if it was disabled before
            _buttons[i].gameObject.SetActive(true);
            //setup newButtonScript
            _buttons[i].CorrespondingServer = activeServers[i];
            //update button text
            _buttons[i].Text.text = GetServerDescription(activeServers[i]).ToString();
        }
        //Disable the buttons that were previously active but now don't need to be active
        //Happens with the number of activeServers drops
        for (int i = activeServers.Count; i < NumActiveServerButtons; ++i)
        {
            _buttons[i].SetButtonHighlight(false);
            _buttons[i].gameObject.SetActive(false);
        }

        //Update the number of active buttons
        NumActiveServerButtons = activeServers.Count;
        //Expand or contract the button pane based on the number of buttons it contains
        _buttonPane.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, _buttonHeight + Mathf.Max(0, NumActiveServerButtons - 1) * effectiveButtonHeight);

        UIListUpdated?.Invoke();

        if (NumActiveServerButtons == 0)
        {
            ChosenServer = null;
        }
    }
Beispiel #3
0
 void OnServerSelect(ServerListUIButton pressedButton)
 {
     ChosenServer = pressedButton;
     PlayerSlecetedServer?.Invoke(pressedButton.CorrespondingServer);
 }