Beispiel #1
0
    public void Init(int index, page_1_2_Data data, GameObject p_UIParent)
    {
        this.gameObject.transform.localPosition = new Vector3(
            this.gameObject.transform.localPosition.x,
            this.gameObject.transform.localPosition.y,
            0);

        mData       = data;
        text.text   = data.openTime;
        text_1.text = data.title;
        UIParent    = p_UIParent;
        RectTransform rt = bgImg.transform.GetComponent <RectTransform>();

        if (index % 2 == 0)
        {
            rt.anchoredPosition = new Vector2(74, 88);
        }
        else
        {
            rt.anchoredPosition = new Vector2(74, -250);
        }

        bgImg.sprite = sprites[index % sprites.Count];
        icon.sprite  = bgSprites[index % bgSprites.Count];
    }
Beispiel #2
0
    private void Init(string str)
    {
        Debug.LogError(str);
        JsonData jsonData = JsonMapper.ToObject(str);
        JsonData dataList = jsonData["data"];

        for (int i = 0; i < dataList.Count; i++)
        {
            string   id        = dataList[i]["id"].ToString();
            string   title     = dataList[i]["title"].ToString();
            JsonData imgs      = dataList[i]["imgs"];
            string   content   = dataList[i]["content"].ToString();
            string   open_time = dataList[i]["open_time"].ToString();

            page_1_2_Data data = new page_1_2_Data();
            data.id       = id;
            data.title    = title;
            data.content  = content;
            data.openTime = open_time;
            if (imgs != null && imgs.ToString() != "")
            {
                for (int k = 0; k < imgs.Count; k++)
                {
                    string path = imgs[k].ToJson();
                    data.images.Add(path);
                }
            }

            ItemDataList.Add(data);
        }

        for (int i = 0; i < ItemDataList.Count; i++)
        {
            GameObject go = GameObject.Instantiate(prefab);
            go.SetActive(true);
            go.transform.parent     = prefab.transform.parent;
            go.transform.localScale = Vector3.one;
            Page_1_2_Item pItem = go.GetComponent <Page_1_2_Item>();
            pItem.Init(i, ItemDataList[i], this.transform.parent.gameObject);
        }
    }