public void ShiftCallbackTest()
    {
        foreach (var testCase in m_shiftCallbackTestCases)
        {
            var unitGaridManager = new UnitGridManager
                                       (testCase.gridWidth,
                                       testCase.gridHeight,
                                       testCase.horizontalCount,
                                       testCase.verticalCount);
            unitGaridManager.UpdateElementCount(testCase.elementCount);

            foreach (var shiftCallback in testCase.shiftCallbacks)
            {
                var movedIndexes       = new List <int>();
                var dataUpdatedIndexes = new List <int>();
                unitGaridManager.Shift(shiftCallback.scrollValue,
                                       (index, delta) =>
                {
                    movedIndexes.Add(index);
                },
                                       (index, delta) =>
                {
                    dataUpdatedIndexes.Add(index);
                });

                Assert.True(IsSamePrimitiveList(movedIndexes, shiftCallback.expectedMovedIndexes));
                Assert.True(IsSamePrimitiveList(dataUpdatedIndexes, shiftCallback.expectedUpdatedIndexes));
            }
        }
    }
Beispiel #2
0
    // ================================= called by ScrollRect component
    public void OnScrolled()
    {
        var currentScrolledValue = m_unitGridManager.GetScrollRectHeight() * (1 - m_scrollRect.verticalNormalizedPosition);

        if (currentScrolledValue != m_oldScrolledValue)
        {
            UnitIconImageProvider.Instance.Stop();

            m_unitGridManager.Shift(currentScrolledValue,
                                    (index, delta) =>
            {
                if (delta == 0)
                {
                    return;
                }

                float height = m_unitGridManager.GetGridsRectHeight();
                Vector2 vec2 = delta > 0
                        ? Vector2.down * height
                        : Vector2.up * height;
                m_units[index].MoveBy(vec2);
            },
                                    (index, delta) =>
            {
                ApplyUnitData(m_unitGridManager.GetModifiedIndex(index), m_unitViewModels[index]);
            });
        }

        m_oldScrolledValue = currentScrolledValue;
    }
    public void ShiftTest()
    {
        foreach (var testCase in m_shiftTestCases)
        {
            var unitGaridManager = new UnitGridManager
                                       (testCase.gridWidth,
                                       testCase.gridHeight,
                                       testCase.horizontalCount,
                                       testCase.verticalCount);
            unitGaridManager.UpdateElementCount(testCase.elementCount);

            foreach (var verticalOffset in testCase.verticalOffsets)
            {
                unitGaridManager.Shift(verticalOffset.scrollValue, null, null);
                Assert.True(unitGaridManager.GetVerticalOffset() == verticalOffset.expected);
            }
        }
    }