public void SaveSettings()
        {
            // Parse prototypes to a format that can be serialized
            ImportCfg.SplatPrototypes.Clear();
            foreach (SplatPrototype prototype in SplatPrototypes)
            {
                ImportCfg.SplatPrototypes.Add(SplatPrototypeConfiguration.Serialize(prototype));
            }

            ImportCfg.DetailPrototypes.Clear();
            foreach (DetailPrototype prototype in DetailPrototypes)
            {
                ImportCfg.DetailPrototypes.Add(DetailPrototypeConfiguration.Serialize(prototype));
            }

            ImportCfg.TreePrototypes.Clear();
            foreach (TreePrototype prototype in TreePrototypes)
            {
                ImportCfg.TreePrototypes.Add(TreePrototypeConfiguration.Serialize(prototype));
            }

            // Serialize
            string filePath = UPath.GetAbsolutePath(ImportCfgPath);

            XmlSerializer serializer = new XmlSerializer(typeof(ImporterConfiguration));
            TextWriter    writer     = new StreamWriter(filePath);

            serializer.Serialize(writer, ImportCfg);
            writer.Close();

            ImportCfg.IsDirty = false;
        }
Esempio n. 2
0
 public static SplatPrototype Deserialize(SplatPrototypeConfiguration config)
 {
     return(new SplatPrototype()
     {
         texture = AssetDatabase.LoadAssetAtPath(config.DiffusePath, typeof(Texture2D)) as Texture2D,
         tileOffset = config.TileOffset,
         tileSize = config.TileSize
     });
 }
        public void LoadSettings()
        {
            // Deserialize
            string filePath = UPath.GetAbsolutePath(ImportCfgPath);

            if (File.Exists(filePath))
            {
                try {
                    TextReader    textReader = new StreamReader(filePath);
                    XmlSerializer serializer = new XmlSerializer(typeof(ImporterConfiguration));
                    ImportCfg = serializer.Deserialize(textReader) as ImporterConfiguration;
                    textReader.Close();
                }
                catch (Exception e) {
                    Debug.LogWarning("Import configuration could not be loaded, loading defaults.\n" + e.Message);
                    ImportCfg = new ImporterConfiguration();
                }
            }
            else
            {
                Debug.LogWarning("No configuration found, loading defaults");
                ImportCfg = new ImporterConfiguration();
            }

            // Parse splatPrototypeSettings to actual splatPrototype objects
            SplatPrototypes.Clear();
            foreach (SplatPrototypeConfiguration settings in ImportCfg.SplatPrototypes)
            {
                var prototype = SplatPrototypeConfiguration.Deserialize(settings);
                SplatPrototypes.Add(prototype);
            }

            DetailPrototypes.Clear();
            foreach (DetailPrototypeConfiguration settings in ImportCfg.DetailPrototypes)
            {
                var prototype = DetailPrototypeConfiguration.Deserialize(settings);
                DetailPrototypes.Add(prototype);
            }

            TreePrototypes.Clear();
            foreach (TreePrototypeConfiguration settings in ImportCfg.TreePrototypes)
            {
                var prototype = TreePrototypeConfiguration.Deserialize(settings);
                TreePrototypes.Add(prototype);
            }

            ImportCfg.IsDirty = false;
        }