Exemple #1
0
    void GenerateUnits()
    {
        _classStatGrowthConfig     = JObject.Parse(File.ReadAllText(_classStatGrowthConfigPath));
        _characterStatGrowthConfig = JObject.Parse(File.ReadAllText(_characterStatGrowthConfigPath));
        _abilityConfig             = JObject.Parse(File.ReadAllText(_abilityConfigPath));

        UnitInfo[]    playerInfo  = initialUnitInfo.playerList;
        UnitInfo[]    enemyInfo   = initialUnitInfo.enemyList;
        CrystalInfo[] crystalInfo = initialUnitInfo.crystalList;

        // PLAYERS
        // updating player units according to selected units
        List <string> selectedUnitIds = StaticData.SelectedUnits;

        for (int i = 0; i < selectedUnitIds.Count; i++)
        {
            UnitDataEntry unitDataEntry = _unitDatabase.UnitDataEntries.Find(x => x.unitName == selectedUnitIds[i]);
            playerInfo[i].UpdateUnitIdAndPrefab(unitDataEntry);
        }
        int numPlayers = selectedUnitIds.Count != 0 ? selectedUnitIds.Count : playerInfo.Length;

        StaticData.SelectedUnits.Clear();

        // instantiate player units
        for (int i = 0; i < numPlayers; i++)
        {
            PlayerUnit player = Instantiate(playerInfo[i].UnitPrefab, playerInfo[i].UnitPositions,
                                            Quaternion.identity).GetComponent <PlayerUnit>();
            player.tag = "player";
            string       unitId       = playerInfo[i].unitID;
            UnitLoadData unitLoadData = unitSaveManager.LoadUnit(unitId);
            Dictionary <StatString, int> classStatGrowth     = _classStatGrowthConfig[unitLoadData.unitClass].ToObject <Dictionary <StatString, int> >();
            Dictionary <StatString, int> characterStatGrowth = _characterStatGrowthConfig[unitId].ToObject <Dictionary <StatString, int> >();
            player.CreateUnit(unitLoadData, _abilityConfig, classStatGrowth, characterStatGrowth);
            player.AssignMap(map);
            player.UpdateUI();
            players.Add(player);
        }

        // ENEMIES

        for (int i = 0; i < initialUnitInfo.enemyList.Length; i++)
        {
            EnemyUnit enemy = Instantiate(enemyInfo[i].UnitPrefab, enemyInfo[i].UnitPositions, Quaternion.identity).GetComponent <EnemyUnit>();
            //enemy.gridPosition = new Vector2(0,0);
            enemy.tag = "enemy";
            string       unitId       = enemyInfo[i].unitID;
            UnitLoadData unitLoadData = unitSaveManager.LoadUnit(unitId, initialUnitInfo.enemyStatsFilename, true);
            Dictionary <StatString, int> classStatGrowth     = _classStatGrowthConfig[unitLoadData.unitClass].ToObject <Dictionary <StatString, int> >();
            Dictionary <StatString, int> characterStatGrowth = _characterStatGrowthConfig[unitId].ToObject <Dictionary <StatString, int> >();
            enemy.CreateUnit(unitLoadData, _abilityConfig, classStatGrowth, characterStatGrowth);
            enemy.AssignMap(map);
            enemy.AssignWaitAndRecovery(enemiesWaitingMode, enemiesRecoveryMode);
            enemy.UpdateUI();
            enemies.Add(enemy);
        }

        for (int i = 0; i < initialUnitInfo.crystalList.Length; i++)
        {
            GameObject crystal = Instantiate(crystalInfo[i].UnitPrefab, crystalInfo[i].UnitPositions, Quaternion.identity);
            //enemy.gridPosition = new Vector2(0,0);
            crystal.tag = "crystal";
        }
    }