Exemplo n.º 1
0
        /// <summary>
        /// Изменилась текущая позиция игрока на поле
        /// </summary>
        private void OnPlayerPositionChanged()
        {
            var newCellPosition = SettingsAccess.GetCellBeginPosition(_currentCellItemPosition);

            // Если изменилась текущая ячейка игрока на поле, добавим разницу между прямоугольниками старых и новых координат игрока на генерацию
            if (newCellPosition != _currentCellPosition)
            {
                var prevRect        = SettingsAccess.GetFieldRectPx(_currentCellPosition);
                var prevVisibleRect = SettingsAccess.GetFullGenerationRect(_currentCellPosition);

                var newRect        = SettingsAccess.GetFieldRectPx(newCellPosition);
                var newVisibleRect = SettingsAccess.GetFullGenerationRect(newCellPosition);

                // Разница между старым прямоугольником всего поля и текущим
                var rectsToFill = RectIntTool.Subtract(newRect, prevRect);
                // Разница между старым прямоугольником полностью генерируемого мира вокруг игрока и текущим
                var visibleRectsFill = RectIntTool.Subtract(newVisibleRect, prevVisibleRect);

                visibleRectsFill.AddRange(rectsToFill);

                if (visibleRectsFill.Count > 0)
                {
                    // Добавить задание на генерацию - сперва прямоугольники полностью генерируемых ячеек вокруг игрока, потом прямоугольники поля
                    _generator.AppendRects(visibleRectsFill, true);
                }

                _currentCellPosition = newCellPosition;
            }

            if (_zoom.IsAdvancedView() == false)
            {
                RefreshNormalVisibleArea();

                SetPosition();
            }
            else
            {
                if (_zoom.IsCellsView())
                {
                    _sortedCellsVisitor.AppendRect(_zoom.GetVisibleRect(_currentCellPosition));
                }
                else
                {
                    _sortedCellsVisitor.AppendRect(_zoom.GetVisibleRect(_currentCellItemPosition));
                }
            }
        }
Exemplo n.º 2
0
        public void VisibleRectCheck()
        {
            var rects = new RectInt[]
            {
                ZoomControl.GetVisibleRect(Vector2Int.zero, 200)
            };

            var checkRects = new RectInt[]
            {
                new RectInt(-100, -100, 200, 200),
            };

            Assert.AreEqual(rects.Length, checkRects.Length);

            for (int i = 0; i < rects.Length; i++)
            {
                Assert.AreEqual(rects[i], checkRects[i]);
            }
        }