public override void OnInspectorGUI() { //Called whenever the inspector is drawn for this object., Dungeonizer realscript = (Dungeonizer)target; if (realscript.minRoomSize > realscript.maxRoomSize) { EditorGUILayout.HelpBox("Please make sure your minumum room size isn't bigger than maximum room size.", MessageType.Error); } EditorGUILayout.HelpBox("Follow us, Lets Make Dungeons Together: https://www.twitch.tv/dungeonizer", MessageType.Info); DrawDefaultInspector(); //This draws the default screen. You don't need this if you want //to start from scratch, but I use this when I'm just adding a button or //some small addition and don't feel like recreating the whole inspector. if (GUILayout.Button("Create Now")) { //add everthing the button would do. realscript.ClearOldDungeon(true); realscript.Generate(); } }
public void NewLevel() { Dungeonizer dungeonizer = GetComponent <Dungeonizer>(); dungeonizer.ClearOldDungeon(); dungeonizer.Generate(); StartCoroutine(Respawn()); Debug.Log("Locating Player"); //DungeonGenLibrary.Tile t; }
public IEnumerator dungeonTimer() { // This means you can create a new dungeon whenever you want. Dungeonizer d = dungeonizer.GetComponent("Dungeonizer") as Dungeonizer; d.ClearOldDungeon(); d.Generate(); yield return(new WaitForSeconds(0.3f)); StartCoroutine(dungeonTimer()); }
public override void OnInspectorGUI() { //Called whenever the inspector is drawn for this object. DrawDefaultInspector(); //This draws the default screen. You don't need this if you want //to start from scratch, but I use this when I'm just adding a button or //some small addition and don't feel like recreating the whole inspector. Dungeonizer realscript = (Dungeonizer)target; if (GUILayout.Button("Create Now")) { //add everthing the button would do. realscript.ClearOldDungeon(true); realscript.Generate(); } }
}; //,"-y"}; public void CheckCustomRooms(Dungeonizer dungeonizer) { customRooms = dungeonizer.ListGet(); customRoomTypes = dungeonizer.TypeGet(); }
public void Generate() { Dungeon dungeon = new Dungeon(); dungeon.min_size = minRoomSize; dungeon.max_size = maxRoomSize; dungeon.maximumRoomCount = maximumRoomCount; dungeon.roomMargin = roomMargin; dungeon.minimumRoomMargin = minimumRoomMargin; dungeon.Generate(); //Calculates all static object locations (walls, corridors, doors, corners etc.) //after this line, dungeonizer will instantiate objects in their calculated locations. foreach (MapTile mapTile in Dungeon.map) { int tile = mapTile.type; int tile_height = mapTile.tile_height; int orientation = mapTile.orientation; GameObject created_tile; Vector3 tile_location; if (!makeIt3d) { tile_location = new Vector3(mapTile.x * tileScaling, mapTile.y * tileScaling, 0); } else { tile_location = new Vector3(mapTile.x * tileScaling, 0, mapTile.y * tileScaling); } created_tile = null; if (tile == 1) { GameObject floorPrefabToUse = floorPrefab[Random.Range(0, floorPrefab.Length)]; Room room = mapTile.room; if (room != null) { foreach (CustomRoom customroom in customRooms) { if (customroom.roomId == room.room_id) { floorPrefabToUse = customroom.floorPrefab; break; } } } created_tile = GameObject.Instantiate(floorPrefabToUse, tile_location, Quaternion.identity) as GameObject; } Dungeonizer dungeonizer = this; if (Dungeon.walls.Contains(tile) || (Dungeon.corridor_walls.Contains(tile) && !(dungeonizer.corridorWallPrefab.Length > 0))) { GameObject wallPrefabToUse = wallPrefab[Random.Range(0, wallPrefab.Length)]; Room room = mapTile.room; if (room != null) { foreach (CustomRoom customroom in customRooms) { if (customroom.roomId == room.room_id) { wallPrefabToUse = customroom.wallPrefab; break; } } } created_tile = GameObject.Instantiate(wallPrefabToUse, tile_location, Quaternion.identity) as GameObject; if (!makeIt3d) //wall rotation stuff here. { created_tile.transform.Rotate(Vector3.forward * (90 * (tile - 4))); } else { created_tile.transform.Rotate(Vector3.up * (90 * (tile - 4))); } } else if (Dungeon.corridor_walls.Contains(tile)) { GameObject wallPrefabToUse = corridorWallPrefab[Random.Range(0, corridorWallPrefab.Length)]; Room room = mapTile.room; if (room != null) { foreach (CustomRoom customroom in customRooms) { if (customroom.roomId == room.room_id) { wallPrefabToUse = customroom.wallPrefab; break; } } } created_tile = GameObject.Instantiate(wallPrefabToUse, tile_location, Quaternion.identity) as GameObject; if (!makeIt3d) //wall rotation stuff here. { created_tile.transform.Rotate(Vector3.forward * (90 * (tile - 4))); } else { created_tile.transform.Rotate(Vector3.up * (90 * (tile - 4))); } } if (tile == 3) { if (corridorFloorPrefab.Length > 0) { created_tile = GameObject.Instantiate(corridorFloorPrefab[Random.Range(0, corridorFloorPrefab.Length)], tile_location, Quaternion.identity) as GameObject; } else { created_tile = GameObject.Instantiate(floorPrefab[Random.Range(0, floorPrefab.Length)], tile_location, Quaternion.identity) as GameObject; } if (orientation == 1 && makeIt3d) { created_tile.transform.Rotate(Vector3.up * (-90)); } } if (Dungeon.corners.Contains(tile)) { GameObject cornerPrefabToUse = cornerPrefab; Room room = mapTile.room; if (room != null) { foreach (CustomRoom customroom in customRooms) { if (customroom.roomId == room.room_id) { cornerPrefabToUse = customroom.cornerPrefab; break; } } } if (cornerPrefabToUse) //there was a bug in this line. A good man helped for fix. { created_tile = GameObject.Instantiate(cornerPrefabToUse, tile_location, Quaternion.identity) as GameObject; if (cornerRotation) { if (!makeIt3d) { created_tile.transform.Rotate(Vector3.forward * (-90 * (tile - 4))); } else { created_tile.transform.Rotate(Vector3.up * (-90 * (tile - 4))); } } } else { created_tile = GameObject.Instantiate(wallPrefab[Random.Range(0, wallPrefab.Length)], tile_location, Quaternion.identity) as GameObject; } } if (created_tile) { created_tile.transform.parent = transform; } } GameObject end_point; GameObject start_point; if (!makeIt3d) { end_point = GameObject.Instantiate(exitPrefab, new Vector3(Dungeon.goalRoom.x * tileScaling, Dungeon.goalRoom.y * tileScaling, 0), Quaternion.identity) as GameObject; start_point = GameObject.Instantiate(startPrefab, new Vector3(Dungeon.startRoom.x * tileScaling, Dungeon.startRoom.y * tileScaling, 0), Quaternion.identity) as GameObject; } else { end_point = GameObject.Instantiate(exitPrefab, new Vector3((Dungeon.goalRoom.x + Mathf.FloorToInt(Dungeon.goalRoom.w / 2)) * tileScaling, 0, (Dungeon.goalRoom.y + Mathf.FloorToInt(Dungeon.goalRoom.h / 2)) * tileScaling), Quaternion.identity) as GameObject; start_point = GameObject.Instantiate(startPrefab, new Vector3((Dungeon.startRoom.x + Mathf.FloorToInt(Dungeon.startRoom.w / 2)) * tileScaling, 0, (Dungeon.startRoom.y + Mathf.FloorToInt(Dungeon.startRoom.h / 2)) * tileScaling), Quaternion.identity) as GameObject; } end_point.transform.parent = transform; start_point.transform.parent = transform; //Spawn Objects; List <SpawnList> spawnedObjectLocations = new List <SpawnList> (); //looks for suitable locations to spawn stuff. (like monsters, chests..) foreach (MapTile mapTile in Dungeon.map) { if (mapTile.type == 1 //do not spawn anything on players start location or finish. && !(mapTile.x == Dungeon.startRoom.x + Mathf.FloorToInt(Dungeon.startRoom.w / 2) && mapTile.y == Dungeon.startRoom.y + Mathf.FloorToInt(Dungeon.startRoom.h / 2)) && !(mapTile.x == Dungeon.goalRoom.x + Mathf.FloorToInt(Dungeon.goalRoom.w / 2) && mapTile.y == Dungeon.goalRoom.y + Mathf.FloorToInt(Dungeon.goalRoom.h / 2)) ) { var location = new SpawnList(); location.byWall = mapTile.isEdge; location.wallLocation = mapTile.edgeLocation; location.x = mapTile.x; location.y = mapTile.y; if (mapTile.byCorridor) { location.byCorridor = true; } location.room = mapTile.room; int roomCenterX = (int)Mathf.Floor(location.room.w / 2) + location.room.x; int roomCenterY = (int)Mathf.Floor(location.room.h / 2) + location.room.y; if (mapTile.x == roomCenterX + 1 && mapTile.y == roomCenterY + 1) { location.inTheMiddle = true; } spawnedObjectLocations.Add(location); } else if (mapTile.type == 3) { var location = new SpawnList(); location.x = mapTile.x; location.y = mapTile.y; if (mapTile.isDoor) { location.byCorridor = true; location.asDoor = mapTile.doorDirection; location.room = mapTile.room; spawnedObjectLocations.Add(location); } } } for (int i = 0; i < spawnedObjectLocations.Count; i++) { SpawnList temp = spawnedObjectLocations [i]; int randomIndex = Random.Range(i, spawnedObjectLocations.Count); spawnedObjectLocations [i] = spawnedObjectLocations [randomIndex]; spawnedObjectLocations [randomIndex] = temp; } int objectCountToSpawn = 0; //you will need below 2 lines if you are going to use dynamic pathfinding. And a NavMeshSurface component attached to same gameobject. //surface = GetComponent<NavMeshSurface>(); //surface.BuildNavMesh(); //Now instantiating gameobjects wanted to "spawn" foreach (SpawnOption objectToSpawn in spawnOptions) { objectCountToSpawn = Random.Range(objectToSpawn.minSpawnCount, objectToSpawn.maxSpawnCount); while (objectCountToSpawn > 0) { bool created = false; for (int i = 0; i < spawnedObjectLocations.Count; i++) { bool createHere = false; if (!spawnedObjectLocations[i].spawnedObject && !spawnedObjectLocations[i].byCorridor) { if (objectToSpawn.spawnRoom > maximumRoomCount) { objectToSpawn.spawnRoom = 0; } if (objectToSpawn.spawnRoom == 0) { if (objectToSpawn.spawnByWall) { if (spawnedObjectLocations[i].byWall) { createHere = true; } } else if (objectToSpawn.spawmInTheMiddle) { if (spawnedObjectLocations[i].inTheMiddle) { createHere = true; } } else { createHere = true; } } else { if (spawnedObjectLocations[i].room.room_id == objectToSpawn.spawnRoom) { if (objectToSpawn.spawnByWall) { if (spawnedObjectLocations[i].byWall) { createHere = true; } } else { createHere = true; } } } } if (createHere) //means dungeonizer found a suitable place to put object. { SpawnList spawnLocation = spawnedObjectLocations[i]; GameObject newObject; Quaternion spawnRotation = Quaternion.identity; if (!makeIt3d) { newObject = GameObject.Instantiate(objectToSpawn.gameObject, new Vector3(spawnLocation.x * tileScaling, spawnLocation.y * tileScaling, 0), spawnRotation) as GameObject; } else { if (spawnLocation.byWall) { if (spawnLocation.wallLocation == "s") { spawnRotation = Quaternion.Euler(new Vector3(0, 270, 0)); } else if (spawnLocation.wallLocation == "n") { spawnRotation = Quaternion.Euler(new Vector3(0, 90, 0)); } else if (spawnLocation.wallLocation == "e") { spawnRotation = Quaternion.Euler(new Vector3(0, 180, 0)); } else if (spawnLocation.wallLocation == "w") { spawnRotation = Quaternion.Euler(new Vector3(0, 0, 0)); } } else { if (objectToSpawn.spawnRotated) { spawnRotation = Quaternion.Euler(new Vector3(0, Random.Range(0, 360), 0)); } else { spawnRotation = Quaternion.Euler(new Vector3(0, Random.Range(0, 2) * 90, 0)); } } newObject = GameObject.Instantiate(objectToSpawn.gameObject, new Vector3(spawnLocation.x * tileScaling, 0 + objectToSpawn.heightFix, spawnLocation.y * tileScaling), spawnRotation) as GameObject; } newObject.transform.parent = transform; spawnedObjectLocations[i].spawnedObject = newObject; objectCountToSpawn--; created = true; break; } } if (!created) //if cant find anywhere to put, dont put. (prevents endless loops) { objectCountToSpawn--; } } } //DOORS if (doorPrefab) { for (int i = 0; i < spawnedObjectLocations.Count; i++) { if (spawnedObjectLocations[i].asDoor > 0) { GameObject newObject; SpawnList spawnLocation = spawnedObjectLocations[i]; GameObject doorPrefabToUse = doorPrefab; Room room = spawnLocation.room; if (room != null) { foreach (CustomRoom customroom in customRooms) { if (customroom.roomId == room.room_id) { doorPrefabToUse = customroom.doorPrefab; break; } } } if (!makeIt3d) { newObject = GameObject.Instantiate(doorPrefabToUse, new Vector3(spawnLocation.x * tileScaling, spawnLocation.y * tileScaling, 0), Quaternion.identity) as GameObject; } else { newObject = GameObject.Instantiate(doorPrefabToUse, new Vector3(spawnLocation.x * tileScaling, 0, spawnLocation.y * tileScaling), Quaternion.identity) as GameObject; } if (!makeIt3d) { newObject.transform.Rotate(Vector3.forward * (-90 * (spawnedObjectLocations[i].asDoor - 1))); } else { newObject.transform.Rotate(Vector3.up * (-90 * (spawnedObjectLocations[i].asDoor - 1))); } newObject.transform.parent = transform; spawnedObjectLocations[i].spawnedObject = newObject; } } } }