コード例 #1
0
ファイル: Level.cs プロジェクト: Sikny/Projet3DJV3A
        private void FixedUpdate()
        {
            if (!_levelStarted)
            {
                return;
            }

            // getting active units, TODO refactor to events on add/remove unit
            _playerUnits.Clear();
            foreach (var unit in _systemUnit.units)
            {
                if (unit.GetType() == typeof(PlayerUnit))
                {
                    _playerUnits.Add((PlayerUnit)unit);
                }
            }

            if (enemySpawns.Count == 0 && livingEnemies.Count == 0 && !_gameEnded)
            {
                Time.timeScale = 1;
                _gameEnded     = true;
                GameSingleton.Instance.EndGame(1); // WIN
            }
            else if (_playerUnits.Count == 0 && !_gameEnded)
            {
                Time.timeScale = 1;
                _gameEnded     = true;
                GameSingleton.Instance.EndGame(0);
            }

            for (int i = 0; i < livingEnemies.Count; i++)
            {
                if (livingEnemies[i] == null)
                {
                    livingEnemies.RemoveAt(i);
                    break;
                }
            }

            for (int i = 0; i < _playerUnits.Count; i++)
            {
                if (_playerUnits[i] == null || !_playerUnits[i].gameObject.activeSelf)
                {
                    _playerUnits.RemoveAt(i);
                    break;
                }
            }

            if (_skipCutscene)
            {
                return;
            }

            if (!_checkForCinematic)
            {
                if (!_mageCheck)
                {
                    _mageCheck = true;
                    bool onlyMages = true;
                    foreach (var unit in _playerUnits)
                    {
                        EntityType type = unit.GetEntityType();
                        if (type != EntityType.Mage && type != EntityType.Bard && type != EntityType.BlackMage &&
                            type != EntityType.Demonist && type != EntityType.WhiteMage && type != EntityType.RedMage)
                        {
                            onlyMages = false;
                            break;
                        }
                    }

                    if (onlyMages)
                    {
                        _skipCutscene = true;
                        return;
                    }
                }

                if (enemySpawns.Count == 0 && livingEnemies.Count == 1 && !_gameEnded)
                {
                    //Debug.Log("start checking for cinematic");
                    _lastUnit          = livingEnemies[0].GetComponent <AiUnit>();
                    _lastEntity        = _lastUnit.entities[0];
                    _checkForCinematic = true;
                    if (_playerUnits.Count < 3)
                    {
                        _isWeak = true;
                    }
                }
            }

            if (_cinematicPlayed)
            {
                return;
            }
            if (!_checkForCinematic)
            {
                return;
            }
            if (_lastUnit.GetNumberAlive() == 1)
            {
                if (_isWeak)
                {
                    if (_lastEntity.GetLife() < _lastEntity.GetMaxLife() / 2)
                    {
                        _cinematicPlayed = true;
                        GameSingleton.Instance.cameraController.PlayCinematic(_lastEntity);
                    }
                }
                else
                {
                    if (_lastEntity.GetLife() < _lastEntity.GetMaxLife())
                    {
                        _cinematicPlayed = true;
                        GameSingleton.Instance.cameraController.PlayCinematic(_lastEntity);
                    }
                }
            }
        }