public void GenerateHouses(ChunkData chunkData) { IEnumerator gen = objectGenerator.GenerateObjects(ObjectType.House, ProceduralTerrain.Current.TerrainHouseData, chunkData); mainQueue.EnqueueAction(gen); mainQueue.EnqueueAction(GenerateVillages(chunkData)); mainQueue.EnqueueAction(GenerateTreeHouseHouses(chunkData)); }
public void Initialise(Map map, int seed) { this.map = map; width = map.levelWidth; height = map.levelHeight; noiseMap = NoiseMapGenerator.Create(map, seed); wallMap = new int[width, height]; CreateWallMap(); ProcessMap(); MSMeshGenerator MSGen = GetComponent <MSMeshGenerator> (); Material[] mats = new Material[map.possibleTerrain.Length]; for (int i = 0; i < map.possibleTerrain.Length; i++) { mats [i] = map.possibleTerrain [i].terrainMaterial; } List <MeshFilter> walkables = MSGen.Generate(wallMap, map.tileSize, map.wallHeight, mats, map.wallMaterial); ObjectGenerator objGen = GetComponent <ObjectGenerator> (); List <GameObject> objects = objGen.GenerateObjects(map, noiseMap); NavMeshGenerator meshGen = GetComponent <NavMeshGenerator> (); meshGen.Initialise(); meshGen.BuildNavMesh(walkables, objects, wallMap.GetLength(0) * map.tileSize, wallMap.GetLength(1) * map.tileSize); StaticBatchingUtility.Combine(objects.ToArray(), objects [0].transform.parent.gameObject); Light worldLight = (Light)Instantiate(new GameObject(), Vector3.zero, Quaternion.Euler(map.lightOptions.angle), this.transform).AddComponent(typeof(Light)); worldLight.name = "World Light"; worldLight.type = LightType.Directional; worldLight.intensity = map.lightOptions.intensity; worldLight.color = map.lightOptions.lightColour; worldLight.shadows = LightShadows.Soft; worldLight.shadowStrength = 0.8f; if (map.postProcProfile != null) { Camera.main.GetComponent <PostProcessingBehaviour> ().profile = map.postProcProfile; } else { Debug.LogWarning("Map is missing a Post Processing Profile"); } }
public override void OnInspectorGUI() { DrawDefaultInspector(); ObjectGenerator myScript = (ObjectGenerator)target; if (GUILayout.Button("Generate Objects On Map")) { myScript.GenerateObjects(); return; } var gameObjects = myScript.FindAllGeneratedObjects(); if (gameObjects.Length > 0) { List <string> options = new List <string>(); for (int i = 0; i < gameObjects.Length; i++) { options.Add(gameObjects[i].name); } EditorGUILayout.Space(); selectedToSave = EditorGUILayout.Popup("Group to save", selectedToSave, options.ToArray()); if (GUILayout.Button("Save selected")) { myScript.SaveGenerated(options[selectedToSave]); return; } EditorGUILayout.Space(); selectedToDelete = EditorGUILayout.Popup("Group to delete", selectedToDelete, options.ToArray()); if (gameObjects.Length > 0 && GUILayout.Button("Delete selected")) { myScript.DeleteGenerated(options[selectedToSave]); selectedToSave = 0; selectedToDelete = 0; return; } } if (myScript.IsSavedDataExists()) { var options = myScript.GetSavedFileNameArray(); EditorGUILayout.Space(); selectedToLoad = EditorGUILayout.Popup("Group to load", selectedToLoad, options); if (GUILayout.Button("Load selected")) { myScript.LoadGenerated(options[selectedToLoad]); return; } } }
public override void OnInspectorGUI() { base.OnInspectorGUI(); // How many instances of the the object do we want to generate Generator.ObjectCount = EditorGUILayout.IntField("# Prefabs to Generate: ", Generator.ObjectCount); EditorGUILayout.Space(); // Grid Parameters for basic grid generation EditorGUILayout.LabelField("Grid Params (GPrm): (Only required for grid generation)"); Generator.SizeX = EditorGUILayout.FloatField("GPrm: Our Object Size (X)", Generator.SizeX); Generator.SizeZ = EditorGUILayout.FloatField("GPrm: Our Object Size (Z)", Generator.SizeZ); Generator.HeightY = EditorGUILayout.FloatField("GPrm: Object Y Axis Position: ", Generator.HeightY); Generator.GridWidth = EditorGUILayout.IntField("GPrm: Grid Width (In prefab #)", Generator.GridWidth); // How many unique game objects are nested within our prefabs that we generate Generator.NumberOfNestedObjects = Generator.ObjectToGenerate.transform.childCount; EditorGUILayout.Space(); // Here we set up the instatiate the unique object templates into a list for later use if (GUILayout.Button("Set Prefab Properties Up")) { Generator.GenerateUniqueObjects(Generator.NumberOfNestedObjects); } if (Generator.EditorObjects.Count > 0) { EditorGUILayout.LabelField($"Done: There are {Generator.EditorObjects.Count} nested objects within your prefab"); EditorGUILayout.Space(); } // Here we generate the desired quantity of prefab objects set to their default state if (GUILayout.Button("Generate Generic Objects")) { Generator.GenerateDefaultObjects(Generator.ObjectCount); } // If we already have generated objects in the scene under the GeneratorObject then we can process them here if (GUILayout.Button("Process Existing Objects")) { Generator.ProcessExistingObjects(); } if (Generator.ObjectsInScene.Count > 0) { EditorGUILayout.LabelField($"Done: There are {Generator.ObjectsInScene.Count} generated objects in the scene"); EditorGUILayout.Space(); } EditorGUILayout.Space(); _goToStep2 = EditorGUILayout.Toggle("Proceed: Step 2", _goToStep2); EditorGUILayout.Space(); if (_goToStep2) { // User input for the name of our default object within the prefab EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Default Object Name: ", GUILayout.Width(175)); Generator.EditorObjects[0].Name = GUILayout.TextArea(Generator.EditorObjects[0].Name); EditorGUILayout.EndHorizontal(); // User input for the name of our special objects within the prefab for (int i = 1; i < Generator.EditorObjects.Count; i++) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(i + "- Special Object Name: ", GUILayout.Width(175)); Generator.EditorObjects[i].Name = GUILayout.TextArea(Generator.EditorObjects[i].Name); EditorGUILayout.EndHorizontal(); } EditorGUILayout.Space(); // User input for the percentage chance of a generated object being our default type EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Default Object %: ", GUILayout.Width(150)); Generator.EditorObjects[0].Percentage = EditorGUILayout.Slider(Generator.EditorObjects[0].Percentage, 0, 100); EditorGUILayout.EndHorizontal(); /* User input for the percentage chance of a generated object being our special types */ for (int i = 1; i < Generator.EditorObjects.Count; i++) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField($"Special Obj #{i} %: ", GUILayout.Width(150)); Generator.EditorObjects[i].Percentage = EditorGUILayout.Slider(Generator.EditorObjects[i].Percentage, 0, 100); EditorGUILayout.EndHorizontal(); } EditorGUILayout.Space(); _goToStep3 = EditorGUILayout.Toggle("Proceed: Step 3", _goToStep3); if (_goToStep3) { int fieldsValidated = 0; foreach (var obj in Generator.EditorObjects) { if (obj.Name != null) { fieldsValidated++; } } if (fieldsValidated == Generator.EditorObjects.Count) { _goToStep2 = true; _goToStep3 = true; EditorGUILayout.Space(); // Here we use the objects generated in the previous method and start set their types based on probability. if (GUILayout.Button("Set Objects: Randomize Object Types")) { Generator.GenerateObjects(); } // This method allows us to reset all the objects back to the default state without any regeneration neeeded. if (GUILayout.Button("Set Objects: Default Object Type")) { if (EditorUtility.DisplayDialog("Confirm Default", "Are you sure you want to set all " + Generator.ObjectsInScene.Count + " objects to their default state?", "Yes", "No")) { Generator.SetObjectsToDefault(); } } // Gives the user the option to create a basic grid layout with the generated objects if (GUILayout.Button("Transform Objects: To Grid")) { if (EditorUtility.DisplayDialog("Confirm Transform", "Are you sure you want to move all " + Generator.ObjectsInScene.Count + " objects in the current scene?", "Yes", "No")) { Generator.TransformToGrid(); } } } } } EditorGUILayout.Space(); /* This button allows us to clear all filters from the GUI to allowing to restart the process, the user will * have to delete the gameobjects from the scene manually before continuing after. */ if (GUILayout.Button("Clear Filters")) { if (EditorUtility.DisplayDialog("Warning", "Do you want to clear all current filters? You will need to set the prefab properties up again", "Yes", "No")) { Generator.ResetFilters(); } } EditorGUILayout.Space(); }