예제 #1
0
        public void OnValidate()
        {
            if (_camera == null)
            {
                _camera = FindObjectOfType <CameraWrapper>();
            }

            _levels        = GetComponentsInChildren <World.Level>(true);
            _selectedLevel = _levels.Length == 0 ? null : _levels[0];

            if (_transitionEffect == null)
            {
                _transitionEffect = FindObjectOfType <Transitions.Transition>();
            }

            if (_characterSelect == null)
            {
                _characterSelect = FindObjectOfType <UI.CharacterSelect>();
            }

            if (_startMenu == null)
            {
                _startMenu = FindObjectOfType <UI.StartMenu>();
            }
        }
예제 #2
0
        private void OnPodiumFinished()
        {
            if (_state == State.FinalPodium)
            {
                TryChangeState(State.Transition, State.LevelSelection);
            }
            else
            {
                if (_currentLevel != null)
                {
                    Destroy(_currentLevel.gameObject);
                    _currentLevel = null;
                }

                TryChangeState(State.Transition, State.Round);
            }
        }
예제 #3
0
        public void OnLevelSelected(int step)
        {
            for (int i = 0; i < _levels.Length; i++)
            {
                if (_levels[i] == null)
                {
                    continue;
                }

                _levels[i].TargetPosition = Vector3.zero + Vector3.right * (i - _currentLevelIndex) * _distanceLevelSelect;
            }

            _selectedLevel = _levels[_currentLevelIndex];

            _targetSizeCamera = _selectedLevel.CameraSize;

            OnLevelSelectedHandler?.Invoke(_selectedLevel, step);
        }
예제 #4
0
        protected bool TryFinishChangeState(State target, params object[] args)
        {
            switch (target)
            {
            case State.Menu:
                _state = target;
                return(true);

            case State.CharacterSelection:
                OnCharacterSelectHandler?.Invoke(true);
                _state = target;
                return(true);

            case State.Begin:
                _podium.Clear();

                foreach (var c in _controllers)
                {
                    if (c == null)
                    {
                        continue;
                    }

                    _podium.Add(c, c._characterResource);
                }

                _podium.gameObject.SetActive(false);

                OnLevelSelectHandler.Invoke(false);

                foreach (World.Level level in _levels)
                {
                    if (level == null)
                    {
                        continue;
                    }

                    if (level == _selectedLevel)
                    {
                        continue;
                    }

                    level.gameObject.SetActive(false);
                }


                _selectedLevel.gameObject.SetActive(false);

                _state = target;
                return(TryChangeState(State.Round, _roundTime));


            case State.Transition:

                _transition = (State)args[0];
                _transitionTimer.Start();

                _transitionEffect.Perform();

                _state = target;
                return(true);


            case State.Podium:
                _podium.gameObject.SetActive(true);
                OnPodiumHandler?.Invoke();
                _state = target;
                return(true);

            case State.FinalPodium:
                _podium.gameObject.SetActive(true);
                OnFinalPodiumHandler?.Invoke();
                _state = target;
                return(true);

            case State.LevelSelection:

                _state = target;

                foreach (World.Level lv in _levels)
                {
                    lv.gameObject.SetActive(true);
                    lv.OnLevelSelect();
                }

                OnLevelSelect();
                OnLevelSelected(0);

                return(true);

            case State.Round:

                // TODO enable

                _selectedLevel.TargetPosition     = Vector3.zero;
                _selectedLevel.transform.position = Vector3.zero;

                _selectedLevel.gameObject.SetActive(true);

                _currentLevel =
                    Instantiate(
                        _selectedLevel.gameObject,
                        Vector3.zero, Quaternion.identity,
                        gameObject.transform).GetComponent <World.Level>();

                _selectedLevel.gameObject.SetActive(false);


                _currentLevel.OnScoreValueAddedHandler += OnScoreValueAdded;

                _currentLevel.OnLevelCompletedHandler += OnLevelCompleted;

                List <Placeholder> placeholders = new List <Placeholder>();
                placeholders.AddRange(_currentLevel._characterPlaceholders);

                int i = 0;
                while (!placeholders.IsEmpty())
                {
                    Placeholder placeholder = placeholders.RemoveRandom();

                    _controllers[i]._character = _controllers[i]
                                                 ._characterResource.Create(
                        _currentLevel.GridToWorld(placeholder._gridPosition),
                        _currentLevel.transform);

                    _controllers[i]._character.Number = _controllers[i].Number;

                    _controllers[i]._character.Color = _controllers[i].Color;

                    _controllers[i]._character._level = _currentLevel;

                    _controllers[i]._character.TryChangeState(Character.State.Disabled);

                    _controllers[i].Score = 0;

                    _controllers[i]._assignedNumber = placeholder.Number;

                    i++;

                    Destroy(placeholder.gameObject);
                }

                _round =
                    new Round(
                        _countDown,
                        _roundTime,
                        _countDownTime,
                        _intermissionTime,
                        _roundIndex);

                StartCoroutine(NewRoundCoroutine());

                _state = target;

                return(true);

            case State.Score:

                _state = target;

                return(true);

            case State.WaitingNextRound:
                //Lobby.Characters.Clear();
                //Lobby.Characters.AddRange(_selectedLevel.Characters);

                foreach (Controller ctrl in Lobby.Controllers)
                {
                    if (ctrl == null)
                    {
                        continue;
                    }

                    //ctrl.Character = null;
                }

                _state = target;

                OnWaiting();
                return(true);


            default:
                return(false);
            }
        }