Пример #1
0
 private void Awake() => Instance = this;
Пример #2
0
        private async void Awake()
        {
            this.resolutionManager = ResolutionManager.Instance;
            this.poolManager       = PoolManager.Instance;
            this.matrixController  = MatrixController.Instance;
            this.levelDataManager  = LevelDataManager.Instance;
            this.audioManager      = AudioManager.Instance;

            while (this.resolutionManager == null)
            {
                await Task.Delay(TimeSpan.FromSeconds(.1f));

                this.resolutionManager = ResolutionManager.Instance;
            }

            while (this.levelDataManager == null)
            {
                await Task.Delay(TimeSpan.FromSeconds(.1f));

                this.levelDataManager = LevelDataManager.Instance;
            }

            while (this.matrixController == null)
            {
                await Task.Delay(TimeSpan.FromSeconds(.1f));

                this.matrixController = MatrixController.Instance;
            }

            while (this.poolManager == null)
            {
                await Task.Delay(TimeSpan.FromSeconds(.1f));

                this.poolManager = PoolManager.Instance;
            }

            while (this.audioManager == null)
            {
                await Task.Delay(TimeSpan.FromSeconds(.1f));

                this.audioManager = AudioManager.Instance;
            }

            this.SwipesRemainsCount.Value = this.gameOptions.Swipes;

            this.matrixController.GameOptions        = this.gameOptions;
            this.matrixController.OnCandyDestroyed  += this.OnCandyDestroyed;
            this.matrixController.OnSuccesfullSwipe += () => this.SwipesRemainsCount.Value--;
            this.matrixController.OnBombCreated     += this.audioManager.OnBombCreated;
            this.matrixController.OnSwiped          += this.audioManager.PlaySwipe;

            this.winPanel.RestartButton.onClick.AddListener(this.RestartTheGame);
            this.loosePanel.RestartButton.onClick.AddListener(this.RestartTheGame);

            this.SwipesRemainsCount
            .Where(value => value == 0)
            .Where(_ => !this.isGameOver)
            .Subscribe(_ => {
                if (this.ObservableColourCount.Value < this.gameOptions.DesiredAmount)
                {
                    this.StartCoroutine(this.LooseTheGame());
                }
                else
                {
                    this.StartCoroutine(this.WinTheGame());
                }
            });

            this.controlPanel.GameControl.onClick.AddListener(() => {
                this.isOnPause = !this.isOnPause;

                if (this.isOnPause)
                {
                    Time.timeScale = 0;
                    this.controlPanel.GameControlText.text = "Play";
                }
                else
                {
                    Time.timeScale = 1;
                    this.controlPanel.GameControlText.text = "Pause";
                }

                this.matrixController.IsOnPause = this.isOnPause;
            });

            // Candies Counting
            this.levelDataManager.BlueCandiesCount
            .Where(value => value > 0)
            .Subscribe(value => this.scoresPanel.BlueScores.text = value.ToString());

            this.levelDataManager.GreenCandiesCount
            .Where(value => value > 0)
            .Subscribe(value => this.scoresPanel.GreenScores.text = value.ToString());

            this.levelDataManager.OrangeCandiesCount
            .Where(value => value > 0)
            .Subscribe(value => this.scoresPanel.OrangeScores.text = value.ToString());

            this.levelDataManager.PurpleCandiesCount
            .Where(value => value > 0)
            .Subscribe(value => this.scoresPanel.PurpleScores.text = value.ToString());

            this.levelDataManager.RedCandiesCount
            .Where(value => value > 0)
            .Subscribe(value => this.scoresPanel.RedScores.text = value.ToString());

            this.levelDataManager.Gold
            .Where(value => value > 0)
            .Subscribe(value => this.scoresPanel.GoldScores.text = value.ToString());

            this.scoresPanel.SwipesRemainsCount.text = this.gameOptions.Swipes.ToString();

            this.SwipesRemainsCount
            .Subscribe(value => this.scoresPanel.SwipesRemainsCount.text = value.ToString());

            this.SplitCandiesConfigsFromOptionsToMatrixControllerByCandyType();
            this.EstablishObservationForDesirableCandyCollected();


            this.resolutionManager.ArrangeUiSizesAccordingToTheScreenWidth();

            this.poolManager.Initialize(this.candiesOptions.Pools);
            this.matrixController.Initialize(this.resolutionManager.SizeForCell);

            this.InitUI();
        }