public static void Show(EditorWindow host, Vector2 displayPosition, TileGeneration selectedTile) { _selectedType = selectedTile.GetTileType(); _startingType = _selectedType; hostWindow = host; var window = CreateInstance <CustomDropDown>(); var position = GetPosition(host, displayPosition); window.position = new Rect(position + host.position.position, s_DefaultSize); window.ShowPopup(); window.Focus(); }
private void DrawGrid() { // Detect if a tile has been clicked if (Event.current.type == EventType.MouseUp) { MouseUpEvent mouseEvent = MouseUpEvent.GetPooled(Event.current); if (mouseEvent != null) { OnMouseClick(mouseEvent); } } if (Event.current.type == EventType.MouseDrag && Event.current.button == 0) { MouseMoveEvent mouseDragEvent = MouseMoveEvent.GetPooled(Event.current); if (mouseDragEvent != null) { OnMousedrag(mouseDragEvent); } } Vector2 areaSizeLeft = new Vector2(150, 300); GUILayout.BeginArea(new Rect(leftMiddle - areaSizeLeft / 2, areaSizeLeft)); GUILayout.Label("Left-click drag selection"); dragSelection = GUILayout.SelectionGrid(dragSelection, dragLabels, 1); switch (dragSelection) { case 0: break; case 1: dragTileTypeIndex = GUILayout.SelectionGrid(dragTileTypeIndex, tileTypeLabels, 1, EditorStyles.radioButton, new GUILayoutOption[] { GUILayout.Width(75 * tileTypeLabels.Length) }); dragTileType = (TileGeneration.TileType)dragTileTypeIndex; break; case 2: GUILayout.BeginHorizontal(); GUILayout.Label("Wall height: "); GUILayout.TextField(dragWallHeight.ToString()); GUILayout.EndHorizontal(); wallHeightSliderValue = EditorGUI.IntSlider(new Rect(0, 165, 200, 12), wallHeightSliderValue, 0, 5); dragWallHeight = wallHeightSliderValue * 0.5f; GUILayout.Space(25); GUILayout.Label("Change wall material: "); dragChangeWallMaterialSelection = GUILayout.SelectionGrid(dragChangeWallMaterialSelection, boolValuesAsLabels, boolValuesAsLabels.Length, EditorStyles.radioButton); _changeWallMaterial = dragChangeWallMaterialSelection == 0; if (_changeWallMaterial) { EditorGUIUtility.labelWidth = 50; dragWallMaterial = (Material)EditorGUILayout.ObjectField("Material:", dragWallMaterial, typeof(Material), false, GUILayout.ExpandWidth(true)); } break; case 3: GUILayout.BeginHorizontal(); GUILayout.Label("Ceiling height: "); GUILayout.TextField(dragCeilingHeight.ToString()); GUILayout.EndHorizontal(); ceilingHeightSliderValue = EditorGUI.IntSlider(new Rect(0, 165, 200, 12), ceilingHeightSliderValue, 0, 5); dragCeilingHeight = ceilingHeightSliderValue * 0.5f; break; case 4: dragIsWalkableSelection = GUILayout.SelectionGrid(dragIsWalkableSelection, boolValuesAsLabels, boolValuesAsLabels.Length, EditorStyles.radioButton); _dragIsWalkable = dragIsWalkableSelection == 0; break; case 5: EditorGUIUtility.labelWidth = 50; dragMaterial = (Material)EditorGUILayout.ObjectField("Material:", dragMaterial, typeof(Material), false, GUILayout.ExpandWidth(true)); dragTilePrefab = (GameObject)EditorGUILayout.ObjectField("Tile prefab: ", dragTilePrefab, typeof(GameObject), false, GUILayout.ExpandWidth(true)); break; } GUILayout.EndArea(); // Area for Buttons for saving or instantiating the Grid, and selected tile options Vector2 areaSizeRight = new Vector2(200, 300); GUILayout.BeginArea(new Rect(rightMiddle - areaSizeRight / 2, areaSizeRight)); if (selectedTile != null) { EditorGUIUtility.labelWidth = 60; GUILayout.Label("Tile " + selectedTileNum + ": [" + selectedTile.GetCoordinates().x + "," + selectedTile.GetCoordinates().y + "]"); selectedTile.SetTileType((TileGeneration.TileType)EditorGUILayout.EnumPopup("TileType: ", selectedTile.GetTileType(), GUILayout.Width(areaSizeRight.x - 50))); selectedTile.AssignMaterial((Material)EditorGUILayout.ObjectField("Material:", selectedTile.GetMaterial(), typeof(Material), false, GUILayout.Width(areaSizeRight.x - 50))); } if (GUILayout.Button("Instantiate Grid", buttonParams)) { grid.InstantiateGrid(); } if (GUILayout.Button("Save Grid as Prefab", buttonParams)) { string savePrefabPath = EditorUtility.SaveFilePanelInProject("Save Grid as Prefab", "UnnamedGrid.prefab", "prefab", "Please select file name to save the grid to:", "Assets/Prefabs/Grids/"); if (!string.IsNullOrEmpty(savePrefabPath)) { string[] fullPathString = savePrefabPath.Split(new char[] { '/' }); string gridName = "Undefined"; for (int i = 0; i < fullPathString.Length; i++) { if (fullPathString[i].Contains(".")) { gridName = fullPathString[i].Substring(0, fullPathString[i].IndexOf('.')); } } GameObject gridToSaveAsPrefab = grid.GetGrid(gridName); PrefabUtility.SaveAsPrefabAsset(gridToSaveAsPrefab, savePrefabPath); GameObject.DestroyImmediate(gridToSaveAsPrefab); } } if (GUILayout.Button("Return to Grid Options", buttonParams)) { _reset = true; } GUILayout.EndArea(); // Draw grid tiles with their respective materials and types tileAreas.Clear(); wallAreas.Clear(); int wallY = 0; for (int y = 0; y < gridTiles.GetLength(1); y++) { for (int x = 0; x < gridTiles.GetLength(0); x++) { Vector2 rectMins = new Vector2(screenMiddle.x - gridTiles.GetLength(0) / 2.0f * tileSize + x * tileSize + x * 5, screenMiddle.y - gridTiles.GetLength(1) / 2.0f * tileSize + y * tileSize + y * 5); Rect tileRect = new Rect(rectMins, tileSizeVector); if (gridTiles[x, y].GetMaterialTexture() != null) { EditorGUI.DrawPreviewTexture(tileRect, gridTiles[x, y].GetMaterialTexture()); } else { EditorGUI.DrawRect(tileRect, gridTiles[x, y].GetMaterial().GetColor("_MainColor")); } EditorGUI.LabelField(new Rect(rectMins - new Vector2(0, 15), tileSizeVector), gridTiles[x, y].GetTileType().ToString(), textCenteringStyle); if (!gridTiles[x, y].IsWalkable()) { EditorGUI.DrawRect(new Rect(rectMins + new Vector2(tileSize * 0.4f, tileSize * 0.7f), tileSizeVector * 0.2f), Color.red); } if (gridTiles[x, y].GetCeiling().GetHeight() > 0) { EditorGUI.DrawRect(new Rect(rectMins + new Vector2(tileSize * 0.4f, tileSize * 0.2f), tileSizeVector * 0.2f), Color.blue); } tileAreas.Add(tileRect); #region DrawWalls //*/ DrawWall(new Rect(rectMins + new Vector2(1, -5), tileSizeVector - new Vector2(1, tileSize * 0.9f)), x, wallY); DrawWall(new Rect(rectMins + new Vector2(-5, 1), tileSizeVector - new Vector2(tileSize * 0.9f, 1)), x, wallY + 1); if (x == gridTiles.GetLength(0) - 1) { DrawWall(new Rect(rectMins + new Vector2(tileSize, 1), tileSizeVector - new Vector2(tileSize * 0.9f, 1)), x + 1, wallY + 1); } if (y == gridTiles.GetLength(1) - 1) { DrawWall(new Rect(rectMins + new Vector2(1, tileSize), tileSizeVector - new Vector2(1, tileSize * 0.9f)), x, wallY + 2); } //*/ #endregion } wallY += 2; } // Return to options menu if (_reset) { ReturnToGridOptions(); } }