Inheritance: MonoBehaviour
Example #1
0
 private int SortByCurrentDataIndex(LoopBaseItem left, LoopBaseItem right)
 {
     if (left.CurItemIndex > right.CurItemIndex)
     {
         return(-1);
     }
     else if (left.CurItemIndex < right.CurItemIndex)
     {
         return(1);
     }
     else
     {
         return(0);
     }
 }
Example #2
0
    private void UpdateItemData(bool isToEnd, Transform targetTrs)
    {
        // update the item
        if (isToEnd)
        {
            this.curMaxDataIndex++;
            LoopBaseItem itemScript = targetTrs.GetComponent <LoopBaseItem>();
            this.curMinDataIndex = itemScript.CurItemIndex + 1;

            itemScript.CurItemIndex = this.curMaxDataIndex;
            itemScript.UpdateData(this.itemDatas[this.curMaxDataIndex]);
        }
        else
        {
            this.curMinDataIndex--;
            LoopBaseItem itemScript = targetTrs.GetComponent <LoopBaseItem>();
            this.curMaxDataIndex = itemScript.CurItemIndex - 1;

            itemScript.CurItemIndex = this.curMinDataIndex;
            itemScript.UpdateData(this.itemDatas[this.curMinDataIndex]);
        }
        // Debuger.Log(" current max index is " + this.curMaxDataIndex);
        // Debuger.Log(" current min index is " + this.curMinDataIndex);
    }
 private int SortByCurrentDataIndex(LoopBaseItem left, LoopBaseItem right)
 {
     if (left.CurItemIndex > right.CurItemIndex)
         return -1;
     else if (left.CurItemIndex < right.CurItemIndex)
         return 1;
     else
         return 0;
 }
Example #4
0
    private void InitLoopScrollView()
    {
        int realItemIndex = this.minLoopCount;

        this.itemScripts.Clear();
        this.mChildren.Clear();

        if (this.minLoopCount > this.itemDatas.Count)
        {
            // just add child.
            realItemIndex = this.itemDatas.Count;
            isInLoop      = false;

            this.curMaxDataIndex = this.itemDatas.Count;
            this.curMinDataIndex = 0;
        }
        else
        {
            this.curMinDataIndex = 0;
            this.curMaxDataIndex = this.minLoopCount - 1;
            this.isInLoop        = true;
        }

        // set the grid sort method
        // 设置grid的排序规则,防止出现排序位置显示错误
        this.mGrid.sorting = UIGrid.Sorting.Alphabetic;

        for (int i = 0; i < realItemIndex; i++)
        {
            // get item from the free game object list
            // GameObject obj = GameObject.Instantiate(this.prefab);
            GameObject obj = this.GetFreeItem();
            if (obj == null)
            {
                obj = GameObject.Instantiate(this.prefab);
            }
            if (!obj.activeSelf)
            {
                obj.SetActive(true);
            }

            GameUtility.AddChildToTarget(mGrid.transform, obj.transform);
            UIWidget widget = obj.GetComponent <UIWidget>();
            this.mChildren.Add(widget);
            this.mChildrenStatus[widget] = false;

            // 设置排序规则保证第一次显示顺序一致
            // set the item right name to sort right
            //obj.name = i.ToString();
            // get the sorted name
            obj.name = i.ToString("D5");
            LoopBaseItem itemScript = obj.GetComponent <LoopBaseItem>();
            itemScript.CurItemIndex = i;
            itemScript.UpdateData(this.itemDatas[i]);
            this.itemScripts.Add(itemScript);
        }
        mGrid.Reposition();
        this.mScrollView.ResetPosition();
        this.UpdateItemVisable(true);
        Debuger.Log("@view item count is " + this.itemDatas.Count);
    }