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;
        }
        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;
        }
Пример #3
0
 public static DetailPrototype Deserialize(DetailPrototypeConfiguration config)
 {
     return(new DetailPrototype()
     {
         bendFactor = config.BendFactor,
         dryColor = config.DryColor,
         healthyColor = config.HealthyColor,
         maxHeight = config.MaxHeight,
         maxWidth = config.MaxWidth,
         minHeight = config.MinHeight,
         minWidth = config.MinWidth,
         noiseSpread = config.NoiseSpread,
         usePrototypeMesh = config.UsePrototypeMesh,
         prototype = config.UsePrototypeMesh ? AssetDatabase.LoadAssetAtPath(config.PrototypePath, typeof(GameObject)) as GameObject : null,
         prototypeTexture = !config.UsePrototypeMesh ? AssetDatabase.LoadAssetAtPath(config.PrototypeTexturePath, typeof(Texture2D)) as Texture2D : null,
         renderMode = config.RenderMode,
     });
 }