Ejemplo n.º 1
0
 /// <summary>
 /// 列表删除数据
 /// </summary>
 /// <param name="data"></param>
 public void RemoveData(System.Object data)
 {
     if (data != null && DataAndPosProviders != null)
     {
         RefreshContentSize();
         var     count = DataAndPosProviders.Count;
         DataPos dp    = null;
         for (var i = 0; i < count; i++)
         {
             dp = DataAndPosProviders[i];
             if (dp.Data != data)
             {
                 continue;
             }
             if (dp.VisableGO != null)
             {
                 RecycleChildItem(dp.VisableGO, dp.Data);
                 dp.VisableGO = null;
             }
             DataAndPosProviders.Remove(dp);
             SetDPsChanged();
             break;
         }
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// 计算某一位置的item应该占多大
        /// </summary>
        /// <param name="dp"></param>
        /// <param name="column"></param>
        /// <param name="row"></param>
        /// <param name="lastItemRect"></param>
        /// <param name="isFirst"></param>
        /// <returns></returns>
        private Rect GetBlockRect(DataPos dp, Int32 column, Int32 row, Rect lastItemRect, Boolean isFirst, RectTransform.Edge dir)
        {
            switch (LayoutMode)
            {
            case LayoutType.Grid:
                return(new Rect(GetGridBlockSizeX(false) * column, GetGridBlockSizeY(false) * row, CellSize.x, CellSize.y));

            case LayoutType.Horizontal:
            case LayoutType.Vertical:
                var size = Vector2.zero;
                if (CalcSizeAction != null)
                {
                    size = CalcSizeAction.Invoke(dp.Data);
                }
                else
                {
                    size = (ChildItem.transform as RectTransform).sizeDelta;
                }
                return(new Rect(LayoutMode == LayoutType.Horizontal ?
                                (lastItemRect.position + new Vector2(lastItemRect.width + (isFirst ? 0: SpacingSize.x), 0))
                                                                        :
                                (lastItemRect.position + new Vector2(0, lastItemRect.height + (isFirst ? 0 : SpacingSize.y)))
                                , size));
            }
            return(Rect.zero);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// 获得一个data对应的index
 /// </summary>
 /// <param name="data"></param>
 /// <returns></returns>
 public Int32 GetDataIndex(System.Object data)
 {
     if (data != null && DataAndPosProviders != null)
     {
         RefreshContentSize();
         var     count = DataAndPosProviders.Count;
         DataPos dp    = null;
         for (var i = 0; i < count; i++)
         {
             dp = DataAndPosProviders[i];
             if (dp.Data == data)
             {
                 return(i);
             }
         }
     }
     return(-1);
 }
Ejemplo n.º 4
0
 /// <summary>
 /// 获得一个GO对应的index
 /// </summary>
 /// <param name="go"></param>
 /// <returns></returns>
 public Int32 GetGameObjectIndex(GameObject go)
 {
     if (go != null && DataAndPosProviders != null)
     {
         RefreshContentSize();
         var     count = DataAndPosProviders.Count;
         DataPos dp    = null;
         for (var i = 0; i < count; i++)
         {
             dp = DataAndPosProviders[i];
             if (dp.VisableGO == go)
             {
                 return(i);
             }
         }
     }
     return(-1);
 }
Ejemplo n.º 5
0
 /// <summary>
 /// 获得某个item的位置
 /// </summary>
 /// <param name="go"></param>
 /// <returns></returns>
 public Boolean TryGetPos(System.Object data, out Vector2 ret)
 {
     if (data != null && DataAndPosProviders != null)
     {
         RefreshContentSize();
         var     count = DataAndPosProviders.Count;
         DataPos dp    = null;
         for (var i = 0; i < count; i++)
         {
             dp = DataAndPosProviders[i];
             if (dp.Data == data)
             {
                 ret = dp.RectReal.position;
                 return(true);
             }
         }
     }
     ret = Vector2.negativeInfinity;
     return(false);
 }
Ejemplo n.º 6
0
 /// <summary>
 /// 获得某个item的位置
 /// </summary>
 /// <param name="go"></param>
 /// <returns></returns>
 public Boolean TryGetPos(GameObject go, out Vector2 ret)
 {
     if (go != null && DataAndPosProviders != null)
     {
         RefreshContentSize();
         var     count = DataAndPosProviders.Count;
         DataPos dp    = null;
         for (var i = 0; i < count; i++)
         {
             dp = DataAndPosProviders[i];
             if (dp.VisableGO == go)
             {
                 ret = dp.RectReal.position;
                 return(true);
             }
         }
     }
     ret = Vector2.negativeInfinity;
     return(false);
 }
Ejemplo n.º 7
0
 /// <summary>
 /// 判断是否相交
 /// </summary>
 /// <param name="otherData"></param>
 /// <returns></returns>
 public Boolean Overlaps(DataPos otherData)
 {
     return(Rect.Overlaps(otherData.Rect));
 }
Ejemplo n.º 8
0
        /// <summary>
        /// 根据当前的数据,重新计算一下Content的大小
        /// </summary>
        private void RefreshContentSize()
        {
            if (!IsDPsChanged)
            {
                return;
            }
            var vp = viewport;

            IsDPsChanged = false;
            IsMoveDirty  = true;
            if (DataAndPosProviders == null)
            {
                return;
            }
            switch (LayoutMode)
            {
            case LayoutType.Grid:
                if (FirstEdge == RectTransform.Edge.Bottom || FirstEdge == RectTransform.Edge.Top)
                {
                    if (SecondEdge == RectTransform.Edge.Bottom || SecondEdge == RectTransform.Edge.Top)
                    {
                        Debug.LogError(String.Format("Order Dir ({0})--->({1}) Error", FirstEdge, SecondEdge));
                        return;
                    }
                }
                else
                {
                    if (SecondEdge == RectTransform.Edge.Left || SecondEdge == RectTransform.Edge.Right)
                    {
                        Debug.LogError(String.Format("Order Dir ({0})--->({1}) Error", FirstEdge, SecondEdge));
                        return;
                    }
                }
                break;

            case LayoutType.Vertical:
                if (FirstEdge == RectTransform.Edge.Left || FirstEdge == RectTransform.Edge.Right)
                {
                    Debug.LogError(String.Format("Order Dir {0} Error", FirstEdge));
                    return;
                }
                break;

            case LayoutType.Horizontal:
                if (FirstEdge == RectTransform.Edge.Top || FirstEdge == RectTransform.Edge.Bottom)
                {
                    Debug.LogError(String.Format("Order Dir {0} Error", FirstEdge));
                    return;
                }
                break;
            }

            var dataCount = DataAndPosProviders.Count;

            RowCount    = 1;
            ColumnCount = 1;
            //求行数与列数
            if (dataCount > 0)
            {
                switch (LayoutMode)
                {
                case LayoutType.Grid:
                    switch (GridConstraint)
                    {
                    case GridLayoutGroup.Constraint.Flexible:
                        //优先排满一行
                        ColumnCount = Mathf.Max(Mathf.FloorToInt(vp.rect.width / GetGridBlockSizeX(false)), 1);
                        RowCount    = Mathf.Max(Mathf.CeilToInt((Single)dataCount / ColumnCount), 1);
                        break;

                    case GridLayoutGroup.Constraint.FixedColumnCount:
                        ColumnCount = Mathf.Max(ConstraintCount, 1);
                        RowCount    = Mathf.Max(Mathf.CeilToInt((Single)dataCount / ColumnCount), 1);
                        break;

                    case GridLayoutGroup.Constraint.FixedRowCount:
                        RowCount    = Mathf.Max(ConstraintCount, 1);
                        ColumnCount = Mathf.Max(Mathf.CeilToInt((Single)dataCount / RowCount), 1);
                        break;

                    default:
                        Debug.LogError("InitScrollRect Error GridConstraint:" + GridConstraint);
                        break;
                    }
                    break;

                case LayoutType.Horizontal:
                    ColumnCount = dataCount;
                    RowCount    = 1;
                    break;

                case LayoutType.Vertical:
                    ColumnCount = 1;
                    RowCount    = dataCount;
                    break;

                default:
                    Debug.LogError("InitScrollRect LayoutMode:" + LayoutMode);
                    break;
                }
            }

            //Debug.LogError("Content size:" + size);
            //行数列数已经确定,下面该设置每个item的位置和大小了
            var     row      = 0;
            var     column   = 0;
            DataPos tmpDP    = null;
            var     lastRect = Rect.zero;
            var     isFirst  = true;

            if ((LayoutMode == LayoutType.Horizontal && FirstEdge == RectTransform.Edge.Left) ||
                (LayoutMode == LayoutType.Vertical && FirstEdge == RectTransform.Edge.Bottom))
            {
                for (var i = dataCount - 1; i >= 0; --i)
                {
                    tmpDP = DataAndPosProviders[i];
                    GetRowAndCol(i, RowCount, ColumnCount, LayoutMode, FirstEdge, SecondEdge, out row, out column);
                    tmpDP.Index = i;
                    var tmpRect = GetBlockRect(tmpDP, column, row, lastRect, isFirst, FirstEdge);
                    isFirst = false;
                    tmpDP.SetRect(tmpRect);
                    lastRect = tmpRect;
                    //Debug.LogError("data :" + i + " , " + tmpDP.ToString() + "," +tmpDP.Data.ToString());
                }
            }
            else
            {
                for (var i = 0; i < dataCount; ++i)
                {
                    tmpDP = DataAndPosProviders[i];
                    GetRowAndCol(i, RowCount, ColumnCount, LayoutMode, FirstEdge, SecondEdge, out row, out column);
                    tmpDP.Index = i;
                    var tmpRect = GetBlockRect(tmpDP, column, row, lastRect, isFirst, FirstEdge);
                    isFirst = false;
                    tmpDP.SetRect(tmpRect);
                    lastRect = tmpRect;
                    //Debug.LogError("data :" + i + " , " + tmpDP.ToString() + "," +tmpDP.Data.ToString());
                }
            }

            var size    = Vector2.zero;
            var tmpVec2 = Vector2.zero;

            //这里需要上边遍历后的结果,所以拆成两部分了
            if (dataCount > 0)
            {
                switch (LayoutMode)
                {
                case LayoutType.Grid:
                    // 如果要使用grid模式,理论上不允许size小于等于0,所以会自动设置到0.01f上
                    CellSize = new Vector2(Mathf.Max(CellSize.x, 0.01f), Mathf.Max(CellSize.y, 0.01f));
                    size.x   = GetGridBlockSizeX(true) + GetGridBlockSizeX(false) * Mathf.Max(0, (ColumnCount - 1));
                    size.y   = GetGridBlockSizeY(true) + GetGridBlockSizeY(false) * Mathf.Max(0, (RowCount - 1));
                    break;

                case LayoutType.Horizontal:
                case LayoutType.Vertical:
                    //水平和竖直布局就很随意了,按照item自己的size进行计算
                    //如果有通过data计算CalcSizeAction方法就使用它进行计算
                    var tmpMax = Vector2.zero;
                    var tmpAll = Vector2.zero;
                    if (CalcSizeAction != null)
                    {
                        tmpVec2 = Vector2.zero;
                        for (int i = 0; i < dataCount; ++i)
                        {
                            tmpDP = DataAndPosProviders[i];
                            //GetRowAndCol(i, RowCount, ColumnCount, LayoutMode, FirstEdge, SecondEdge, out row, out column);
//                              row = i / ColumnCount;
//                              column = i % ColumnCount;
                            tmpVec2 = tmpDP.Rect.size + new Vector2((i == 0)?0: SpacingSize.x, (i == 0) ? 0 : SpacingSize.y);
                            tmpAll += tmpVec2;
                            tmpMax  = new Vector2(Mathf.Max(tmpMax.x, tmpVec2.x), Mathf.Max(tmpMax.y, tmpVec2.y));
                        }
                        size = LayoutMode == LayoutType.Vertical ? new Vector2(tmpMax.x, tmpAll.y) : new Vector2(tmpAll.x, tmpMax.y);
                    }
                    else if (ChildItem != null)
                    {
                        tmpVec2 = (ChildItem.transform as RectTransform).rect.size;
                        size.x  = tmpVec2.x + (tmpVec2.x + SpacingSize.x) * Mathf.Max(0, (ColumnCount - 1));
                        size.y  = tmpVec2.y + (tmpVec2.y + SpacingSize.y) * Mathf.Max(0, (RowCount - 1));
                    }
                    else
                    {
                        Debug.LogError("Error CalcSizeAction is null, and  Childitem is null too");
                    }
                    break;
                }
            }
            var ct = this.content;

            ct.sizeDelta = size;
            //所有数据都设置好了,也得到了真正的size,下一步就是设置每个item真正的位置了
            for (var i = 0; i < dataCount; ++i)
            {
                DataAndPosProviders[i].RefreshRealRect(size, FirstEdge, SecondEdge);
            }
        }
Ejemplo n.º 9
0
 public FacturacionControl()
 {
     contexdb = new DataPos();
 }