Exemplo n.º 1
0
    void InitAllServer()
    {
        int index = 0;

        foreach (ServerInfo info in FCDownloadManager.Instance.GameServers)
        {
            ServerButtonImage buttonImage = GetServerButtonImageByState(info.state);
            GameObject        obj         = NGUITools.AddChild(allServerGrid.gameObject, cloneSingle.gameObject);
            obj.transform.localPosition = cloneSingle.transform.localPosition;
            UISingleServer singServer = obj.GetComponent <UISingleServer>();
            singServer.Init(this, info, buttonImage);
            singServer.gameObject.SetActive(true);
            obj.name = string.Format("sort{0}", index.ToString("000"));
            ++index;
        }

        UIGrid uigrid = allServerGrid.GetComponent <UIGrid>();

        uigrid.repositionNow = true;
    }
Exemplo n.º 2
0
    void InitThreeServer()
    {
        List <ServerInfo> serverList = FCDownloadManager.Instance.GameServers;

        serverList.Sort(ServerInfo.CompareServerFromMaxToMin); //paixu
        const int         Count           = 3;
        List <ServerInfo> threeServerList = new List <ServerInfo>();

        ServerInfo serverInfo = GetServerInfoFromCache(PrefsKey.ServerCacheOne);

        if (null != serverInfo)
        {
            threeServerList.Add(serverInfo);
        }

        serverInfo = GetServerInfoFromCache(PrefsKey.ServerCacheTwo);

        if (null != serverInfo)
        {
            threeServerList.Add(serverInfo);
        }

        if (threeServerList.Count >= 1)
        {
            foreach (ServerInfo info in serverList)
            {
                if (threeServerList.Count >= Count)
                {
                    break;
                }

                if (!threeServerList.Contains(info))
                {
                    threeServerList.Add(info);
                }
            }
        }
        else
        {
            List <ServerInfo> recommendedList = serverList.FindAll(
                delegate(ServerInfo info)
            {
                return(info.state == ServerState.Recommended);
            });

            foreach (ServerInfo info in recommendedList)
            {
                if (threeServerList.Count >= Count)
                {
                    break;
                }

                if (!threeServerList.Contains(info))
                {
                    threeServerList.Add(info);
                }
            }

            if (threeServerList.Count < Count)
            {
                foreach (ServerInfo info in serverList)
                {
                    if (threeServerList.Count >= Count)
                    {
                        break;
                    }

                    if (!threeServerList.Contains(info))
                    {
                        threeServerList.Add(info);
                    }
                }
            }
        }

        int index = 0;

        foreach (ServerInfo info in threeServerList)
        {
            ServerButtonImage buttonImage = GetServerButtonImageByState(info.state);
            GameObject        obj         = NGUITools.AddChild(cacheGrid.gameObject, cloneSingle.gameObject);
            UISingleServer    singServer  = obj.GetComponent <UISingleServer>();
            singServer.Init(this, info, buttonImage, true);
            singServer.gameObject.SetActive(true);
            singServer.name = string.Format("sort{0}", index.ToString("000"));
            ++index;
        }

        UIGrid uigrid = cacheGrid.GetComponent <UIGrid>();

        uigrid.repositionNow = true;
    }