/// <summary> /// Create the terrain defined by these settings /// </summary> public void CreateTerrain() { Terrain[,] world; //Update the session GaiaSessionManager sessionMgr = GaiaSessionManager.GetSessionManager(); if (sessionMgr != null && sessionMgr.IsLocked() != true) { //Update terrain settings in session sessionMgr.m_session.m_terrainWidth = m_tilesX * m_terrainSize; sessionMgr.m_session.m_terrainDepth = m_tilesZ * m_terrainSize; sessionMgr.m_session.m_terrainHeight = m_terrainHeight; sessionMgr.AddDefaults(this); sessionMgr.SetSeaLevel(m_seaLevel); //Then add the operation GaiaOperation op = new GaiaOperation(); op.m_description = "Creating terrain"; op.m_generatedByID = m_defaultsID; op.m_generatedByName = this.name; op.m_generatedByType = this.GetType().ToString(); op.m_isActive = true; op.m_operationDateTime = DateTime.Now.ToString(); op.m_operationType = GaiaOperation.OperationType.CreateTerrain; sessionMgr.AddOperation(op); } //Create the terrains array world = new Terrain[m_tilesX, m_tilesZ]; //And iterate through and create each terrain for (int x = 0; x < m_tilesX; x++) { for (int z = 0; z < m_tilesZ; z++) { CreateTile(x, z, ref world, null); } } //Now join them together and remove their seams RemoveWorldSeams(ref world); }
public GaiaOperation GetTerrainCreationOperation(GaiaResource resources) { //Then add the operation GaiaOperation op = new GaiaOperation(); op.m_description = "Creating terrain"; op.m_generatedByID = m_defaultsID; op.m_generatedByName = this.name; op.m_generatedByType = this.GetType().ToString(); op.m_isActive = true; op.m_operationDateTime = DateTime.Now.ToString(); op.m_operationType = GaiaOperation.OperationType.CreateTerrain; #if UNITY_EDITOR op.m_operationDataJson = new string[2]; string ap = AssetDatabase.GetAssetPath(this); if (string.IsNullOrEmpty(ap)) { op.m_operationDataJson[0] = "GaiaDefaults.asset"; } else { op.m_operationDataJson[0] = AssetDatabase.GetAssetPath(this); } ap = AssetDatabase.GetAssetPath(resources); if (string.IsNullOrEmpty(ap)) { op.m_operationDataJson[1] = "GaiaResources.asset"; } else { op.m_operationDataJson[1] = AssetDatabase.GetAssetPath(resources); } #endif return(op); }
/// <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(); }
private void DrawOperations(bool helpEnabled) { if (m_manager.m_session == null) { return; } if (m_manager.m_session.m_operations.Count > 0) { GUILayout.BeginHorizontal(); GUILayout.Space(8); bool oldSelectAll = m_manager.m_selectAllOperations; m_manager.m_selectAllOperations = m_editorUtils.Toggle(m_manager.m_selectAllOperations, m_editorUtils.GetContent("SelectAllToolTip")); if (m_manager.m_selectAllOperations != oldSelectAll) { foreach (GaiaOperation op in m_manager.m_session.m_operations) { op.m_isActive = m_manager.m_selectAllOperations; } } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); } else { GUILayout.BeginHorizontal(); GUILayout.Space(50); GUILayout.FlexibleSpace(); m_editorUtils.Text("NoOperationsYet"); GUILayout.FlexibleSpace(); GUILayout.Space(50); GUILayout.EndHorizontal(); } //Extra indent needed to draw the foldouts in the correct position EditorGUI.indentLevel++; bool currentGUIState = GUI.enabled; for (int i = 0; i < m_manager.m_session.m_operations.Count; i++) { GaiaOperation op = m_manager.m_session.m_operations[i]; GUIStyle headerStyle = m_operationCreateWorldStyle; switch (op.m_operationType) { case GaiaOperation.OperationType.CreateWorld: headerStyle = m_operationCreateWorldStyle; break; case GaiaOperation.OperationType.ClearSpawns: headerStyle = m_operationClearSpawnsStyle; break; case GaiaOperation.OperationType.FlattenTerrain: headerStyle = m_operationFlattenTerrainStyle; break; case GaiaOperation.OperationType.RemoveNonBiomeResources: headerStyle = m_operationRemoveNonBiomeResourcesStyle; break; case GaiaOperation.OperationType.Spawn: headerStyle = m_operationSpawnStyle; break; case GaiaOperation.OperationType.Stamp: headerStyle = m_operationStampStyle; break; case GaiaOperation.OperationType.StampUndo: headerStyle = m_operationStampUndoRedoStyle; break; case GaiaOperation.OperationType.StampRedo: headerStyle = m_operationStampUndoRedoStyle; break; case GaiaOperation.OperationType.MaskMapExport: headerStyle = m_operationMaskMapExportStyle; break; } GUI.enabled = op.m_isActive; GUILayout.BeginHorizontal(headerStyle); GUI.enabled = currentGUIState; op.m_isActive = GUILayout.Toggle(op.m_isActive, "", m_operationCheckboxStyle); GUI.enabled = op.m_isActive; op.m_isFoldedOut = m_editorUtils.Foldout(op.m_isFoldedOut, new GUIContent((i + 1).ToString() + " " + op.m_description.ToString()), true, m_operationFoldOutStyle); GUILayout.EndHorizontal(); GUI.enabled = currentGUIState; if (op.m_isFoldedOut) { DrawOperationFields(op, m_editorUtils, m_manager, helpEnabled, i); } GUILayout.Space(2); } EditorGUI.indentLevel--; }