public void LineEnumeratorCheck() { var rect = SettingsAccess.GetFieldRectPx(Vector2Int.zero); CheckLine(rect, 100, 100); CheckLine(rect, 100, 1000); CheckLine(rect, 1000, 100); CheckLine(rect, 1000, 1000); }
/// <summary> /// Инициализация поля /// </summary> /// <param name="zoom">Зум поля</param> /// <param name="progress">Прогресс инициализации</param> /// <param name="input">Управление игроком</param> /// <param name="debug">Отладка</param> public void Init(ZoomControl zoom, ProgressBar progress, IPlayerInput input, IGameDebug debug) { // Подпишемся на изменения зума _zoom = zoom; _input = input; // Инициализируем случайные значения положения игрока на поле и его рейтинг _currentCellPosition = SettingsAccess.GetRandomFieldPosition(); _currentCellItemPosition = SettingsAccess.GetRandomCellPosition(_currentCellPosition); _playerRating = NoiseTool.GetRandomPlayerRating(); // Инициализируем коллекцию ячеек _cells = new CellCollection(_playerRating); // Инициализируем механизм поиска первых <see cref="SettingsAccess.MaxAdvancedVisiblePlanet"/> планет, ближайших по рейтингу к рейтингу игрока _sortedCellsVisitor = gameObject.AddComponent <SortedCellsVisitor>().Init(_cells, _playerRating, debug); _sortedCellsVisitor.OnProcessEnd += OnSearchTopRatingsEnd; string generationString; if (SystemInfo.supportsComputeShaders) { // Если поддерживаются Computed Shader _generator = gameObject.AddComponent <ComputedShaderNoiseGenerator>() .SetDebug(debug); generationString = "GENERATE COMPUTED SHADER"; } else { #if (UNITY_ANDROID) // По идее, должен поддерживаться большинством платформ, добавлять директивы препроцессора по мере тестирования _generator = gameObject.AddComponent <CustomRenderTextureNoiseGenerator>() .SetDebug(debug); generationString = "GENERATE RENDER TEXTURE"; #else // Для всех остальных платформ. _generator = gameObject.AddComponent <CpuNoiseGenerator>() .SetDebug(debug); generationString = "GENERATE CPU"; #endif } _generator.OnProcessEnd += OnGenerationEnd; // Добавим первое задание на генерацию всего поля _generator.AppendRect(SettingsAccess.GetFieldRectPx(_currentCellPosition)); // Отобразим прогресс progress.Begin(() => _generator.GetProgress(), generationString, OnEndInit); }
/// <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)); } } }