void UpdateItemPrefab()
        {
            ItemPrefabConfData tData      = mLoopListView.GetItemPrefabConfData("ItemPrefab1");
            GameObject         prefabObj  = tData.mItemPrefab;
            RectTransform      rf         = prefabObj.GetComponent <RectTransform>();
            ListItem6          itemScript = prefabObj.GetComponent <ListItem6>();
            float         w     = mLoopListView.ViewPortWidth;
            int           count = itemScript.mItemList.Count;
            GameObject    p0    = itemScript.mItemList[0].gameObject;
            RectTransform rf0   = p0.GetComponent <RectTransform>();
            float         w0    = rf0.rect.width;
            int           c     = Mathf.FloorToInt(w / w0);

            if (c == 0)
            {
                c = 1;
            }
            mItemCountPerRow = c;
            float padding = (w - w0 * c) / (c + 1);

            if (padding < 0)
            {
                padding = 0;
            }
            rf.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, w);
            if (c > count)
            {
                int dif = c - count;
                for (int i = 0; i < dif; ++i)
                {
                    GameObject    go  = Object.Instantiate(p0, Vector3.zero, Quaternion.identity, rf);
                    RectTransform trf = go.GetComponent <RectTransform>();
                    trf.localScale    = Vector3.one;
                    trf.localPosition = Vector3.zero;
                    trf.rotation      = Quaternion.identity;
                    ListItem5 t = go.GetComponent <ListItem5>();
                    itemScript.mItemList.Add(t);
                }
            }
            else if (c < count)
            {
                int dif = count - c;
                for (int i = 0; i < dif; ++i)
                {
                    ListItem5 go = itemScript.mItemList[itemScript.mItemList.Count - 1];
                    itemScript.mItemList.RemoveAt(itemScript.mItemList.Count - 1);
                    Object.DestroyImmediate(go.gameObject);
                }
            }
            float curX = padding;

            for (int k = 0; k < itemScript.mItemList.Count; ++k)
            {
                GameObject obj = itemScript.mItemList[k].gameObject;
                obj.transform.localPosition = new Vector3(curX, 0, 0);
                curX = curX + w0 + padding;
            }
            mLoopListView.OnItemPrefabChanged("ItemPrefab1");
        }
Example #2
0
 static int GetItemPrefabConfData(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 2);
         SuperScrollView.LoopListView2 obj = (SuperScrollView.LoopListView2)ToLua.CheckObject <SuperScrollView.LoopListView2>(L, 1);
         string arg0 = ToLua.CheckString(L, 2);
         SuperScrollView.ItemPrefabConfData o = obj.GetItemPrefabConfData(arg0);
         ToLua.PushObject(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }