/// <summary> /// Draws the data fields for each operation /// </summary> /// <param name="op"></param> public static void DrawOperationFields(GaiaOperation op, EditorUtils editorUtils, GaiaSessionManager sessionManager, bool helpEnabled, int currentIndex) { //shared default fields first //op.m_isActive = m_editorUtils.Toggle("Active", op.m_isActive, helpEnabled); bool currentGUIState = GUI.enabled; GUI.enabled = op.m_isActive; op.m_description = editorUtils.TextField("Description", op.m_description, helpEnabled); editorUtils.LabelField("DateTime", new GUIContent(op.m_operationDateTime), helpEnabled); EditorGUI.indentLevel++; op.m_terrainsFoldedOut = editorUtils.Foldout(op.m_terrainsFoldedOut, "AffectedTerrains", helpEnabled); if (op.m_terrainsFoldedOut) { foreach (string name in op.m_affectedTerrainNames) { EditorGUILayout.LabelField(name); } } EditorGUI.indentLevel--; //type specific fields, switch by op type to draw additional fields suitable for the op type switch (op.m_operationType) { case GaiaOperation.OperationType.CreateWorld: editorUtils.LabelField("xTiles", new GUIContent(op.WorldCreationSettings.m_xTiles.ToString()), helpEnabled); editorUtils.LabelField("zTiles", new GUIContent(op.WorldCreationSettings.m_zTiles.ToString()), helpEnabled); editorUtils.LabelField("TileSize", new GUIContent(op.WorldCreationSettings.m_tileSize.ToString()), helpEnabled); break; case GaiaOperation.OperationType.Spawn: editorUtils.LabelField("NumberOfSpawners", new GUIContent(op.SpawnOperationSettings.m_spawnerSettingsList.Count.ToString()), helpEnabled); float size = (float)Mathd.Max(op.SpawnOperationSettings.m_spawnArea.size.x, op.SpawnOperationSettings.m_spawnArea.size.z); editorUtils.LabelField("SpawnSize", new GUIContent(size.ToString()), helpEnabled); break; } GUI.enabled = currentGUIState; //Button controls EditorGUILayout.BeginHorizontal(); GUILayout.Space(20); if (editorUtils.Button("Delete")) { if (EditorUtility.DisplayDialog(editorUtils.GetTextValue("PopupDeleteTitle"), editorUtils.GetTextValue("PopupDeleteText"), editorUtils.GetTextValue("OK"), editorUtils.GetTextValue("Cancel"))) { try { if (!String.IsNullOrEmpty(op.scriptableObjectAssetGUID)) { AssetDatabase.DeleteAsset(AssetDatabase.GUIDToAssetPath(op.scriptableObjectAssetGUID)); } } catch (Exception ex) { Debug.LogError("Error while deleting one of the operation data files: " + ex.Message + " Stack Trace:" + ex.StackTrace); } sessionManager.RemoveOperation(currentIndex); EditorGUIUtility.ExitGUI(); } } GUI.enabled = op.m_isActive; if (editorUtils.Button("Play")) { if (EditorUtility.DisplayDialog(editorUtils.GetTextValue("PopupPlayTitle"), editorUtils.GetTextValue("PopupPlayText"), editorUtils.GetTextValue("OK"), editorUtils.GetTextValue("Cancel"))) { GaiaSessionManager.ExecuteOperation(op); //Destroy all temporary tools used while executing //not if it is a spawn operation since that is asynchronous if (op.m_operationType != GaiaOperation.OperationType.Spawn) { GaiaSessionManager.DestroyTempSessionTools(); } } } GUI.enabled = currentGUIState; //EditorGUILayout.EndHorizontal(); //EditorGUILayout.BeginHorizontal(); //GUILayout.Space(20); if (editorUtils.Button("ViewData")) { switch (op.m_operationType) { case GaiaOperation.OperationType.CreateWorld: Selection.activeObject = op.WorldCreationSettings; break; case GaiaOperation.OperationType.Stamp: Selection.activeObject = op.StamperSettings; break; case GaiaOperation.OperationType.Spawn: Selection.activeObject = op.SpawnOperationSettings; break; case GaiaOperation.OperationType.FlattenTerrain: Selection.activeObject = op.FlattenOperationSettings; break; case GaiaOperation.OperationType.StampUndo: Selection.activeObject = op.UndoRedoOperationSettings; break; case GaiaOperation.OperationType.StampRedo: Selection.activeObject = op.UndoRedoOperationSettings; break; case GaiaOperation.OperationType.ClearSpawns: Selection.activeObject = op.ClearOperationSettings; break; case GaiaOperation.OperationType.RemoveNonBiomeResources: Selection.activeObject = op.RemoveNonBiomeResourcesSettings; break; case GaiaOperation.OperationType.MaskMapExport: Selection.activeObject = op.ExportMaskMapOperationSettings; break; } EditorGUIUtility.PingObject(Selection.activeObject); } switch (op.m_operationType) { case GaiaOperation.OperationType.Stamp: if (editorUtils.Button("PreviewInStamper")) { Stamper stamper = GaiaSessionManager.GetOrCreateSessionStamper(); stamper.LoadSettings(op.StamperSettings); #if GAIA_PRO_PRESENT if (GaiaUtils.HasDynamicLoadedTerrains()) { //We got placeholders, activate terrain loading stamper.m_loadTerrainMode = LoadMode.EditorSelected; } #endif Selection.activeObject = stamper.gameObject; } break; case GaiaOperation.OperationType.Spawn: if (editorUtils.Button("PreviewInSpawner")) { BiomeController bmc = null; List <Spawner> spawnerList = null; Selection.activeObject = GaiaSessionManager.GetOrCreateSessionSpawners(op.SpawnOperationSettings, ref bmc, ref spawnerList); } break; case GaiaOperation.OperationType.MaskMapExport: #if GAIA_PRO_PRESENT if (editorUtils.Button("PreviewInExport")) { MaskMapExport mme = null; Selection.activeObject = GaiaSessionManager.GetOrCreateMaskMapExporter(op.ExportMaskMapOperationSettings.m_maskMapExportSettings, ref mme); } #endif break; } EditorGUILayout.EndHorizontal(); }
public void CreateWorldMapTerrain() { //Remove old world map terrain, if any Terrain oldWMTerrain = TerrainHelper.GetWorldMapTerrain(); if (oldWMTerrain != null) { #if UNITY_EDITOR if (EditorUtility.DisplayDialog("Delete old world map?", "You are about to create a new world map in this scene. This will delete the existing world map and the stamp tokens on it. This will only affect the small world map terrain, the actual full scene terrain tiles will not be removed. Continue?", "Continue", "Cancel")) { DestroyImmediate(oldWMTerrain.gameObject); } else { return; } #else Destroy(oldWMTerrain.gameObject); #endif } GaiaSettings gaiaSettings = GaiaUtils.GetGaiaSettings(); GaiaDefaults currentDefaults = gaiaSettings.m_currentDefaults; GaiaSessionManager gsm = GaiaSessionManager.GetSessionManager(); //Collect some info from the existing world, if any. //We need the average height from the terrains to create the height of the worldmap accordingly in scale double averageHeight = currentDefaults.m_terrainHeight; //We need the heightmap resolution and terrain size stored in the session //To properly scale between world map and local map even when one of the two is not loaded at the moment int count = 0; foreach (Terrain t in Terrain.activeTerrains) { averageHeight += t.terrainData.size.y; if (!TerrainHelper.IsWorldMapTerrain(t)) { m_localHeightmapRes = t.terrainData.heightmapResolution; m_localTileSize = t.terrainData.size.x; } count++; } //} //only calculate an average if there is at least one placeholder or terrain if (count > 0) { averageHeight /= count; } BoundsDouble bounds = new BoundsDouble(); TerrainHelper.GetTerrainBounds(ref bounds); //Collect the new world settings for world creation WorldCreationSettings worldCreationSettings = ScriptableObject.CreateInstance <WorldCreationSettings>(); worldCreationSettings.m_xTiles = 1; worldCreationSettings.m_zTiles = 1; worldCreationSettings.m_tileSize = (count > 0) ? Mathd.RoundToInt(bounds.size.x) : gaiaSettings.m_tilesX * currentDefaults.m_terrainSize; worldCreationSettings.m_tileHeight = currentDefaults.m_terrainHeight; worldCreationSettings.m_createInScene = false; worldCreationSettings.m_autoUnloadScenes = false; worldCreationSettings.m_applyFloatingPointFix = false; worldCreationSettings.m_applyFloatingPointFix = false; worldCreationSettings.m_centerOffset = Vector3.zero; //(count > 0) ? new Vector2Double(bounds.center.x + bounds.extents.x + worldCreationSettings.m_tileSize, bounds.center.z) : Vector2Double.zero; worldCreationSettings.m_isWorldMap = true; //clone defaults so we can inject our custom heightmap resolution for the worldmap GaiaDefaults clonedDefaults = Instantiate(currentDefaults); clonedDefaults.m_heightmapResolution = (int)m_heightmapResolution; worldCreationSettings.m_gaiaDefaults = clonedDefaults; m_currentWorldCreationSettings = worldCreationSettings; GaiaSessionManager.OnWorldCreated -= OnWorldMapCreate; GaiaSessionManager.OnWorldCreated += OnWorldMapCreate; GaiaSessionManager.CreateWorld(worldCreationSettings); }