public void parseroom2(roomsimple room, int[,] heighttable, List<GameObject> modelarray, GameObject parent ) { //use the parent parameter as the parent of the room, it also holds the RoomComponent later GameObject roomcenter = parent; roomcenter.transform.position = Vector3.zero; // add each tile made to the tile list tiles.Add(roomcenter); foreach (Vector2Serializer wall in room.walls){ float posx = wall.x; float posy = wall.y; // only look at tiles above 0,0 if ((posx >= 0.0) && (posy >= 0.0)){ // use the height to create walls of the correct height int height = heighttable[(int)posx,(int)posy]; for (int k = 0; k < height+(wallheight); k++){ Vector3 rot = new Vector3(UnityEngine.Random.Range(0.0f,360.0f),UnityEngine.Random.Range(0.0f,360.0f),UnityEngine.Random.Range(0.0f,360.0f)); rot.x = Mathf.Round(rot.x / 90) * 90; rot.y = Mathf.Round(rot.y / 90) * 90; rot.z = Mathf.Round(rot.z / 90) * 90; if (wallmasterlist.Contains(new Vector3(posx,k,posy))){ //Debug.Log(new Vector3(posx,k,posy)); //Debug.Log("already in wallmasterlist"); continue; } wallmasterlist.Add(new Vector3(posx,k,posy)); GameObject currentgo = Instantiate(modelarray[UnityEngine.Random.Range(0,modelarray.Count)],new Vector3(posx,k,posy),Quaternion.identity) as GameObject; currentgo.transform.Rotate(rot.x,rot.y,rot.z); tiles.Add(currentgo); //here is where we check the x and z and determine what parent this tile belongs to if (wallcheck(posx,posy,room) == 0) { currentgo.transform.parent = roomcenter.transform.FindChild("leftwall").transform; } else if (wallcheck(posx,posy,room) == 1) { currentgo.transform.parent = roomcenter.transform.FindChild("rightwall").transform; } else if (wallcheck(posx,posy,room) == 2) { currentgo.transform.parent = roomcenter.transform.FindChild("topwall").transform; } else if (wallcheck(posx,posy,room) == 3) { currentgo.transform.parent = roomcenter.transform.FindChild("bottomwall").transform; } //I think the wrong positions are added to the walltobuild because of the offset roomcenter //grab the roomcomponent of the current room/parent object, and store the actual walls that we build here. // these are the blocks we WILL clear from the wallmasterlist when we regen the room roomcenter.GetComponent<Roomcomponent>().wallstobuild.Add(currentgo.transform.localPosition); } } } foreach (Vector2Serializer floor in room.floortiles){ float posx = floor.x; float posy = floor.y; if ((posx >= 0.0) && (posy >= 0.0)){ if (!edgecheck(posx,posy,room)){ int height = heighttable[(int)posx,(int)posy]; int k = height-2; Vector3 rot = new Vector3(UnityEngine.Random.Range(0.0f,360.0f),UnityEngine.Random.Range(0.0f,360.0f),UnityEngine.Random.Range(0.0f,360.0f)); rot.x = Mathf.Round(rot.x / 90) * 90; rot.y = Mathf.Round(rot.y / 90) * 90; rot.z = Mathf.Round(rot.z / 90) * 90; GameObject currentgo = Instantiate(modelarray[3],new Vector3(posx,k,posy),Quaternion.identity) as GameObject; tiles.Add(currentgo); currentgo.transform.parent = roomcenter.transform.FindChild("floor").transform; currentgo.transform.Rotate(rot.x,rot.y,rot.z); } else{ int height = heighttable[(int)posx,(int)posy]; for (int k = height-3; k < height-1; k++){ GameObject currentgo = Instantiate(modelarray[3],new Vector3(posx,k,posy),Quaternion.identity) as GameObject; tiles.Add(currentgo); currentgo.transform.parent = roomcenter.transform.FindChild("floor").transform; } } } } }
public bool edgecheck(float posx,float posy,roomsimple room) { if ((posx == room.xpos-1) || (posy== room.ypos-1)){ //Debug.Log ("edge"); return true; } if ((posx == room.width+room.xpos) || (posy == room.height+room.ypos)){ //Debug.Log ("edge"); return true; } return false; }
public void Run() { roomparents.Clear(); rooms.Clear(); crooms.Clear(); //if theres no generator object create one if (GameObject.Find("Generator") == null) { generator = new GameObject("Generator"); generator.AddComponent<mazegenerator_python_standin>(); } else { DestroyImmediate(generator); generator = new GameObject("Generator"); generator.AddComponent<mazegenerator_python_standin>(); } //run the generation generator.GetComponent<mazegenerator_python_standin>().generate(iterations,xcenter,ycenter,xsd,ysd,doormaxalways,doorminalways,doorrandomize,desiredDoorWidth,flatlevel,heightmin,heightmax); table =(int[,]) generator.GetComponent<mazegenerator_python_standin>().convertedQuadTable; heighttable = (int[,]) generator.GetComponent<mazegenerator_python_standin>().heightsTable; rooms = generator.GetComponent<mazegenerator_python_standin>().rooms; foreach (room _room in rooms) { roomsimple currentroom = new roomsimple(_room.width,_room.height,_room.center,_room.walls,_room.floortiles,_room.xpos,_room.ypos); crooms.Add(currentroom); } // we should check if generate returned something(maybe a bool on completion) foreach (GameObject tile in tiles) { DestroyImmediate(tile); } tiles.Clear(); wallmasterlist.Clear(); foreach (roomsimple room in crooms) { parseroom2(room,heighttable,modelarray); } // fill the location information on each tile foreach (GameObject tile in tiles) { // we ignore the roomcomponents that are in the tiles list, since these are not really tiles and have no gentiletex parameter if (tile.transform.parent != null) { tile.GetComponent<genFlatTexTile>().updateDicts(); } } // now generate the atlas genMajorAtlas(); // now generate the meshes now that the atlas is generated foreach (GameObject parent in roomparents) { clusterRoomAndGenMesh(parent); } curlevel = new levelobject(table,heighttable,crooms); save("auto_iteration_save.txt"); }
public int wallcheck(float posx,float posy,roomsimple room) { if (posx == room.xpos-1){ //Debug.Log ("left"); return 0; } if (posx == room.width+room.xpos){ //Debug.Log ("right"); return 1; } if (posy == room.height+room.ypos){ //Debug.Log ("top"); return 2; } if (posy == room.ypos-1){ //Debug.Log ("bottom"); return 3; } return 4; //Debug.Log("something has gone wrong"); }
public void parseroom2(roomsimple room, int[,] heighttable, List<GameObject> modelarray ) { //create a new centerobject and the 4 walls and floor subparents GameObject newroomcenter = new GameObject("Room"); roomparents.Add(newroomcenter); GameObject leftwall = new GameObject("leftwall"); GameObject rightwall = new GameObject("rightwall"); GameObject topwall = new GameObject("topwall"); GameObject bottomwall = new GameObject("bottomwall"); GameObject floor = new GameObject("floor"); leftwall.transform.parent = newroomcenter.transform; rightwall.transform.parent = newroomcenter.transform; bottomwall.transform.parent = newroomcenter.transform; topwall.transform.parent = newroomcenter.transform; //topwall.layer = 2; //topwall.AddComponent<genFlatTexWall>(); floor.transform.parent = newroomcenter.transform; newroomcenter.AddComponent<Roomcomponent>().room = room; newroomcenter.GetComponent<Roomcomponent>().load_models(); parseroom2(room,heighttable,modelarray,newroomcenter); }