void Update() { if (isDead) { return; } if (Game.inMenu) { return; } SwipeController.Update(); MoveUpdate(); }
private IEnumerator GameProcess() { var startTime = Time.time; var respawnTime = startTime + _remoteConfigsService.Configs.GameConfig.AfterStartDelay; var swipeTime = Time.time; var indexOfVegetables = 0; Dictionary <VegetableModel, IVegetableControllerWithBadAndGoodScenarios> vegetableControllers = new Dictionary <VegetableModel, IVegetableControllerWithBadAndGoodScenarios>(); while (true) { //Initialized Vegetables if (indexOfVegetables < _gameDataModel.Vegetables.Count && Time.time >= respawnTime) { GameObject prefab = _localConfig.VegetablePrefab; if (_gameDataModel.Vegetables[indexOfVegetables].CatchedByPaw) { prefab = _localConfig.VegetableCatchedByPawPrefab; } if (_gameDataModel.Vegetables[indexOfVegetables].EscapedAndFallen) { prefab = _localConfig.VegetableWithEscapedAndFallenPrefab; } if (_gameDataModel.Vegetables[indexOfVegetables].EscapedBehindScreen) { prefab = _localConfig.VegetableWithEscapedBehindScreenPrefab; } GameObject go = Instantiate(prefab, _vegetablesRootParent); var vegetableController = go.GetComponent <IVegetableBaseController>(); vegetableController.Init(_remoteConfigsService.Configs.GameConfig, _localConfig, _gameDataModel.Vegetables[indexOfVegetables]); if (vegetableController is IVegetableControllerWithBadAndGoodScenarios) { vegetableControllers.Add(_gameDataModel.Vegetables[indexOfVegetables], (IVegetableControllerWithBadAndGoodScenarios)vegetableController); } indexOfVegetables++; if (indexOfVegetables < _gameDataModel.Vegetables.Count) { respawnTime = startTime + _gameDataModel.Vegetables[indexOfVegetables].CreateTime; } } //Swipes if (Time.time >= swipeTime) { if (_queueSwipes.Count > 0) { _gameDataModel.Chef.CurrentShelf = _queueSwipes.Dequeue(); swipeTime = Time.time + _remoteConfigsService.Configs.GameConfig.DurationOfSwipe; } } //Check states of Vegetables models int failures = 0; int total = 0; foreach (var vegetable in _gameDataModel.Vegetables) { if (!vegetable.Launched) { continue; } if (vegetable.VegetableState == VegetableState.canСatch) { vegetable.VegetableState = VegetableState.waitResult; if (vegetable.ShelfIndex == _gameDataModel.Chef.CurrentShelf) { vegetableControllers[vegetable].RunGoodScenario(); } else { vegetableControllers[vegetable].RunBadScenario(); } } if ((vegetable.VegetableState == VegetableState.caught && _remoteConfigsService.Configs.GameConfig.Vegetables[vegetable.VegetableConfigIndex].IsFresh == false) || (vegetable.VegetableState == VegetableState.fallen && _remoteConfigsService.Configs.GameConfig.Vegetables[vegetable.VegetableConfigIndex].IsFresh == true)) { failures++; } if (vegetable.VegetableState == VegetableState.caught || vegetable.VegetableState == VegetableState.fallen || vegetable.VegetableState == VegetableState.catchByFeature) { total++; } } _inputController.Update(); _gameDataModel.Chef.CurrentStars = _remoteConfigsService.Configs.GameConfig.StartStarsCount - failures; if (total == _gameDataModel.Vegetables.Count) { _gameResult.text = "Молодец!"; yield return(new WaitForSeconds(_remoteConfigsService.Configs.GameConfig.PlayerWinDelay)); RestartLevel(); yield break; } if (_gameDataModel.Chef.CurrentStars <= 0) { _gameResult.text = "Игра окончена"; yield return(new WaitForSeconds(_remoteConfigsService.Configs.GameConfig.GameOverDelay)); RestartLevel(); yield break; } yield return(null); } }