public void LoadEventFile(string filename)
    {
        FileStream    fs         = new FileStream(Application.dataPath + "/" + filename + XML_EXTENSION, FileMode.Open);
        XmlSerializer serializer = new XmlSerializer(typeof(GameEventContainer));

        GameEventContainer container = serializer.Deserialize(fs) as GameEventContainer;

        container.UpdateChoiceReferences();
        fs.Close();
    }
    public void SaveEventFile(string filename)
    {
        FileStream fs = new FileStream(Application.dataPath + "/" + filename + XML_EXTENSION, FileMode.Create);


        XmlSerializer serializer = new XmlSerializer(typeof(GameEventContainer));

        XmlWriterSettings xws = new XmlWriterSettings();

        xws.OmitXmlDeclaration = true;
        xws.Encoding           = Encoding.UTF8;
        XmlTextWriter xtw = (XmlTextWriter)XmlTextWriter.Create(fs, xws);

        xtw.Formatting = Formatting.Indented;

        GameEventContainer container = new GameEventContainer();
        GameEvent          xmlEvent  = new GameEvent();

        xmlEvent.Name    = "TEST";
        xmlEvent.Text    = "This is a Test!";
        xmlEvent.Augment = new AugmentReward("TEST_REWARD");
        container.GameEvents.Add(xmlEvent);

        xmlEvent                       = new GameEvent();
        xmlEvent.Name                  = "TEST2";
        xmlEvent.Text                  = "This is also a Test!";
        xmlEvent.Choice                = new GameEventChoice[1];
        xmlEvent.Choice[0]             = new GameEventChoice("Ok...");
        xmlEvent.Choice[0].InlineEvent = new GameEvent("Its crazy up in here!");
        container.GameEvents.Add(xmlEvent);

        xmlEvent           = new GameEvent();
        xmlEvent.Name      = "TEST3";
        xmlEvent.Text      = "This is a further Test!";
        xmlEvent.Choice    = new GameEventChoice[2];
        xmlEvent.Choice[0] = new GameEventChoice();
        xmlEvent.Choice[0].ReferenceEvent = new GameEventReference(container.GameEvents[0].Name);
        List <string> textList = new List <string>();

        textList.Add("Blah");
        textList.Add("Blather");
        textList.Add("Blatherest");
        xmlEvent.Choice[0].TextList       = textList;
        xmlEvent.Choice[1]                = new GameEventChoice("Not what I thought it would be...");
        xmlEvent.Choice[1].ReferenceEvent = new GameEventReference(container.GameEvents[1].Name);
        container.GameEvents.Add(xmlEvent);

        serializer.Serialize(xtw, container, container.Namespaces);
        fs.Close();
    }
Example #3
0
        public override void HandleResponse(byte[] response)
        {
            var stream = new MemoryStream(response);

            EventContainer = GameEventContainer.Deserialize(stream);
        }