Exemple #1
0
        private static void CreatePO(string filename)
        {
            // Creates an instance of the XmlSerializer class and specifies the type of object to serialize.
            XmlSerializer  serializer = new XmlSerializer(typeof(XMLExternalMod));
            TextWriter     writer     = new StreamWriter(filename);
            XMLExternalMod mod        = new XMLExternalMod();

            // Creates a test file and additional components for verifying file integrity.
            mod.name    = "Test mod structure";
            mod.creator = "Some programmer probably";

            Texture image1 = new Texture();

            image1.name    = "Tex name 1";
            image1.pattern = "Tex1";

            Texture image2 = new Texture();

            image2.name    = "Tex name 2";
            image2.pattern = "Tex2";

            // Inserts the item into the array.
            Texture[] images = { image1, image2 };
            mod.pattern = images;

            // Serializes the pattern, and closes the TextWriter.
            serializer.Serialize(writer, mod);
            writer.Close();
        }
Exemple #2
0
        private static void MigratePO(string filename, XMLExternalMod mod)
        {
            foreach (Texture image in mod.pattern)
            {
                string picture = SearchMultipleExtensions(IOHelper.ConvertFileToDir(filename) + "\\" + image.pattern);
                if (File.Exists(picture))
                {
                    ModPattern newCandidate = ScriptableObject.CreateInstance <ModPattern>();
                    newCandidate.Name        = mod.name;
                    newCandidate.Author      = mod.creator;
                    newCandidate.Description = filename;

                    if (picture.EndsWith(".tga"))
                    {
                        newCandidate.Main_Texture = TGALoader.LoadTGA(picture);
                        mods.Add(newCandidate);
                    }
                    else
                    {
                        try {
                            byte[]    fileData = File.ReadAllBytes(picture);
                            Texture2D tex      = new Texture2D(2, 2);
                            tex.LoadImage(fileData);                     //..this will auto-resize the texture dimensions.
                            newCandidate.Main_Texture = tex;
                            mods.Add(newCandidate);
                        } catch {
                            Debug.LogError("Could not open the picture: " + picture);
                        }
                    }
                }
            }
        }
Exemple #3
0
        private static void FillBlanks(XMLExternalMod mod)
        {
            if (mod.name == null)
            {
                mod.name = "No mod title";
            }
            if (mod.creator == null)
            {
                mod.creator = "No author";
            }

            foreach (Texture image in mod.pattern.ToList())
            {
                if (image.name == null)
                {
                    image.name = "Unnamed Texture";
                }
            }
        }