Ejemplo n.º 1
0
        private void MoveLineToPool(ScorllItemData line)
        {
            var rectTransf = line.gameObject.GetComponent <RectTransform>();

            rectTransf.anchoredPosition += disableDistance;
            unUsedLineQueue.Enqueue(line);
        }
Ejemplo n.º 2
0
        private void ResetBaseItemData(int index, ScorllItemData itemBase)
        {
            int adjustIndex = index;

            if (isLoop)
            {
                adjustIndex = adjustIndex % totalCount;
                if (adjustIndex < 0)
                {
                    adjustIndex += totalCount;
                }
            }
            itemBase.index = index;
            var rectTransf = itemBase.gameObject.GetComponent <RectTransform>();

            rectTransf.anchoredPosition = GetPosition(index);
            if (adjustIndex < totalCount)
            {
                ResetItemLuaFunc(itemBase.gameObject, index, adjustIndex);
            }
            else
            {
                if (GLog.IsLogInfoEnabled)
                {
                    GLog.LogInfo("index is more than totalCount : " + adjustIndex);
                }
            }
        }
Ejemplo n.º 3
0
        private void MoveItemToPool(ScorllItemData item)
        {
            var rectTransf = item.gameObject.GetComponent <RectTransform>();

            rectTransf.anchoredPosition += disableDistance;
            itemViewDict.Remove(item.index + 1);
            unUsedItemQueue.Enqueue(item);
        }
Ejemplo n.º 4
0
        private void ResetLinePosition(ScorllItemData line, int index)
        {
            var rectTransf = line.gameObject.GetComponent <RectTransform>();

            rectTransf.anchoredPosition = GetVector2WithDirection(
                directionSign[directionAxisIndex] * (cellSizeWithSpace[directionAxisIndex] * (index + 1) - (cellSpace[directionAxisIndex] + lineSpace) / 2),
                0
                );
        }
Ejemplo n.º 5
0
 public void ResetItem(int index)
 {
     for (int i = 0; i < itemList.Count; i++)
     {
         ScorllItemData item = itemList[i];
         if (item.index == index)
         {
             ResetBaseItemData(index, item);
             break;
         }
     }
 }
Ejemplo n.º 6
0
        private void DelItemFromPanel(int index)
        {
            var            maxIndex   = -1;
            ScorllItemData deleteItem = null;

            for (int i = itemList.Count; i > 0; i--)
            {
                ScorllItemData item = itemList[i - 1];
                if (item.index == index)
                {
                    deleteItem = item;
                    var dataIndex = index;
                    dataIndex = dataIndex % (totalCount + 1); // 之前DelItem 中totalCount 已经减1,但是数据还没移除
                    if (dataIndex < 0)
                    {
                        dataIndex += (totalCount + 1);
                    }
                    DestroyItemLuaFunc(dataIndex);
                }
                if (item.index > maxIndex)
                {
                    maxIndex = item.index;
                }
                if (item.index > index)
                {
                    item.index -= 1;
                    UpdateItemIndexLuaFunc(item.gameObject, item.index);
                    var rectTransf = item.gameObject.GetComponent <RectTransform>();
                    rectTransf.anchoredPosition = GetPosition(item.index);
                }
            }
            if (deleteItem != null)
            {
                MoveItemToPool(deleteItem);
                itemList.Remove(deleteItem);
                if (maxIndex < totalCount)
                {
                    CreateItem(maxIndex);
                }
            }
            else
            {
                DestroyItemLuaFunc(index);
            }
        }
Ejemplo n.º 7
0
        private void ResetBaseLineData(int index, ScorllItemData lineBase)
        {
            var maxRoll     = totalLines;
            int adjustIndex = index;

            if (isLoop)
            {
                adjustIndex = adjustIndex % maxRoll;
                if (adjustIndex < 0)
                {
                    if (adjustIndex != 0)
                    {
                        adjustIndex += maxRoll;
                    }
                }
            }
            lineBase.index = index;
            ResetLinePosition(lineBase, index);
        }
