コード例 #1
0
ファイル: JoinMenu.cs プロジェクト: harko12/Battle
    IEnumerator UpdateChannelList()
    {
        var channelList = GetComponent <TNChannelList>();

        while (true)
        {
            var list = channelList.Channels;
            // the channel list script keeps an updated list of the channels
            for (int i = 0; i < list.size; ++i)
            {
                GameObject go = null;
                if (ChannelLines.Count <= i)
                {
                    go = GameObject.Instantiate(ChannelLine) as GameObject;
                    go.transform.SetParent(ChannelListRoot.transform);
                    ChannelLines.Add(go);
                }
                var ent = list.buffer[i];
                go = ChannelLines.buffer[i];
                go.SetActive(true);
                var button      = go.GetComponentInChildren <UnityEngine.UI.Button>();
                var textFields  = go.GetComponentsInChildren <Text>();
                var channelData = ent.data; // jsonize at somepoint.. for now just the channel name
                var channelName = (string.IsNullOrEmpty(channelData) ? "loading.." : channelData);
                textFields[0].text = channelName;
                textFields[1].text = ent.level;
                textFields[2].text = "no info right now";
                button.onClick.RemoveAllListeners();
                button.onClick.AddListener(delegate
                {
                    Debug.LogFormat("joining id:{0} level:{1}", ent.id, ent.level);
                    TNManager.SetTimeout(120); // stupid levels take forever to load
                    SceneManager.LoadScene("Game", LoadSceneMode.Single);
                    TNManager.JoinChannel(ent.id, false, true);
                    //                    TNManager.JoinChannel(ent.id, ent.level);
                });
            }
            // hide any extra lines
            for (int i = list.size; i < ChannelLines.Count; i++)
            {
                ChannelLines[i].SetActive(false);
            }

            yield return(new WaitForSeconds(GetComponent <TNChannelList>().RefreshInterval));
        }
    }