Example #1
0
        void Awake()
        {
            IPlayerInput input;

#if (UNITY_ANDROID && !UNITY_EDITOR)
            input = _mobileInput;
#else
            if (SystemInfo.operatingSystemFamily == OperatingSystemFamily.Other)
            {
                input = _mobileInput;
            }
            else
            {
                input = gameObject.AddComponent <KeyboardInput>();
            }
#endif
            IGameDebug debug = null;

            if (SettingsAccess.Instance.IsDebugMode)
            {
                debug = _debug;

                debug.StartDebug();
            }

            _field.Init(_zoom, _progressBar, input, debug);
        }
Example #2
0
        /// <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);
        }