예제 #1
0
    private IEnumerator Prepare()
    {
        _btnBack.onClick.AddListener(BackButtonPressedHandler);
        _btnRestart.onClick.AddListener(RestartButtonPressedHandler);
        _gameDataModel = new GameDataModel();
        _gameDataModel.Chef.CurrentStars = _remoteConfigsService.Configs.GameConfig.StartStarsCount;
        var background = Resources.Load <Sprite>(_remoteConfigsService.Configs.GameConfig.GameBackGroundImageName);

        if (background == null)
        {
            throw new UnassignedReferenceException($"{nameof(background)}: {_remoteConfigsService.Configs.GameConfig.GameBackGroundImageName} not found!");
        }
        _backGround.sprite = background;
        _chefUI.Init(_localConfig, _gameDataModel.Chef);
        _starsUI.Init(_gameDataModel.Chef);
        _queueSwipes     = new Queue <int>();
        _inputController = new SwipeController(OnSwipeDetected, _localConfig, _remoteConfigsService.Configs.GameConfig);

        float createStartTime = 0;
        var   shelf           = Random.Range(0, _localConfig.Shelfs.Count);

        shelfList = new List <int>();

        for (var i = 0; i < _remoteConfigsService.Configs.GameConfig.FreshVegatablesCount; i++)
        {
            shelf = GetIndexShelf(shelf);
            VegetableModel newVegetable;
            newVegetable            = CreateVegetableModel(true, shelf);
            newVegetable.CreateTime = createStartTime - _remoteConfigsService.Configs.GameConfig.Vegetables[newVegetable.VegetableConfigIndex].DurationOfPath;
            _gameDataModel.Vegetables.Add(newVegetable);

            if (Random.value <= _remoteConfigsService.Configs.GameConfig.PercentageOfSpoiledVegetables)
            {
                shelf                   = GetIndexShelf(shelf);
                newVegetable            = CreateVegetableModel(false, Utils.RandomExclude(_localConfig.Shelfs.Count, shelf));
                newVegetable.CreateTime = createStartTime - _remoteConfigsService.Configs.GameConfig.Vegetables[newVegetable.VegetableConfigIndex].DurationOfPath -
                                          _remoteConfigsService.Configs.GameConfig.VegetablesCreateRate / 2;
                _gameDataModel.Vegetables.Add(newVegetable);
            }

            createStartTime += _remoteConfigsService.Configs.GameConfig.VegetablesCreateRate;
        }

        _gameDataModel.Vegetables.Sort((a, b) =>
        {
            return(a.CreateTime.CompareTo(b.CreateTime));
        }
                                       );

        for (int i = _gameDataModel.Vegetables.Count; i > 0; i--)
        {
            _gameDataModel.Vegetables[i - 1].CreateTime -= (_gameDataModel.Vegetables[0].CreateTime - _remoteConfigsService.Configs.GameConfig.AfterStartDelay);
        }

#if UNITY_EDITOR
        DebugInfo();
#endif

        StartCoroutine(GameProcess());

        yield return(null);
    }
예제 #2
0
 public void InitPuntuacion(int maxPuntuacion)
 {
     StarsPuntuacion.Init(maxPuntuacion);
 }