//SHOW EDIT //------------------ public void ShowEdit() { //SHOW EDIT GUILayout.BeginVertical("Box", GUILayout.ExpandWidth(false)); EditorGUILayout.HelpBox("Left Click Add / Right Click Remove Cell" + "\n" + "Undo/Redo: Z + Y" + "\n" + "Show/Hide grid: H", MessageType.Info); GUILayout.BeginHorizontal(); GUILayout.Label("Show Grid:"); creator.configuration.ui.showGrid = EditorGUILayout.Toggle(creator.configuration.ui.showGrid); GUILayout.Label("Show Grid on deselect:"); creator.configuration.ui.showGridAlways = EditorGUILayout.Toggle(creator.configuration.ui.showGridAlways); GUILayout.EndHorizontal(); creator.configuration.ui.autoBuild = EditorGUILayout.Toggle("Automatic build:", creator.configuration.ui.autoBuild); //GUILayout.BeginHorizontal(); //creator.brushx2 = EditorGUILayout.Toggle("Brush size x2:", creator.brushx2); //GUILayout.Label("enable recommended"); //GUILayout.EndHorizontal(); creator.configuration.ui.brushSize = EditorGUILayout.IntSlider("Brush size:", creator.configuration.ui.brushSize, 2, 5); creator.configuration.ui.cellColor = EditorGUILayout.ColorField("Cell Color:", creator.configuration.ui.cellColor); creator.configuration.ui.floorCellColor = EditorGUILayout.ColorField("Floor Color:", creator.configuration.ui.floorCellColor); creator.configuration.ui.gridColor = EditorGUILayout.ColorField("Grid Color:", creator.configuration.ui.gridColor); creator.configuration.ui.brushColor = EditorGUILayout.ColorField("Brush Color:", creator.configuration.ui.brushColor); creator.configuration.ui.maskColor = EditorGUILayout.ColorField("Mask Color:", creator.configuration.ui.maskColor); EditorGUILayout.Space(); EditorGUILayout.BeginVertical("Box"); EditorGUILayout.BeginHorizontal(); //fill layer if (GUILayout.Button(iconFillBlock, GUILayout.Width(35), GUILayout.Height(35))) { if (!creator.configuration.worldMap[creator.configuration.ui.mapIndex].paintMask) { creator.FillLayerBlock(); } else { creator.configuration.worldMap[creator.configuration.ui.mapIndex].maskMap = new bool[creator.configuration.global.width, creator.configuration.global.height]; } } if (GUILayout.Button(iconFillFloor, GUILayout.Width(35), GUILayout.Height(35))) { if (!creator.configuration.worldMap[creator.configuration.ui.mapIndex].paintMask) { creator.FillLayerGround(); } else { for (int ym = 0; ym < creator.configuration.worldMap[creator.configuration.ui.mapIndex].maskMap.GetLength(1); ym++) { for (int xm = 0; xm < creator.configuration.worldMap[creator.configuration.ui.mapIndex].maskMap.GetLength(0); xm++) { creator.configuration.worldMap[creator.configuration.ui.mapIndex].maskMap[xm, ym] = true; } } } } //copy / paste layer //copy map from layer if (GUILayout.Button(iconCopyMap, GUILayout.Width(35), GUILayout.Height(35))) { creator.CopyMapFromLayer(); } //paste map to layer if (GUILayout.Button(iconPasteMap, GUILayout.Width(35), GUILayout.Height(35))) { creator.PasteMapToLayer(); } EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); GUILayout.BeginVertical("Box"); GUILayout.BeginHorizontal(); GUILayout.Label(iconLayer, GUILayout.Width(20), GUILayout.Height(20)); GUILayout.Label("Layers"); GUILayout.EndHorizontal(); GUILayout.BeginVertical("TextArea"); //show layers for (int l = creator.configuration.worldMap.Count - 1; l >= 0; l--) { if (creator.configuration.ui.mapIndex == l) { GUI.color = guiBlue; } GUILayout.BeginHorizontal("Box"); GUI.color = Color.white; GUILayout.Label(iconLayer, GUILayout.Width(20), GUILayout.Height(18)); if (GUILayout.Button("Layer: " + (l + 1).ToString(), "Label", GUILayout.Height(18))) { creator.configuration.ui.mapIndex = l; for (int pm = 0; pm < creator.configuration.worldMap.Count; pm++) { creator.configuration.worldMap[pm].paintMask = false; } } creator.configuration.global.layerPresetIndex[l] = EditorGUILayout.Popup(creator.configuration.global.layerPresetIndex[l], creator.configuration.ui.availablePresets); //EditorGUILayout.LayerField(0, GUILayout.Width(50)); //duplicate layer if (GUILayout.Button(iconDuplicate, "ToolbarButton", GUILayout.Height(18), GUILayout.Width(20))) { creator.AddNewLayer(true, false, 0, true, l); } GUI.color = guiRed; if (l != 0) { if (GUILayout.Button("x", "ToolbarButton", GUILayout.Height(18), GUILayout.Width(20))) { creator.RemoveLayer(l); } } GUI.color = Color.white; GUILayout.EndHorizontal(); //Mask Layers if (l < creator.configuration.worldMap.Count) { if (creator.configuration.worldMap[l].useMask) { if (creator.configuration.worldMap[l].paintMask) { GUI.color = guiBluelight; } GUILayout.BeginHorizontal(); GUILayout.Label(iconMaskLayerArrow, GUILayout.Width(20), GUILayout.Height(18)); GUILayout.BeginHorizontal("Box"); GUI.color = Color.white; if (GUILayout.Button("Select", "ToolbarButton", GUILayout.Height(18))) { creator.configuration.ui.mapIndex = l; for (int pm = 0; pm < creator.configuration.worldMap.Count; pm++) { if (pm == creator.configuration.ui.mapIndex) { if (!creator.configuration.worldMap[l].paintMask) { creator.configuration.worldMap[l].paintMask = true; } else { creator.configuration.worldMap[l].paintMask = false; } } else { creator.configuration.worldMap[pm].paintMask = false; } } } GUILayout.Label("Mask: " + (l + 1).ToString()); GUI.color = Color.white; creator.configuration.worldMap[l].selectedMask = EditorGUILayout.Popup(creator.configuration.worldMap[l].selectedMask, _maskNames); if (GUILayout.Button("apply", "ToolbarButton", GUILayout.Height(15), GUILayout.Width(50))) { creator.configuration.worldMap[l].maskMap = new bool[creator.configuration.global.width, creator.configuration.global.height]; creator.configuration.worldMap[l].maskMap = creator.iMasks[creator.configuration.worldMap[l].selectedMask].ApplyMask(creator.configuration.worldMap[l].cellMap, creator.GetComponent <TileWorldCreator>(), creator.configuration); if (creator.firstTimeBuild) { //creator.BuildMapEditor(); creator.BuildMapComplete(false, false, true); } else { if (creator.configuration.global.buildOverlappingTiles) { //creator.BuildMapPartial(true); //creator.BuildMapPartial(false, false, 0, 0); creator.BuildMapPartial(false, false); } else { creator.firstTimeBuild = true; //creator.BuildMapEditor(); creator.BuildMapComplete(false, false, true); } } //update one dim array to make sure they are updated when saving map creator.UpdateMap(); } GUI.color = guiRed; if (GUILayout.Button("x", "ToolbarButton", GUILayout.Height(15), GUILayout.Width(20))) { creator.configuration.worldMap[l].useMask = false; } GUI.color = Color.white; GUILayout.EndHorizontal(); GUILayout.EndHorizontal(); GUILayout.Space(4); } } //GUILayout.Space(6); } GUILayout.Space(6); GUILayout.EndVertical(); GUILayout.BeginHorizontal(); if (GUILayout.Button("Add new layer")) { creator.AddNewLayer(true, false, 0, false, 0); } if (GUILayout.Button("Add mask")) { if (!creator.configuration.worldMap[creator.configuration.ui.mapIndex].useMask) { creator.AddNewMask(creator.configuration.ui.mapIndex); } } GUILayout.EndHorizontal(); GUILayout.EndVertical(); GUILayout.EndVertical(); }
//Initialize Editor public void Init(bool _buildMap) { creator.configuration.ui.autoBuild = true; if (_buildMap) { //use the settings from the tileworldcreator prefab //if this is false we will have to assign new settings like in the //runtime demoscene (new TileWorldCreator.Settings();) //creator.useSettingsFromReference = true; //first generate a new map creator.GenerateMaps(); //assign a new mask map to layers which are using one for (int l = 0; l < creator.configuration.global.layerCount; l++) { if (creator.configuration.worldMap[l].useMask) { creator.AddNewMask(l); } } // Build the map with coroutine set to false, merge false and optimization set to true. creator.BuildMapComplete(false, false, true); //bool array for painted cells cellMap = new bool[creator.configuration.global.width, creator.configuration.global.height]; cellInstancedMap = new bool[creator.configuration.global.width, creator.configuration.global.height]; for (int w = 0; w < creator.configuration.global.width; w++) { for (int h = 0; h < creator.configuration.global.height; h++) { cellMap[w, h] = false; cellInstancedMap[w, h] = false; } } } //setup camera editorCam.transform.position = new Vector3(creator.configuration.global.width / 2 + creator.transform.position.x, 10, creator.configuration.global.height / 2 + creator.transform.position.z); editorCam.transform.rotation = Quaternion.Euler(new Vector3(90, 0, 0)); editorCam.orthographic = true; float _h = ((float)creator.configuration.global.height / 2); float _w = ((float)creator.configuration.global.width / (float)creator.configuration.global.height) * 3; editorCam.orthographicSize = _h + _w; maxDistance = _h + _w; camDistance = maxDistance; if (grid != null) { Destroy(grid.gameObject); } if (cell != null) { Destroy(cell.gameObject); } if (cursor != null) { Destroy(cursor.gameObject); } //setup editor //generate grid plane //matGrid = new Material(Shader.Find("Particles/Additive")); -> does not work in builds, becuase shader will no be included in build matGrid = new Material(mainMaterial); if (showGrid) { matGrid.SetTexture("_MainTex", gridTexture); matGrid.SetColor("_TintColor", gridColorActive); } else { matGrid.SetColor("_TintColor", gridColorDeactive); } grid = GeneratePlane(creator.configuration.global.width, creator.configuration.global.height, matGrid, "grid"); //generate cell plane and material add and material remove //which will be used for the cells //material add cell //matCellAdd = new Material(Shader.Find("Particles/Additive")); matCellAdd = new Material(mainMaterial); matCellAdd.SetColor("_TintColor", cellAddColor); ////material remove cell //matCellRemove = new Material(Shader.Find("Particles/Additive")); matCellRemove = new Material(mainMaterial); matCellRemove.SetColor("_TintColor", cellRemoveColor); cell = GeneratePlane(1, 1, matCellAdd, "cell"); //move cell cell.transform.position = new Vector3(-1000, -1000, -1000); //generate cursor //matCursor = new Material(Shader.Find("Particles/Additive")); matCursor = new Material(mainMaterial); matCursor.SetColor("_TintColor", cursorColor); cursor = GeneratePlane(2, 2, matCursor, "cursor"); mapReady = true; //parent grid, cell and cursor object cell.transform.parent = this.transform; grid.transform.parent = this.transform; cursor.transform.parent = this.transform; this.transform.position = creator.transform.position; //initialize layers and build arrays InitLayers(); }