RTSEngine.Data.Team.RTSSquad.Deserialize C# (CSharp) Method

Deserialize() public static method

public static Deserialize ( BinaryReader s, RTSTeam team, List &units ) : RTSSquad
s System.IO.BinaryReader
team RTSTeam
units List
return RTSSquad
        public static RTSSquad Deserialize(BinaryReader s, RTSTeam team, out List<int> units)
        {
            RTSSquad squad = team.AddSquad();
            int c = s.ReadInt32();
            units = new List<int>();
            for(int i = 0; i < c; i++) {
                units.Add(s.ReadInt32());
            }
            squad.gridPos = s.ReadVector2();
            if(s.ReadBoolean()) {
                if(squad.ActionController != null) squad.ActionController.Deserialize(s);
            }
            else {
                squad.ActionController = null;
            }
            if(s.ReadBoolean()) {
                if(squad.MovementController != null) squad.MovementController.Deserialize(s);
            }
            else {
                squad.MovementController = null;
            }
            if(s.ReadBoolean()) {
                if(squad.TargetingController != null) squad.TargetingController.Deserialize(s);
            }
            else {
                squad.TargetingController = null;
            }
            return squad;
        }

Usage Example

コード例 #1
0
        public static RTSTeam Deserialize(BinaryReader s, int index, GameState state)
        {
            int     t    = s.ReadInt32();
            RTSTeam team = new RTSTeam(index, t);

            team.Race = RTSRace.Deserialize(s, state);
            if (s.ReadBoolean())
            {
                string it = s.ReadString();
                team.Input = state.Scripts[it].CreateInstance <ACInputController>();
                team.Input.Deserialize(s);
                team.Input.Init(state, index, null);
            }

            RTSColorScheme scheme = new RTSColorScheme();

            scheme.Name      = s.ReadString();
            scheme.Primary   = s.ReadVector3();
            scheme.Secondary = s.ReadVector3();
            scheme.Tertiary  = s.ReadVector3();
            team.ColorScheme = scheme;

            int?       target;
            var        du = new Dictionary <int, RTSUnit>();
            List <int> su;

            int         c = s.ReadInt32();
            RTSBuilding building;

            for (int i = 0; i < c; i++)
            {
                building = RTSBuilding.Deserialize(s, team, out target);
                team.buildings.Add(building);
                if (target.HasValue)
                {
                    // TODO: Add A Target Binding
                }
                state.CGrid.Add(building);
            }

            c = s.ReadInt32();
            RTSUnit unit;

            for (int i = 0; i < c; i++)
            {
                unit = RTSUnit.Deserialize(s, team, out target);
                du.Add(unit.UUID, unit);
                team.units.Add(unit);
                if (target.HasValue)
                {
                    // TODO: Add A Target Binding
                }
            }

            c = s.ReadInt32();
            RTSSquad squad;

            for (int i = 0; i < c; i++)
            {
                squad = RTSSquad.Deserialize(s, team, out su);
                team.squads.Add(squad);
                foreach (int uuid in su)
                {
                    if (du.TryGetValue(uuid, out unit))
                    {
                        squad.Add(unit);
                    }
                    else
                    {
                        throw new Exception("Could Not Find A Unit With The Specified UUID");
                    }
                }
            }
            return(team);
        }