Ejemplo n.º 8
0
        private void CreateItem(int index)
        {
            ScorllItemData itemData;

            if (unUsedItemQueue.Count > 0)
            {
                itemData = unUsedItemQueue.Dequeue();
                ResetBaseItemData(index, itemData);
            }
            else
            {
                int adjustIndex = index;
                if (isLoop)
                {
                    adjustIndex = adjustIndex % totalCount;
                    if (adjustIndex < 0)
                    {
                        adjustIndex += totalCount;
                    }
                }
                var obj = CreateItemLuaFunc(adjustIndex);
                if (obj == null)
                {
                    if (GLog.IsLogErrorEnabled)
                    {
                        GLog.LogError("Expected to find obj of type gameObject,but found none" + obj);
                    }
                }
                itemData            = new ScorllItemData();
                itemData.index      = index;
                itemData.gameObject = obj;
                var rectTransf = itemData.gameObject.GetComponent <RectTransform>();
                rectTransf.SetParent(contentTransform, false);
                rectTransf.anchorMin        = new Vector2(0, 1);
                rectTransf.anchorMax        = new Vector2(0, 1);
                rectTransf.pivot            = new Vector2(0, 1);
                rectTransf.sizeDelta        = cellSize;
                rectTransf.anchoredPosition = GetPosition(index);
            }
            itemList.Add(itemData);
        }
Ejemplo n.º 9
0
        private void CreateLine(int index)
        {
            ScorllItemData lineData;

            if (unUsedLineQueue.Count > 0)
            {
                lineData = unUsedLineQueue.Dequeue();
                ResetBaseLineData(index, lineData);
            }
            else
            {
                var lineObject = CreateLineLuaFunc(index);
                if (lineObject == null)
                {
                    if (GLog.IsLogErrorEnabled)
                    {
                        GLog.LogError("Expected to find obj of type gameObject,but found none" + lineObject);
                    }
                }
                var rectTransf = lineObject.GetComponent <RectTransform>();
                rectTransf.SetParent(contentTransform, false);
                rectTransf.anchorMin        = new Vector2(0, 1);
                rectTransf.anchorMax        = new Vector2(0, 1);
                rectTransf.pivot            = GetVector2WithDirection(0.5f, 1.0f - directionAxisIndex);
                rectTransf.anchoredPosition = GetVector2WithDirection(
                    directionSign[directionAxisIndex] * (cellSizeWithSpace[directionAxisIndex] * (index + 1) - (cellSpace[directionAxisIndex] + lineSpace) / 2),
                    0
                    );
                rectTransf.sizeDelta = GetVector2WithDirection(
                    lineSpace,
                    GetComponent <RectTransform>().rect.size[otherDirectionAxisIndex]
                    );
                lineData            = new ScorllItemData();
                lineData.index      = index;
                lineData.gameObject = lineObject;
            }
            lineList.Add(lineData);
        }
Ejemplo n.º 10
0
        private void AddItemIntoPanel(int index)
        {
            var            maxItemIndex = int.MinValue;
            ScorllItemData maxItem      = null;

            for (int i = 0; i < itemList.Count; i++)
            {
                ScorllItemData item = itemList[i];
                if (item.index >= index)
                {
                    item.index += 1;
                    var rectTransf = item.gameObject.GetComponent <RectTransform>();
                    rectTransf.anchoredPosition = GetPosition(item.index);
                    UpdateItemIndexLuaFunc(item.gameObject, item.index);
                }
                if (item.index > maxItemIndex)
                {
                    maxItemIndex = item.index;
                    maxItem      = item;
                }
            }

            if (usePool)
            {
                if (maxItem != null)
                {
                    var offsetIndex = GetPosIndex();
                    var lastIndex   = (viewCount + offsetIndex) * maxPerLine;
                    if (maxItemIndex >= lastIndex)
                    {
                        MoveItemToPool(maxItem);
                        itemList.Remove(maxItem);
                    }
                }
            }
            CreateItem(index);
        }