Exemple #1
0
    private void LoadScenarioFile(string url)
    {
        ZipFile zip = ZipFile.Read(url);

        foreach (var entry in zip.Entries)
        {
            if (entry.FileName == "structure")
            {
                entry.Extract();
                break;
            }
        }
        zip.Dispose();

        string structure = File.ReadAllText("structure");

        File.Delete("structure");

        if (structure == "")
        {
            Debug.LogError("Chargement d'un fichier structure vide ?");
            return;
        }

        ScenarioSave  scenarioSave = new ScenarioSave();
        XmlSerializer serializer   = new XmlSerializer(scenarioSave.GetType());

        using (TextReader reader = new StringReader(structure))
        {
            scenarioSave = (ScenarioSave)serializer.Deserialize(reader);

            reader.Dispose();
        }

        ResetScenario();

        LoadScenarioResources(scenarioSave);
        LoadScenarioStructure(scenarioSave);
    }
Exemple #2
0
    public void SaveScenario()
    {
        ScenarioSave scenario = new ScenarioSave();

        scenario.resources = new ResourceData[AppManager.Instance.ResourcesManager.Count()];
        for (int i = 0; i < scenario.resources.Length; ++i)
        {
            ResourceData resourceData = new ResourceData();
            resourceData.id       = AppManager.Instance.ResourcesManager.Resources[i].Id;
            scenario.resources[i] = resourceData;
        }

        scenario.soundblocks = new SoundBlockData[blocks.Count];
        int linkCount = 0;

        for (int i = 0; i < blocks.Count; i++)
        {
            SoundBlockData blockData = new SoundBlockData();
            SoundBlock     block     = blocks[i];
            blockData.blockId = block.soundblockId;
            if (block.source.clip != null)
            {
                blockData.clipId = AppManager.Instance.ResourcesManager.GetResource(block.source.clip.name).Id;
            }
            else
            {
                blockData.clipId = -1;
            }

            if (firstBlock == block)
            {
                blockData.isFirstBlock = true;
            }

            blockData.isLooping = block.source.loop;
            blockData.position  = block.transform.localPosition;

            if (block.link != null)
            {
                linkCount++;
            }

            scenario.soundblocks[i] = blockData;
        }

        scenario.links = new LinkData[linkCount];
        int nextLinkIndex = 0;

        for (int i = 0; i < blocks.Count; i++)
        {
            if (blocks[i].link != null)
            {
                LinkData link = new LinkData();
                link.fromSoundblock = blocks[i].soundblockId;
                link.toSoundblock   = blocks[i].nextBlock.soundblockId;
                link.linkType       = blocks[i].link.linkType;
                link.isActive       = blocks[i].link.IsActive;

                scenario.links[nextLinkIndex] = link;
                nextLinkIndex++;
            }
        }

        scenario.soundBlockNextId = nextID;
        scenario.resourceNextId   = AppManager.Instance.ResourcesManager.nextResourceID;

        XmlSerializer writer = new XmlSerializer(scenario.GetType());

        using (FileStream stream = File.Create("structure"))
        {
            writer.Serialize(stream, scenario);
            stream.Close();
        }

        ZipFile zip = ZipFile.Read(scenarioUrl);

        zip.RemoveEntry("structure");
        zip.AddFile("structure");
        zip.Save(scenarioUrl);

        File.Delete("structure");

        Debug.Log("Saved Project " + scenarioUrl);
    }