void OnGUI() { if (calculatorThread != null) { GUI.enabled = false; } MeshFilter newMesh; newMesh = (MeshFilter)EditorGUILayout.ObjectField("Object: ", meshFilter, typeof(MeshFilter), true); if (newMesh != meshFilter) { meshFilter = newMesh; Reset(); return; } GUI.enabled = true; if (mesh == null) { return; } GUILayout.Label(string.Format("Size: {0} x {1} x {2}", size.x, size.y, size.z)); if (GUILayout.Toggle(drawFull, "Show Blocks", "Button") != drawFull) { drawFull = !drawFull; SceneView.RepaintAll(); } DisplayGUI(); CalculateGUI(); ConfigGUI(); PaletteGUI(); CompositionGUI(); StructureDetailsGUI(); ExportGUI(); float x0 = editorSettings.invertX ? Mathf.Ceil(mesh.bounds.max.x) - 0.5f : Mathf.Floor(mesh.bounds.min.x) + 0.5f; float y0 = editorSettings.invertY ? Mathf.Ceil(mesh.bounds.max.y) - 0.5f : Mathf.Floor(mesh.bounds.min.y) + 0.5f; float z0 = editorSettings.invertZ ? Mathf.Ceil(mesh.bounds.max.z) - 0.5f : Mathf.Floor(mesh.bounds.min.z) + 0.5f; posx = new Vector3( x0 + (AABBGenerator.RelativeX(pos, editorSettings.axisOrder, size) * (editorSettings.invertX ? -1 : 1)), y0 + (AABBGenerator.RelativeY(pos, editorSettings.axisOrder, size) * (editorSettings.invertY ? -1 : 1)), z0 + (AABBGenerator.RelativeZ(pos, editorSettings.axisOrder, size) * (editorSettings.invertZ ? -1 : 1)) ); }
void Start() { dungeonWidth = DungeonStates.instance.dungeonWidth; dungeonHeight = DungeonStates.instance.dungeonHeight; roomMaxSize = DungeonStates.instance.roomMaxSize; roomMinSize = DungeonStates.instance.roomMinSize; roomMaxMonsters = DungeonStates.instance.roomMaxMonsters; maxRooms = DungeonStates.instance.maxRooms; // generamos el dungeon _dungeonGenerator = new AABBGenerator(); //_dungeonGenerator = new BSPGenerator(); //_dungeonGenerator = new AutomataGenerator(); _tileMap = _dungeonGenerator.makeMap(dungeonWidth, dungeonHeight, maxRooms, roomMinSize, roomMaxSize); //_tileMap = _dungeonGenerator.makeMap(dungeonWidth, dungeonHeight); //_tileMap = _dungeonGenerator.makeMap(dungeonWidth, dungeonHeight); _tileObjects = new GameObject[dungeonWidth, dungeonHeight]; float tileWidth = floorTilePrefab.GetComponent <Renderer> ().bounds.size.z; float tileHeight = floorTilePrefab.GetComponent <Renderer> ().bounds.size.x; Vector3 translation = new Vector3(); for (int x = 0; x < dungeonWidth; x++) { for (int y = 0; y < dungeonHeight; y++) { Tile currentTile = _tileMap [x, y]; GameObject tileObject = null; if (currentTile.blocked != true) { if (currentTile.room1) { tileObject = (GameObject)GameObject.Instantiate(floorTilePrefab); } else if (currentTile.room2) { tileObject = (GameObject)GameObject.Instantiate(floorTilePrefab2); } else if (currentTile.room3) { tileObject = (GameObject)GameObject.Instantiate(floorTilePrefab3); } else if (currentTile.room4) { tileObject = (GameObject)GameObject.Instantiate(floorTilePrefab4); } else if (currentTile.pasillo) { tileObject = (GameObject)GameObject.Instantiate(pasilloTilePrefab); } else { tileObject = (GameObject)GameObject.Instantiate(floorTilePrefab); } translation.x = tileWidth * x; translation.z = -tileHeight * y; tileObject.transform.Translate(translation); _tileObjects [x, y] = tileObject; tileObject.transform.parent = gameObject.transform; } else { bool wall = false; //checkear si es pared de algun room for (int i = y - 1; i <= y + 1; i++) { for (int j = x - 1; j <= x + 1; j++) { if (i > 0 && i < dungeonHeight) { if (j > 0 && j < dungeonWidth) { if (_tileMap [j, i].blocked != true) { wall = true; } } } } } if (wall) { tileObject = (GameObject)GameObject.Instantiate(wallTilePrefab); translation.x = tileWidth * x; translation.z = -tileHeight * y; tileObject.transform.Translate(translation); _tileObjects [x, y] = tileObject; tileObject.transform.parent = gameObject.transform; } } } } placeObjects(); //NavMeshBuilder.BuildNavMesh (); int PlayerRoomSpawnNumer = Random.Range(0, _dungeonGenerator.ArrayRooms.Count); Room PlayerRoomSpawn = _dungeonGenerator.ArrayRooms [PlayerRoomSpawnNumer]; _dungeonGenerator.ArrayRooms [PlayerRoomSpawnNumer].canSpawnEnemys = false; _player = (GameObject)Instantiate(playerPrefab); _playerX = (int)Random.Range(PlayerRoomSpawn.rect.xMin + 1, PlayerRoomSpawn.rect.xMax); _playerY = (int)Random.Range(PlayerRoomSpawn.rect.yMin + 1, PlayerRoomSpawn.rect.yMax); GameObject currentPlayerTile = (GameObject)_tileObjects [_playerX, _playerY]; _player.transform.position = currentPlayerTile.transform.position; _player.transform.position += (Vector3.up * 5); _camera = (GameObject)Instantiate(CameraPrefab); _camera.transform.position = currentPlayerTile.transform.position; _camera.transform.position += (Vector3.up * 10); int ObjetiveRoomNumber; while (true) { ObjetiveRoomNumber = Random.Range(0, _dungeonGenerator.ArrayRooms.Count); if (ObjetiveRoomNumber != PlayerRoomSpawnNumer) { break; } } Room ObjetiveRoom = _dungeonGenerator.ArrayRooms [ObjetiveRoomNumber]; _objetive = (GameObject)Instantiate(ObjetivePrefab); _objetiveX = (int)Random.Range(ObjetiveRoom.rect.xMin + 1, ObjetiveRoom.rect.xMax); _objetiveY = (int)Random.Range(ObjetiveRoom.rect.yMin + 1, ObjetiveRoom.rect.yMax); GameObject ObjetiveTile = (GameObject)_tileObjects [_objetiveX, _objetiveY]; _objetive.transform.position = ObjetiveTile.transform.position; _objetive.transform.position += (Vector3.up * 5); Invoke("placeEnemies", 2f); }
void Export() { string path = EditorUtility.SaveFilePanelInProject("Export structure...", "struct_file", "json", "Export..."); if (path.Length == 0) { return; } JsonStructure toExport = new JsonStructure(); if (structure.structureUID == string.Empty) { Debug.LogError("Missing Structure ID! Check Structure Details category."); return; } toExport.uniqueName = structure.structureUID; toExport.width = (int)size.x; toExport.height = (int)size.y; toExport.length = (int)size.z; toExport.palette = new List <JsonPaletteEntry>(); foreach (PaletteEntry entry in structure.palette) { if (!entry.isValid) { Debug.LogError("Invalid palette entry! Check Palette category."); return; } toExport.palette.Add(new JsonPaletteEntry(entry.isOreDict? "ore" : entry.mod, entry.name, entry.identifier, entry.meta)); } Block master = structure.validFullBlocks.FirstOrDefault(x => x.pos == structure.masterPos); if (master == null) { Debug.LogError("Master block not set or missing palette value! Check Composition category."); return; } PaletteEntry masterPaletteEntry = structure.palette.FirstOrDefault(x => x.identifier == master.paletteValue); if (masterPaletteEntry == null) { Debug.LogError("Master block is missing valid palette value! Check Composition and Palette categories."); return; } toExport.master = new JsonMaster( calculator.BlockPosToLocalX(master.pos), calculator.BlockPosToLocalY(master.pos), calculator.BlockPosToLocalZ(master.pos), masterPaletteEntry.isOreDict ? "ore" : masterPaletteEntry.mod, masterPaletteEntry.name, masterPaletteEntry.meta); toExport.pointsOfInterest = new List <JsonPoI>(); foreach (PoI poi in structure.pointsOfInterest) { if (structure.ignoredPositions2.Contains(poi.pos) || !structure.validFullBlocks.Any(x => x.pos == poi.pos)) { continue; } toExport.pointsOfInterest.Add(new JsonPoI() { position = poi.pos, name = poi.id, facing = poi.facing }); } int firstDimension = AABBGenerator.FirstDimension((int)size.x, (int)size.y, (int)size.z, editorSettings.axisOrder); int secondDimension = AABBGenerator.SecondDimension((int)size.x, (int)size.y, (int)size.z, editorSettings.axisOrder); int thirdDimension = AABBGenerator.ThirdDimension((int)size.x, (int)size.y, (int)size.z, editorSettings.axisOrder); toExport.structure = new List <string>(); string emptyLine = new string(' ', firstDimension); for (int line = 0; line < secondDimension * thirdDimension; line++) { toExport.structure.Add(emptyLine); } foreach (Block block in structure.validFullBlocks) { if (structure.ignoredPositions2.Contains(block.pos)) { continue; } if (block.IsInvalid()) { Debug.LogError(string.Format("Block {0} is missing valid palette value! Check Composition and Palette categories.", block.pos)); return; } int firstPos = AABBGenerator.RelativeX(block.pos, editorSettings.axisOrder, size); int secondPos = AABBGenerator.RelativeZ(block.pos, editorSettings.axisOrder, size); int thirdPos = AABBGenerator.RelativeY(block.pos, editorSettings.axisOrder, size); //Debug.Log(string.Format("{0}, {1}, {2}, {3}, {4}", firstPos, secondPos, thirdPos, toExport.structure[thirdPos * secondDimension + secondPos].Length, block.paletteValue)); toExport.structure[thirdPos * secondDimension + secondPos] = ReplaceAt(toExport.structure[thirdPos * secondDimension + secondPos], firstPos, block.paletteValue); } toExport.AABB = new List <byte>(); List <Box>[] orderedList = new List <Box> [(int)(size.x * size.y * size.z)]; foreach (BlockPosition aabb in structure.allSubAABBs) { if (orderedList[aabb.pos] == null) { orderedList[aabb.pos] = new List <Box>(); } orderedList[aabb.pos].Add(aabb.normalizedBox); } Box fullBox = new Box(0, 0, 0, 16, 16, 16); StringBuilder builder = new StringBuilder(); for (int index = 0; index < orderedList.Length; index++) { if (structure.ignoredPositions2.Contains(index) || orderedList[index] == null) //no collision boxes { builder.Append("null"); } else if (orderedList[index].Count == 1 && orderedList[index][0] == fullBox) //full collision box { builder.Append("[]"); } else //partial collision boxes { List <string> floats = new List <string>(); foreach (Box box in orderedList[index]) { floats.Add(box.ToString(editorSettings.outputFormat)); } builder.Append("[" + string.Join(",", floats) + "]"); } builder.Append(","); } builder.Length -= 1; string json = JsonUtility.ToJson(toExport, false); json = json.Insert(json.LastIndexOf('[') + 1, builder.ToString()); using (StreamWriter writer = new StreamWriter(path)) { writer.Write(json); writer.Flush(); writer.Close(); } }