Esempio n. 1
0
    public static Ship DeserializeShip(XmlReader reader)
    {
        GameObject workingGO   = null;
        Ship       workingShip = null;
        int        mainPortNum = 0;
        int        portNum     = 0;

        while (reader.Read() && !(!reader.IsStartElement() && reader.LocalName.Equals(typeof(Ship).Name)))
        {
            Debug.Log(reader.LocalName);
            if (reader.IsStartElement())
            {
                Module module = null;
                // Debug.Log(reader.LocalName);
                switch (reader.LocalName)
                {
                case "BASE":
                    workingGO   = MyPrefab.ReadXml(reader, null);
                    workingShip = workingGO.GetComponent <Ship>();
                    workingShip.Start();
                    break;

                case "DAMAGEABLE":
                    Damageable.ReadXml(reader, workingShip);
                    break;

                case "SHIP_DATA":
                    Ship.ReadXml(reader, workingShip);
                    break;

                case "MAIN_PORT":
                    module = DeserializeModule(reader);
                    if (module)
                    {
                        workingShip.mainPorts[mainPortNum].Connect(module);
                    }
                    mainPortNum++;
                    break;

                case "PORT":
                    module = DeserializeModule(reader);
                    if (module)
                    {
                        workingShip.ports[portNum].Connect(module);
                    }
                    portNum++;
                    break;
                }
            }
        }
        return(workingShip);
    }
Esempio n. 2
0
    public static Module DeserializeModule(XmlReader reader)
    {
        GameObject workingGO = null;
        Component  workingCO = null;

        while (reader.Read() && !(!reader.IsStartElement() && reader.LocalName.Equals(typeof(Module).Name)))
        {
            if (reader.IsStartElement())
            {
                switch (reader.LocalName)
                {
                case "BASE":
                    workingGO = MyPrefab.ReadXml(reader, null);
                    workingCO = workingGO.GetComponent <Module>();
                    break;

                case "DAMAGEABLE":
                    Damageable.ReadXml(reader, workingCO);
                    break;

                case "MODULE_DATA":
                    Module.ReadXml(reader, workingCO);
                    break;

                case "SINGLE_SHOT_WEAPON":
                    SingleShotWeapon.ReadXml(reader, workingCO);
                    break;

                case "WEAPON":
                    Weapon.ReadXml(reader, workingCO);
                    break;

                case "SHOT_WEAPON":
                    ShotWeapon.ReadXml(reader, workingCO);
                    break;
                }
            }
        }
        return((Module)workingCO);
    }