Пример #1
0
    static void Main(string[] args)
    {
        Console.WriteLine("Hello World!");

        List <int> list = new List <int>();

        list.Add(0);
        list.Add(1);
        list.Add(2);
        list.Add(3);
        list.Add(4);
        Deque <int> deque = new Deque <int>(list, true);

        deque.PrintToConsole();
        Console.WriteLine();
        deque.RemoveHead();
        deque.RemoveHead();
        deque.AddTail(5);
        deque.AddHead(1);
        deque.AddHead(0);
        deque.AddHead(-1);
        deque.AddHead(-2);
        deque.AddHead(-3);
        deque.PrintToConsole();
        Console.WriteLine();
        deque.RemoveTail();
        deque.RemoveTail();
        deque.PrintToConsole();
        Console.WriteLine();
        deque.AddTail(4);
        deque.AddTail(5);
        deque.AddTail(6);
        deque.AddTail(7);
        deque.AddTail(8);
        deque.PrintToConsole();
        Console.WriteLine();

        foreach (var item in deque)
        {
            Console.WriteLine(item);
        }

        //int[] ints = new int[20];
        //deque.CopyTo(ints, 3);

        //foreach (int number in ints)
        //{
        //    Console.WriteLine(number);
        //}

        Console.ReadKey();
    }
Пример #2
0
        public void MyAddBeginingTest()
        {
            var d = new Deque <int>();
            var l = new List <int>();


            Random rnd   = new Random();
            int    upper = 10000;

            for (int i = 0; i < upper; i++)
            {
                d.AddHead(i);
                l.Add(i);
            }
            Console.WriteLine("some shit");
            for (int i = 0; i < upper; i++)
            {
                int ll = l[upper - 1 - i];
                int dd = d[i];
                Assert.AreEqual(l[upper - 1 - i], d[i]);
            }
        }
Пример #3
0
 public void AddFront(ref Vector3D position)
 {
     m_positions.AddHead(ref position);
 }
Пример #4
0
    // Update is called once per frame
    void Update()
    {
        if (cellTotalCount == 0 || Cells.Count == 0)
        {
            return;
        }
        int i = 0;

        foreach (IScrollRectExCallBack cell in Cells)
        {
            var index = startIndex + i;
            var pos   = new Vector2(0, GetCellY(index));
            (cell.transform as RectTransform).anchoredPosition = scrollRect.content.anchoredPosition - pos;
            i++;
        }

        if (startIndex != 0)
        {
            var preIndex = startIndex - 1;
            var pos      = new Vector2(0f, GetCellY(preIndex));
            var bottomY  = (scrollRect.content.anchoredPosition - pos).y - cellSizeY / 2f;
            if (bottomY < 0f)
            {
                startIndex = preIndex;
                var cell = GetCellFromPool();
                cell.ScrollCellIndex(startIndex);
                cell.transform.name = startIndex.ToString();
                var siblingIndex = CellParent.childCount - (endIndex - startIndex);
                cell.transform.SetSiblingIndex(siblingIndex);
                Cells.AddHead(cell);
                (Cells.GetHead().transform as RectTransform).anchoredPosition = scrollRect.content.anchoredPosition - pos;
            }
        }

        if (endIndex != cellTotalCount - 1)
        {
            var nextIndex = endIndex + 1;
            var pos       = new Vector2(0f, GetCellY(nextIndex));
            var topY      = (scrollRect.content.anchoredPosition - pos).y + cellSizeY / 2f;
            if (topY > -scrollRectHeight)
            {
                endIndex = nextIndex;
                var cell = GetCellFromPool();
                cell.ScrollCellIndex(endIndex);
                cell.transform.name = endIndex.ToString();
                cell.transform.SetAsLastSibling();
                Cells.AddTail(cell);
                (Cells.GetTail().transform as RectTransform).anchoredPosition = scrollRect.content.anchoredPosition - pos;
            }
        }
        //
        var startPos    = new Vector2(0f, GetCellY(startIndex));
        var cellBottomY = (scrollRect.content.anchoredPosition - startPos).y - cellSizeY / 2f;

        if (cellBottomY > 0f)
        {
            var cell = Cells.GetHead();
            cell.transform.SetAsFirstSibling();
            Cells.RemoveHead();
            (cell.transform as RectTransform).anchoredPosition = new Vector2(999999f, 0f);
            startIndex = startIndex + 1;
            ReleaseCell(cell);
        }

        var endPos   = new Vector2(0f, GetCellY(endIndex));
        var itemTopY = (scrollRect.content.anchoredPosition - endPos).y + cellSizeY / 2f;

        if (itemTopY < -scrollRectHeight)
        {
            var cell = Cells.GetTail();
            cell.transform.SetAsFirstSibling();
            Cells.RemoveTail();
            (cell.transform as RectTransform).anchoredPosition = new Vector2(999999f, 0f);
            endIndex = endIndex - 1;
            ReleaseCell(cell);
        }
    }
