/// <summary> /// Create the terrain defined by these settings - and apply the resources to it /// </summary> public void CreateTerrain(GaiaResource resources) { Terrain[,] world; //Update the resouces ny associating them with their assets resources.AssociateAssets(); //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; //Add the defaults sessionMgr.AddDefaults(this); //Set the sea level - but only if it is zero - if not zero then its been deliberately set if (Gaia.GaiaUtils.Math_ApproximatelyEqual(sessionMgr.m_session.m_seaLevel, 0f)) { sessionMgr.SetSeaLevel(m_seaLevel); } //Grab the resources scriptable object sessionMgr.AddResource(resources); //Adjust them if they are different to the defaults resources.ChangeSeaLevel(sessionMgr.m_session.m_seaLevel); //Then add the operation sessionMgr.AddOperation(GetTerrainCreationOperation(resources)); } //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, resources); } } //Now join them together and remove their seams RemoveWorldSeams(ref world); }
public override void OnInspectorGUI() { //Get our resource m_resource = (GaiaResource)target; //Set up the box style if (m_boxStyle == null) { m_boxStyle = new GUIStyle(GUI.skin.box); m_boxStyle.normal.textColor = GUI.skin.label.normal.textColor; m_boxStyle.fontStyle = FontStyle.Bold; m_boxStyle.alignment = TextAnchor.UpperLeft; } //Setup the wrap style if (m_wrapStyle == null) { m_wrapStyle = new GUIStyle(GUI.skin.label); m_wrapStyle.wordWrap = true; } //Create a nice text intro GUILayout.BeginVertical("Gaia Resource", m_boxStyle); GUILayout.Space(20); //EditorGUILayout.LabelField("The resource manager allows you to manage the resources used by your terrain and spawner. To see what every setting does you can hover over it.\n\nGet From Terrain - Pick up resources and settings from the current terrain.\n\nUpdate DNA - Updates DNA for all resources and automatically calculate sizes.\n\nApply To Terrain - Apply terrain specific settings such as texture, detail and tree prototypes back into the terrain. Prefab this settings to save time creating your next terrain.", m_wrapStyle); EditorGUILayout.LabelField("These are the resources used by the Spawning & Stamping system. Create a terrain, add textures, details and trees, then press Get Resources From Terrain to load. To see how the settings influence the system you can hover over them.", m_wrapStyle); GUILayout.EndVertical(); float oldSeaLevel = m_resource.m_seaLevel; float oldHeight = m_resource.m_terrainHeight; EditorGUI.BeginChangeCheck(); DrawDefaultInspector(); DropAreaGUI(); GUILayout.BeginVertical("Resource Controller", m_boxStyle); GUILayout.Space(20); if (GUILayout.Button(GetLabel("Set Asset Associations"))) { if (EditorUtility.DisplayDialog("Set Asset Associations", "This will update your asset associations and can not be undone ! Here temporarily until hidden.", "Yes", "No")) { if (m_resource.SetAssetAssociations()) { EditorUtility.SetDirty(m_resource); } } } if (GUILayout.Button(GetLabel("Associate Assets"))) { if (EditorUtility.DisplayDialog("Associate Assets", "This will locate and associate the first resource found that matches your asset and can not be undone !", "Yes", "No")) { if (m_resource.AssociateAssets()) { EditorUtility.SetDirty(m_resource); } } } if (GUILayout.Button(GetLabel("Get Resources From Terrain"))) { if (EditorUtility.DisplayDialog("Get Resources from Terrain ?", "Are you sure you want to get / update your resource prototypes from the terrain ? This will update your settings and can not be undone !", "Yes", "No")) { m_resource.UpdatePrototypesFromTerrain(); EditorUtility.SetDirty(m_resource); } } if (GUILayout.Button(GetLabel("Replace Resources In Terrains"))) { if (EditorUtility.DisplayDialog("Replace Resources in ALL Terrains ?", "Are you sure you want to replace the resources in ALL terrains with these? This can not be undone !", "Yes", "No")) { m_resource.ApplyPrototypesToTerrain(); } } if (GUILayout.Button(GetLabel("Add Missing Resources To Terrains"))) { if (EditorUtility.DisplayDialog("Add Missing Resources to ALL Terrains ?", "Are you sure you want to add your missing resource prototypes to ALL terrains ? This can not be undone !", "Yes", "No")) { m_resource.AddMissingPrototypesToTerrain(); } } if (m_resource.m_texturePrototypes.GetLength(0) == 0) { GUI.enabled = false; } if (GUILayout.Button(GetLabel("Create Coverage Texture Spawner"))) { m_resource.CreateCoverageTextureSpawner(GetRangeFromTerrain(), GetTextureIncrementFromTerrain()); } GUI.enabled = true; if (m_resource.m_detailPrototypes.GetLength(0) == 0) { GUI.enabled = false; } if (GUILayout.Button(GetLabel("Create Clustered Grass Spawner"))) { m_resource.CreateClusteredDetailSpawner(GetRangeFromTerrain(), GetDetailIncrementFromTerrain()); } if (GUILayout.Button(GetLabel("Create Coverage Grass Spawner"))) { m_resource.CreateCoverageDetailSpawner(GetRangeFromTerrain(), GetDetailIncrementFromTerrain()); } GUI.enabled = true; if (m_resource.m_treePrototypes.GetLength(0) == 0) { GUI.enabled = false; } if (GUILayout.Button(GetLabel("Create Clustered Terrain Tree Spawner"))) { m_resource.CreateClusteredTreeSpawner(GetRangeFromTerrain()); } if (GUILayout.Button(GetLabel("Create Coverage Terrain Tree Spawner"))) { m_resource.CreateCoverageTreeSpawner(GetRangeFromTerrain()); } GUI.enabled = true; if (m_resource.m_gameObjectPrototypes.GetLength(0) == 0) { GUI.enabled = false; } if (GUILayout.Button(GetLabel("Create Clustered Prefab Spawner"))) { m_resource.CreateClusteredGameObjectSpawner(GetRangeFromTerrain()); } if (GUILayout.Button(GetLabel("Create Coverage Prefab Spawner"))) { m_resource.CreateCoverageGameObjectSpawner(GetRangeFromTerrain()); } GUI.enabled = true; if (GUILayout.Button(GetLabel("Visualise"))) { GameObject gaiaObj = GameObject.Find("Gaia"); if (gaiaObj == null) { gaiaObj = new GameObject("Gaia"); } GameObject visualiserObj = GameObject.Find("Visualiser"); if (visualiserObj == null) { visualiserObj = new GameObject("Visualiser"); visualiserObj.AddComponent <ResourceVisualiser>(); visualiserObj.transform.parent = gaiaObj.transform; } ResourceVisualiser visualiser = visualiserObj.GetComponent <ResourceVisualiser>(); visualiser.m_resources = m_resource; Selection.activeGameObject = visualiserObj; } GUILayout.Space(5f); GUILayout.EndVertical(); //Check for changes, make undo record, make changes and let editor know we are dirty if (EditorGUI.EndChangeCheck()) { if (oldHeight != m_resource.m_terrainHeight) { m_resource.ChangeHeight(oldHeight, m_resource.m_terrainHeight); } if (oldSeaLevel != m_resource.m_seaLevel) { m_resource.ChangeSeaLevel(oldSeaLevel, m_resource.m_seaLevel); } Undo.RecordObject(m_resource, "Made resource changes"); EditorUtility.SetDirty(m_resource); //Stop the save from going nuts if ((DateTime.Now - m_lastSaveDT).Seconds > 5) { m_lastSaveDT = DateTime.Now; AssetDatabase.SaveAssets(); } } }