private void LoadFromXml(string filename) { //Generation settings _generationSettings = new GenerationSettings(); var root = XElement.Load(filename); //locate generation node var generation = root.Element("Generation"); var district = root.Element("Districts"); var terrain = root.Element("Terrain"); if (generation == null) { return; } _generationSettings.UseSeed = bool.Parse(generation.Element("UseSeed").Value); _generationSettings.Seed = int.Parse(generation.Element("Seed").Value); _generationSettings.Width = double.Parse(generation.Element("Width").Value); _generationSettings.Length = double.Parse(generation.Element("Length").Value); _generationSettings.StartX = double.Parse(generation.Element("StartX").Value); _generationSettings.StartY = double.Parse(generation.Element("StartY").Value); _generationSettings.Amount = int.Parse(generation.Element("Amount").Value); _generationSettings.PointAlgorithm = (PointGenerationAlgorithm) Enum.Parse(typeof(PointGenerationAlgorithm), generation.Element("Point").Value); _generationSettings.VoronoiAlgorithm = (VoronoiAlgorithm)Enum.Parse(typeof(VoronoiAlgorithm), generation.Element("Voronoi").Value); var parentname = generation.Element("Parent").Value; _townGenerator.Parent = null; if (parentname != string.Empty) { _townGenerator.Parent = GameObject.Find(parentname); } //Load in terrain settings var splatmaps = new List <SplatTexture>(); foreach (var e in terrain.Element("Splatmaps").Elements()) { var newSplat = new SplatTexture { Texture = AssetDatabase.LoadAssetAtPath <Texture2D>(e.Value), TileSize = float.Parse(e.Attribute("Tiling").Value) }; splatmaps.Add(newSplat); } var trees = new List <GameObject>(); foreach (var e in terrain.Elements("Trees").Elements()) { var prefab = AssetDatabase.LoadAssetAtPath <GameObject>(e.Value); trees.Add(prefab); } var props = new List <GameObject>(); foreach (var e in terrain.Elements("Props").Elements()) { var prefab = AssetDatabase.LoadAssetAtPath <GameObject>(e.Value); props.Add(prefab); } var details = new List <DetailObject>(); foreach (var e in terrain.Elements("Details").Elements()) { var d = new DetailObject(); var type = (DetailType)int.Parse(e.Attribute("Type").Value); switch (type) { case DetailType.Texture: d.Detail = AssetDatabase.LoadAssetAtPath <Texture2D>(e.Value); d.Type = DetailType.Texture; break; case DetailType.GameObject: d.Detail = AssetDatabase.LoadAssetAtPath <GameObject>(e.Value); d.Type = DetailType.GameObject; break; } details.Add(d); } //lakes _terrainEditor.Settings.GenerateLake = bool.Parse(terrain.Element("Lakes").Attribute("generate").Value); _terrainEditor.Settings.WaterPrefab = AssetDatabase.LoadAssetAtPath <GameObject>(terrain.Element("Lakes").Element("lake").Value); _terrainEditor.GetSettings().SplatMaps = splatmaps; _terrainEditor.GetSettings().Trees = trees; _terrainEditor.GetSettings().Props = props; _terrainEditor.GetSettings().Details = details; //Clear previous loaded districts _prefabSelectors.Clear(); foreach (var districtElem in district.Elements()) { //Create district var distictEditor = CreatePrefabSelection(districtElem.Name.ToString()); if (distictEditor != null) { distictEditor.GetSettings().Frequency = int.Parse(districtElem.Element("Frequency").Value); distictEditor.GetSettings().Size = double.Parse(districtElem.Element("Size").Value); distictEditor.GetSettings().Offset = int.Parse(districtElem.Element("Offset").Value); distictEditor.GetSettings().Percentage = double.Parse(districtElem.Element("Interval").Value); //Load in all buildings distictEditor.ResetPrefabs(); foreach (var bElem in districtElem.Element("Buildings").Elements()) { distictEditor.AddPrefab(bElem.Value); } } } }
/// <summary> /// Editor for the splatmaps of the terrain /// </summary> private void TerrainTextureGUI() { var windowWidth = _parentWindow.maxSize.x; var spacing = windowWidth * 0.05f; var buttonWidth = windowWidth / 2 - spacing; Settings.RoadWidth = EditorGUILayout.IntSlider("Road width", Settings.RoadWidth, 2, 15); //Selected Texture GUI EditorGUILayout.BeginHorizontal(GUILayout.Width(windowWidth), GUILayout.Height(20)); GUILayout.Space(spacing / 2); _selectedTexture.Texture = (Texture2D)EditorGUILayout.ObjectField(_selectedTexture.Texture, typeof(Texture2D), false, GUILayout.Width(buttonWidth * 1.5f)); EditorGUILayout.LabelField(_selectedTexture.ID); GUILayout.Space(spacing / 2); EditorGUILayout.EndHorizontal(); //texture previews of added textures int size = 64; GUILayout.BeginHorizontal(); GUILayout.Space(spacing); //the splatmaps are limited to 4 + 1 road for (int i = 0; i < Settings.SplatMaps.Count; ++i) { var splatTexture = Settings.SplatMaps[i]; GUILayout.BeginVertical(); splatTexture.ID = (i == 0) ? splatTexture.ID = "Road" : "Terrain " + i; GUILayout.Label(splatTexture.ID); if (GUILayout.Button(splatTexture.Texture, GUIStyle.none, GUILayout.Width(size + (size * 0.2f)), GUILayout.Height(size))) { _selectedTexture = splatTexture; } GUILayout.EndVertical(); } GUILayout.Space(spacing); GUILayout.EndHorizontal(); //Adding / Removing EditorGUILayout.BeginHorizontal(GUILayout.Width(windowWidth), GUILayout.Height(20)); GUILayout.Space(spacing); if (GUILayout.Button("Add terrain Texture", GUILayout.Width(buttonWidth))) { if (Settings.SplatMaps.Count < 4) { var splat = new SplatTexture(); splat.Texture = _selectedTexture.Texture; splat.TileSize = _selectedTexture.TileSize; Settings.SplatMaps.Add(splat); } } //remove the selected splatTexture if (GUILayout.Button("Remove terrain Texture", GUILayout.Width(buttonWidth))) { Settings.SplatMaps.Remove(_selectedTexture); } GUILayout.Space(spacing); EditorGUILayout.EndHorizontal(); }
/// <summary> /// Editor for the splatmaps of the terrain /// </summary> private void TerrainTextureGUI() { var windowWidth = _parentWindow.maxSize.x; var spacing = windowWidth*0.05f; var buttonWidth = windowWidth/2 - spacing; Settings.RoadWidth = EditorGUILayout.IntSlider("Road width", Settings.RoadWidth, 2,15); //Selected Texture GUI EditorGUILayout.BeginHorizontal(GUILayout.Width(windowWidth), GUILayout.Height(20)); GUILayout.Space(spacing/2); _selectedTexture.Texture = (Texture2D)EditorGUILayout.ObjectField(_selectedTexture.Texture, typeof (Texture2D),false,GUILayout.Width(buttonWidth * 1.5f)); EditorGUILayout.LabelField(_selectedTexture.ID); GUILayout.Space(spacing/2); EditorGUILayout.EndHorizontal(); //texture previews of added textures int size = 64; GUILayout.BeginHorizontal(); GUILayout.Space(spacing); //the splatmaps are limited to 4 + 1 road for(int i = 0; i < Settings.SplatMaps.Count; ++i) { var splatTexture = Settings.SplatMaps[i]; GUILayout.BeginVertical(); splatTexture.ID = (i == 0) ? splatTexture.ID = "Road" : "Terrain " + i; GUILayout.Label(splatTexture.ID); if (GUILayout.Button(splatTexture.Texture,GUIStyle.none, GUILayout.Width(size + (size * 0.2f)), GUILayout.Height(size))) { _selectedTexture = splatTexture; } GUILayout.EndVertical(); } GUILayout.Space(spacing); GUILayout.EndHorizontal(); //Adding / Removing EditorGUILayout.BeginHorizontal(GUILayout.Width(windowWidth), GUILayout.Height(20)); GUILayout.Space(spacing); if (GUILayout.Button("Add terrain Texture", GUILayout.Width(buttonWidth))) { if (Settings.SplatMaps.Count < 4) { var splat = new SplatTexture(); splat.Texture = _selectedTexture.Texture; splat.TileSize = _selectedTexture.TileSize; Settings.SplatMaps.Add(splat); } } //remove the selected splatTexture if (GUILayout.Button("Remove terrain Texture", GUILayout.Width(buttonWidth))) { Settings.SplatMaps.Remove(_selectedTexture); } GUILayout.Space(spacing); EditorGUILayout.EndHorizontal(); }
private void LoadFromXml(string filename) { //Generation settings _generationSettings = new GenerationSettings(); var root = XElement.Load(filename); //locate generation node var generation = root.Element("Generation"); var district = root.Element("Districts"); var terrain = root.Element("Terrain"); if (generation == null) return; _generationSettings.UseSeed = bool.Parse(generation.Element("UseSeed").Value); _generationSettings.Seed = int.Parse(generation.Element("Seed").Value); _generationSettings.Width = double.Parse(generation.Element("Width").Value); _generationSettings.Length = double.Parse(generation.Element("Length").Value); _generationSettings.StartX = double.Parse(generation.Element("StartX").Value); _generationSettings.StartY = double.Parse(generation.Element("StartY").Value); _generationSettings.Amount = int.Parse(generation.Element("Amount").Value); _generationSettings.PointAlgorithm = (PointGenerationAlgorithm) Enum.Parse(typeof(PointGenerationAlgorithm), generation.Element("Point").Value); _generationSettings.VoronoiAlgorithm = (VoronoiAlgorithm)Enum.Parse(typeof(VoronoiAlgorithm), generation.Element("Voronoi").Value); var parentname = generation.Element("Parent").Value; _townGenerator.Parent = null; if (parentname != string.Empty) { _townGenerator.Parent = GameObject.Find(parentname); } //Load in terrain settings var splatmaps = new List<SplatTexture>(); foreach (var e in terrain.Element("Splatmaps").Elements()) { var newSplat = new SplatTexture { Texture = AssetDatabase.LoadAssetAtPath<Texture2D>(e.Value), TileSize = float.Parse(e.Attribute("Tiling").Value) }; splatmaps.Add(newSplat); } var trees = new List<GameObject>(); foreach (var e in terrain.Elements("Trees").Elements()) { var prefab = AssetDatabase.LoadAssetAtPath<GameObject>(e.Value); trees.Add(prefab); } var props = new List<GameObject>(); foreach (var e in terrain.Elements("Props").Elements()) { var prefab = AssetDatabase.LoadAssetAtPath<GameObject>(e.Value); props.Add(prefab); } var details = new List<DetailObject>(); foreach (var e in terrain.Elements("Details").Elements()) { var d = new DetailObject(); var type = (DetailType)int.Parse(e.Attribute("Type").Value); switch (type) { case DetailType.Texture: d.Detail = AssetDatabase.LoadAssetAtPath<Texture2D>(e.Value); d.Type = DetailType.Texture; break; case DetailType.GameObject: d.Detail = AssetDatabase.LoadAssetAtPath<GameObject>(e.Value); d.Type = DetailType.GameObject; break; } details.Add(d); } //lakes _terrainEditor.Settings.GenerateLake = bool.Parse(terrain.Element("Lakes").Attribute("generate").Value); _terrainEditor.Settings.WaterPrefab = AssetDatabase.LoadAssetAtPath<GameObject>(terrain.Element("Lakes").Element("lake").Value); _terrainEditor.GetSettings().SplatMaps = splatmaps; _terrainEditor.GetSettings().Trees = trees; _terrainEditor.GetSettings().Props = props; _terrainEditor.GetSettings().Details = details; //Clear previous loaded districts _prefabSelectors.Clear(); foreach (var districtElem in district.Elements()) { //Create district var distictEditor = CreatePrefabSelection(districtElem.Name.ToString()); if (distictEditor != null) { distictEditor.GetSettings().Frequency = int.Parse(districtElem.Element("Frequency").Value); distictEditor.GetSettings().Size = double.Parse(districtElem.Element("Size").Value); distictEditor.GetSettings().Offset = int.Parse(districtElem.Element("Offset").Value); distictEditor.GetSettings().Percentage = double.Parse(districtElem.Element("Interval").Value); //Load in all buildings distictEditor.ResetPrefabs(); foreach (var bElem in districtElem.Element("Buildings").Elements()) { distictEditor.AddPrefab(bElem.Value); } } } }