예제 #1
0
    /// <summary>
    /// 根据配置文件 初始化泡泡布置
    /// </summary>
    public void InitByLayoutData(string layoutStr)
    {
        string[] items = layoutStr.Split('|');

        for (int i = 0; i < items.Length; ++i)
        {
            string             oneItem   = items[i];
            string[]           itemInfos = oneItem.Split('^');
            BubbleConfigStruct info      = new BubbleConfigStruct();
            info.id         = int.Parse(itemInfos[0]);
            info.prefabName = itemInfos[1];
            info.pos        = StrToVec(itemInfos[2]);
            info.rotate     = StrToVec(itemInfos[3]);
            info.scale      = StrToVec(itemInfos[4]);

            layoutList.Add(info);
        }

        for (int j = 0; j < layoutList.Count; ++j)
        {
            BubbleConfigStruct info = layoutList[j];

            Transform newBubble = GetBubbleTran(info.id);
            newBubble.parent = transform;

            BubbleUnit bubble = newBubble.GetComponent <BubbleUnit> ();
            bubble.SetData(info.id);
            bubbleList.Add(bubble);

            newBubble.transform.localPosition = info.pos;
            newBubble.transform.localRotation = Quaternion.Euler(info.rotate);
            newBubble.transform.localScale    = info.scale;
        }
    }
예제 #2
0
    void CreateConfigData()
    {
        //deal name
        for (int i = 0; i < transform.childCount; i++)
        {
            string childName = transform.GetChild(i).name;
            int    sIndex    = childName.IndexOf(' ');

            if (sIndex > 0)
            {
                childName = childName.Remove(sIndex);
                transform.GetChild(i).name = childName;
            }
        }

        List <BubbleConfigStruct> infoList = new List <BubbleConfigStruct> ();

        for (int j = 0; j < transform.childCount; ++j)
        {
            Transform child = transform.GetChild(j);

            BubbleConfigStruct info = new BubbleConfigStruct();

            info.id         = child.GetComponent <BubbleUnit>().ID;
            info.prefabName = child.name;
            info.pos        = child.localPosition;
            info.rotate     = child.localRotation.eulerAngles;
            info.scale      = child.localScale;

            infoList.Add(info);
        }

        resConfigData = "";
        for (int k = 0; k < infoList.Count; ++k)
        {
            BubbleConfigStruct info = infoList[k];

            string str = "";
            str += info.id + "^";
            str += info.prefabName + "^";
            str += VecToStr(info.pos) + "^";
            str += VecToStr(info.rotate) + "^";
            str += VecToStr(info.scale);

            if (k != infoList.Count - 1)
            {
                str += "|";
            }

            resConfigData += str;
        }
    }