Beispiel #1
0
 protected override void OnStart()
 {
     dataUnit       = GetData <DataUnit>();
     dataProjectile = GetData <DataProjectile>();
 }
Beispiel #2
0
        public static DataPlayer Convert(Dictionary <string, object> data, DataUnits dataUnits, DataPlayer reference)
        {
            DataPlayer dataPlayer = DataPlayer.Copy(reference);

            dataPlayer.Gold.SetValueAndForceNotify((int)data[Gold]);


            var unitStats = data[PlayerUnits] as Stats[];

            var playerUnits = new List <DataUnit>();
            int i           = 0;

            foreach (var item in dataUnits.units)
            {
                var unit = DataUnit.Copy(item);
                if (i < unitStats.Length)
                {
                    unit.stats = unitStats[i];
                }
                playerUnits.Add(unit);
                i++;
            }
            dataPlayer.playerUnits = playerUnits;



            var playerSquadNumbers = data[PlayerSquad] as int[];
            var playerSquad        = new List <DataUnit>();

            foreach (var item in playerSquadNumbers)
            {
                playerSquad.Add(playerUnits[item]);
            }
            dataPlayer.squad = playerSquad;


            var towerStats   = data[PlayerTowers] as Stats[];
            var playerTowers = new List <DataUnit>();

            i = 0;
            foreach (var item in dataUnits.towers)
            {
                var tower = DataUnit.Copy(item);

                if (i < towerStats.Length)
                {
                    tower.stats = towerStats[i];
                }
                playerTowers.Add(tower);
                i++;
            }
            dataPlayer.playerTowers = playerTowers;

            var activeTowerNumber = (int)data[PlayerActiveTower];

            if (activeTowerNumber >= 0 && playerTowers.Count > activeTowerNumber)
            {
                dataPlayer.dataTower = playerTowers[activeTowerNumber];
            }
            else
            {
                dataPlayer.dataTower = playerTowers[0];
            }

            return(dataPlayer);
        }