private void OnEnable() { grid = (GridCreator)target; grid.GenerateMaps(true); redoStack = new LinkedList <GridCreator.CellType[, ]>(); undoStack = new LinkedList <GridCreator.CellType[, ]>(); current = (GridCreator.CellType[, ])grid.worldMap.Clone(); undoStack.AddLast(new LinkedListNode <GridCreator.CellType[, ]>(grid.worldMap)); }
public override void OnInspectorGUI() { var undoStack = grid.undoStack; var redoStack = grid.redoStack; var current = grid.current; GUILayout.BeginHorizontal(); GUILayout.Label("Grid Width:"); var oldWidth = grid.width; grid.width = EditorGUILayout.IntSlider(grid.width, 0, 100); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Grid height:"); var oldHeight = grid.height; grid.height = EditorGUILayout.IntSlider(grid.height, 0, 100); GUILayout.EndHorizontal(); if (grid.width != oldWidth || grid.height != oldHeight) { grid.GenerateMaps(false); } for (int i = 0; i < grid.streets.Count; i++) { if (grid.streets [grid.streets.Count - 1].Count > 1) { GUILayout.BeginHorizontal(); GUILayout.Label("Street" + (i + 1) + ": "); if (GUILayout.Button("Select")) { for (int j = 0; j < grid.selectedStreet.Count; j++) { grid.selectedStreet [j] = false; } grid.selectedStreet [i] = true; } if (GUILayout.Button("Deselect")) { grid.selectedStreet [i] = false; } if (GUILayout.Button("Delete")) { grid.streets.RemoveAt(i); grid.selectedStreet.RemoveAt(i); if (grid.selectedStreet.Count > i) { grid.selectedStreet [i] = false; } } GUILayout.EndHorizontal(); } } //select number of building types and add building prefabs showBuildingTypes = EditorGUILayout.Foldout(showBuildingTypes, "Show Building Types"); if (showBuildingTypes) { GUILayout.BeginVertical("Box", GUILayout.ExpandWidth(true)); EditorGUILayout.Space(); AddTypesOfPrefabs("House Types", grid.housePrefab); EditorGUILayout.Space(); AddTypesOfPrefabs("Skyscraper Types", grid.skyscraperPrefab); GUILayout.EndVertical(); } EditorGUILayout.Space(); //select number of building types and add building prefabs showTreeTypes = EditorGUILayout.Foldout(showTreeTypes, "Show Building Types"); if (showTreeTypes) { GUILayout.BeginVertical("Box", GUILayout.ExpandWidth(true)); AddTypesOfPrefabs("ConeTree Types", grid.conetreePrefab); EditorGUILayout.Space(); AddTypesOfPrefabs("WoodTree Types", grid.woodtreePrefab); GUILayout.EndVertical(); } DrawBasicEditTools(); if (GUILayout.Button("Generate City", GUILayout.Height(30))) { grid.showGrid = false; if (grid.terrainData == null || grid.city == null) { grid.city = GameObject.Find("MyProceduralCity"); if (grid.city) { grid.terrainData = grid.city.GetComponent <TerrainData> (); } else { // create new city GO grid.terrainData = new TerrainData(); grid.city = Terrain.CreateTerrainGameObject(grid.terrainData); grid.city.name = "MyProceduralCity"; grid.city.transform.position = Vector3.zero; grid.city.AddComponent <CityPopulator> (); } } grid.city.GetComponent <CityPopulator> ().Populate(grid); } if (GUILayout.Button("Reset Map", GUILayout.Height(30))) { grid.showGrid = true; redoStack = new LinkedList <GridCreator.CellType[, ]> (); undoStack = new LinkedList <GridCreator.CellType[, ]> (); grid.GenerateMaps(true); current = (GridCreator.CellType[, ])grid.worldMap.Clone(); undoStack.AddLast(new LinkedListNode <GridCreator.CellType[, ]> (grid.worldMap)); } if (GUILayout.Button("Save!", GUILayout.Height(30))) { var city = grid.city; if (city == null) { Debug.Log("Please generate map first"); } else { city.GetComponent <CityPopulator> ().ClearFromScripts(); PrefabCreator.CreatePrefab(city.gameObject); } } GUI.enabled = true; SceneView.RepaintAll(); if (GUI.changed) { grid.firstTimeBuild = true; } //base.OnInspectorGUI (); }
private void OnEnable() { grid = (GridCreator)target; grid.GenerateMaps(false); grid.showGrid = true; }
private void Reset() { grid = (GridCreator)target; grid.GenerateMaps(true); }