Esempio n. 1
0
        public void AddAServer(string address, int port)
        {
            if (dictServers.ContainsKey(address))
            {
                return;
            }

            GameObject obj = Instantiate(objTempItem, objContent.transform) as GameObject;

            ServerItem item = obj.GetComponent <ServerItem>();

            item.Init(address, port, ConnectServer);
            dictServers[address] = obj;
        }
Esempio n. 2
0
    /// <summary>
    /// 显示所有的服务器
    /// </summary>
    public void ShowServer(List <ServerData> serverDataList)
    {
        //1.如果当前图标数小于传进来的数据那么就添加
        //2.如果大于就失活
        if (serverDataList == null)
        {
            return;
        }

        Debug.Log("更新");
        for (int i = 0; i < serverDataList.Count; i++)
        {
            GameObject item = null;

            if (i < serverItemContent.childCount)
            {
                item = serverItemContent.GetChild(i).gameObject;
            }
            else
            {
                //实例化到场景中
                item = PoolManager.Instance.GetObj("Prafebs/UI/ServerItem");
                //设置父对象
                item.transform.SetParent(serverItemContent);
                (item.transform as RectTransform).localScale = Vector3.one;
            }
            ServerItem si = item.GetComponent <ServerItem>();
            //初始化图标
            si.Init(serverDataList[i], selectServerCallback);
        }
        int num = serverItemContent.childCount;

        for (int i = serverDataList.Count; i < num; i++)
        {
            PoolManager.Instance.PushObj(serverItemContent.GetChild(serverDataList.Count).gameObject);
        }
    }