Пример #5
0
    // Update is called once per frame
    void Update()
    {
        if (Cells.Count == 0)
        {
            return;
        }

        foreach (int cellIndex in Cells)
        {
            var index     = cellIndex;
            var cellsDesc = CellsDescDic[index];
            for (int j = 0; j < cellsDesc.Ids.Count; j++)
            {
                var cell = cellsDesc.CallBack1s[j];
                (cell.transform as RectTransform).anchoredPosition = scrollRect.content.anchoredPosition - cellsDesc.ArchoredPoss[j];
            }
        }

        if (startIndex != 0)
        {
            var preIndex  = startIndex - 1;
            var cellsDesc = CellsDescDic[preIndex];
            var pos       = cellsDesc.ArchoredPoss[0].y;
            var cellSizeY = cellsDesc.LayoutDesc.CellSize.y + cellsDesc.LayoutDesc.Spacing.y;
            var bottomY   = (scrollRect.content.anchoredPosition.y - pos) - cellSizeY / 2f;
            if (bottomY < 0f)
            {
                startIndex = preIndex;
                cellsDesc.CallBack1s.Clear();
                for (int i = 0; i < cellsDesc.Ids.Count; i++)
                {
                    var cell = GetCellFromPool(cellsDesc.LayoutDesc.Prefab);
                    cell.ScrollCellIndex((int)cellsDesc.Ids[i]);
                    cellsDesc.CallBack1s.Add(cell);
                    cell.transform.name = cellsDesc.Ids[i].ToString();
                    cell.prefab         = cellsDesc.LayoutDesc.Prefab;
                    (cell.transform as RectTransform).anchoredPosition = scrollRect.content.anchoredPosition - cellsDesc.ArchoredPoss[0];
                }
                Cells.AddHead(startIndex);
            }
        }

        if (endIndex != CellsDescDic.Count - 1)
        {
            var nextIndex = endIndex + 1;
            var cellsDesc = CellsDescDic[nextIndex];
            var pos       = cellsDesc.ArchoredPoss[0].y;
            var cellSizeY = cellsDesc.LayoutDesc.CellSize.y + cellsDesc.LayoutDesc.Spacing.y;
            var topY      = (scrollRect.content.anchoredPosition.y - pos) + cellSizeY / 2f;
            if (topY > -scrollRectHeight)
            {
                endIndex = nextIndex;
                cellsDesc.CallBack1s.Clear();
                for (int i = 0; i < cellsDesc.Ids.Count; i++)
                {
                    var cell = GetCellFromPool(cellsDesc.LayoutDesc.Prefab);
                    cellsDesc.CallBack1s.Add(cell);
                    cell.ScrollCellIndex((int)cellsDesc.Ids[i]);
                    cell.transform.name = cellsDesc.Ids[i].ToString();
                    cell.prefab         = cellsDesc.LayoutDesc.Prefab;
                    (cell.transform as RectTransform).anchoredPosition = scrollRect.content.anchoredPosition - cellsDesc.ArchoredPoss[0];
                }


                Cells.AddTail(endIndex);
            }
        }
        ////
        {
            var cellsDesc = CellsDescDic[startIndex];
            var startPos  = cellsDesc.ArchoredPoss[0].y;
            var cellSizeY = cellsDesc.LayoutDesc.CellSize.y + cellsDesc.LayoutDesc.Spacing.y;

            var cellBottomY = (scrollRect.content.anchoredPosition.y - startPos) - cellSizeY / 2f;
            if (cellBottomY > 0f)
            {
                Cells.RemoveHead();
                for (int i = 0; i < cellsDesc.CallBack1s.Count; i++)
                {
                    ReleaseCell(cellsDesc.CallBack1s[i]);
                    (cellsDesc.CallBack1s[i].transform as RectTransform).anchoredPosition = new Vector2(999999f, 0f);
                }
                cellsDesc.CallBack1s.Clear();

                startIndex = startIndex + 1;
            }
        }


        {
            var cellsDesc = CellsDescDic[endIndex];
            var endPos    = cellsDesc.ArchoredPoss[0].y;
            var cellSizeY = cellsDesc.LayoutDesc.CellSize.y + cellsDesc.LayoutDesc.Spacing.y;

            var itemTopY = (scrollRect.content.anchoredPosition.y - endPos) + cellSizeY / 2f;
            if (itemTopY < -scrollRectHeight)
            {
                Cells.RemoveTail();
                for (int i = 0; i < cellsDesc.CallBack1s.Count; i++)
                {
                    ReleaseCell(cellsDesc.CallBack1s[i]);
                    (cellsDesc.CallBack1s[i].transform as RectTransform).anchoredPosition = new Vector2(999999f, 0f);
                }
                endIndex = endIndex - 1;
            }
        }
    }