Esempio n. 1
0
    void RepositionVertical()
    {
        int            count = this.m_ContentParent.childCount;
        Bounds         tempBounds;
        Vector3        preEndPos = Vector3.zero;
        Transform      curTrans;
        Vector3        padingY            = new Vector3(0, this.m_Padding.y, 0);
        ProfessionItem tempProfessionItem = null;
        float          fontHeight         = 31;

        for (int i = 0; i < count; i++)
        {
            curTrans               = this.m_ContentParent.GetChild(i);
            tempProfessionItem     = curTrans.GetComponent <ProfessionItem>();
            curTrans.localPosition = preEndPos - padingY;
            //lz-2016.08.11 因为KickstarterBackers这一项的内容太多,所以从数据上分成了几项,做了分段处理,但是位置应该连起来
            if (null != tempProfessionItem && tempProfessionItem.TitleIsNullOrEmpty)
            {
                curTrans.localPosition = preEndPos - new Vector3(0, (tempProfessionItem.CellHeight - fontHeight) * 2, 0);
            }
            else
            {
                curTrans.localPosition = preEndPos - padingY;
            }
            tempBounds  = NGUIMath.CalculateRelativeWidgetBounds(curTrans);
            preEndPos.y = curTrans.localPosition.y - tempBounds.size.y;
        }
    }
Esempio n. 2
0
    //lz-2016.06.13 这种方法可以使可以更便捷的调整每一块,每一条上下左右的间距,和对齐问题
    void XmlModeFillContent()
    {
        //lz-2016.08.02 这里不能用全路径Load
        TextAsset   textAsset = Resources.Load("Credits/CreditsXml", typeof(TextAsset)) as TextAsset;
        XmlDocument xmlDoc    = new XmlDocument();

        xmlDoc.LoadXml(textAsset.text);

        //root
        XmlNode rootNode = xmlDoc.SelectSingleNode("Root");

        //title
        XmlElement     titleNode = (XmlElement)rootNode.SelectSingleNode("Title");
        ManyPeopleItem titleItem = GetNewParticipantItem();

        titleItem.UpdateNames(titleNode.GetAttribute("Name"));
        //Participant
        XmlNode participantNode = rootNode.SelectSingleNode("Participant");

        for (int i = 0; i < participantNode.ChildNodes.Count; i++)
        {
            XmlElement professionNode = (XmlElement)participantNode.ChildNodes[i];


            //lz-2016.08.15 Kickstarter Backers人员较多,所以结构不一样
            if (professionNode.GetAttribute("Name").Equals("Kickstarter Backers") ||
                (professionNode.GetAttribute("Name").Equals("Other Contributors")))
            {
                List <string> kBNames = new List <string>();
                for (int k = 0; k < professionNode.ChildNodes.Count; k++)
                {
                    XmlElement peopleNode = (XmlElement)professionNode.ChildNodes[k];
                    string     tempStr    = string.Empty;
                    for (int aIndex = 0; aIndex < this.m_MaxCol; aIndex++)
                    {
                        tempStr = peopleNode.GetAttribute("Name" + aIndex);
                        if (string.IsNullOrEmpty(tempStr))
                        {
                            continue;
                        }
                        kBNames.Add(tempStr);
                    }
                }
                List <string> shotNames = new List <string> ();
                List <string> longNames = new List <string> ();
                kBNames.ForEach(name => { if (name.Length <= this.m_MaxNameWidth)
                                          {
                                              shotNames.Add(name);
                                          }
                                          else
                                          {
                                              longNames.Add(name);
                                          } });
                shotNames = shotNames.OrderBy(a => a.Length).ToList();
                //lz-2016.08.16 如果名字短的不是整行数,就把不够一行的那个几个元素放到长名字里面去
                if (shotNames.Count % this.m_MaxCol != 0 && longNames.Count > 0)
                {
                    int startIndex = shotNames.Count - (shotNames.Count % this.m_MaxCol);
                    longNames.AddRange(shotNames.GetRange(startIndex, shotNames.Count - startIndex));
                    shotNames.RemoveRange(startIndex, shotNames.Count - startIndex);
                }
                longNames = longNames.OrderBy(a => a.Length).ToList();
                if (shotNames.Count > 0)
                {
                    int                   professionCount    = 0;
                    ProfessionItem        professionItem     = null;
                    List <ManyPeopleName> manyPeopleNameList = new List <ManyPeopleName> ();
                    string                professionName     = professionNode.GetAttribute("Name");
                    for (int j = 0; j < shotNames.Count; j += this.m_MaxCol)
                    {
                        professionCount++;
                        int      count = j + this.m_MaxCol < shotNames.Count?this.m_MaxCol:shotNames.Count - j;
                        string[] names = shotNames.GetRange(j, count).ToArray();
                        manyPeopleNameList.Add(new ManyPeopleName(names));
                        if (professionCount % this.m_ProfessionItemMaxCapacity == 0 || j + this.m_MaxCol >= shotNames.Count)
                        {
                            professionItem = this.GetNewProfessionItem();
                            professionItem.UpdateInfo(new ProfessionInfo(professionName, manyPeopleNameList), false);
                            manyPeopleNameList.Clear();
                            professionName = "";
                        }
                    }
                }
                if (longNames.Count > 0)
                {
                    ProfessionItem        professionItem = null;
                    List <ManyPeopleName> namelist       = new List <ManyPeopleName>();
                    int    professionCount = 0;
                    string professionName  = shotNames.Count > 0?"":professionNode.GetAttribute("Name");
                    for (int m = 0; m < longNames.Count; m += 2)
                    {
                        professionCount++;
                        namelist.Add(new ManyPeopleName(longNames[m], m + 1 < longNames.Count ? longNames[m + 1] : ""));
                        if (professionCount % this.m_ProfessionItemMaxCapacity == 0 || m + 2 >= longNames.Count)
                        {
                            professionItem = this.GetNewProfessionItem();
                            professionItem.UpdateInfo(new ProfessionInfo(professionName, namelist));
                            namelist.Clear();
                        }
                    }
                }
            }
            else
            {
                ProfessionItem        professionItem = this.GetNewProfessionItem();
                List <ManyPeopleName> namelist       = new List <ManyPeopleName>();
                for (int j = 0; j < professionNode.ChildNodes.Count; j++)
                {
                    XmlElement peopleNode = (XmlElement)professionNode.ChildNodes[j];
                    namelist.Add(new ManyPeopleName(peopleNode.GetAttribute("EnglishName"), peopleNode.GetAttribute("ChineseName")));
                }
                professionItem.UpdateInfo(new ProfessionInfo(professionNode.GetAttribute("Name"), namelist));
            }
        }
        //End
        XmlElement endNode = (XmlElement)rootNode.SelectSingleNode("End");

        this.m_EndManyPeopleItem = GetNewParticipantItem();
        this.m_EndManyPeopleItem.UpdateNames(endNode.GetAttribute("Name"));
    }