public override void OnInspectorGUI() { //Initialization m_editorUtils.Initialize(); // Do not remove this! if (m_profile != null) { //Monitor for changes EditorGUI.BeginChangeCheck(); if (m_gaiaSettings == null) { m_gaiaSettings = GaiaUtils.GetGaiaSettings(); } m_editorUtils.Panel("GlobalSettings", GlobalSettings, false, true, true); //Check for changes, make undo record, make changes and let editor know we are dirty if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(m_profile, "Made changes"); EditorUtility.SetDirty(m_profile); } } else { if (GaiaGlobal.Instance != null) { m_profile = GaiaGlobal.Instance.SceneProfile; } } }
public void OnEnable() { //Get Gaia Lighting Profile object m_profile = (GaiaLightingProfile)target; if (m_editorUtils == null) { // Get editor utils for this m_editorUtils = PWApp.GetEditorUtils(this); } if (m_gaiaSettings == null) { m_gaiaSettings = GaiaUtils.GetGaiaSettings(); } m_renderPipeline = m_gaiaSettings.m_pipelineProfile.m_activePipelineInstalled; m_version = PWApp.CONF.Version; if (m_profile != null) { m_profileValues = m_profile.m_lightingProfiles[m_profile.m_selectedLightingProfileValuesIndex]; } enableEditMode = System.IO.Directory.Exists(GaiaUtils.GetAssetPath("Dev Utilities")); }
public void OnWorldMapCreate() { m_worldMapTerrain = TerrainHelper.GetWorldMapTerrain(); GaiaSettings gaiaSettings = GaiaUtils.GetGaiaSettings(); GaiaDefaults currentDefaults = gaiaSettings.m_currentDefaults; TerrainLoaderManager.Instance.TerrainSceneStorage.m_hasWorldMap = true; float worldheightmapRes = m_worldMapTerrain.terrainData.heightmapResolution / m_worldMapTerrain.terrainData.size.x; BoundsDouble bounds = new BoundsDouble(); TerrainHelper.GetTerrainBounds(ref bounds); if (bounds.size.x > 0) { TerrainLoaderManager.Instance.TerrainSceneStorage.m_worldMaprelativeSize = (float)m_currentWorldCreationSettings.m_tileSize / (float)bounds.size.x; TerrainLoaderManager.Instance.TerrainSceneStorage.m_worldMapRelativeHeightmapPixels = (((float)bounds.size.x / m_localTileSize) * m_localHeightmapRes / m_localHeightmapRes); } else { //no bounds size means no real terrains (yet) - set these parameters according to the current settings/defaults then TerrainLoaderManager.Instance.TerrainSceneStorage.m_worldMaprelativeSize = (float)m_currentWorldCreationSettings.m_tileSize / (gaiaSettings.m_tilesX * currentDefaults.m_terrainSize); TerrainLoaderManager.Instance.TerrainSceneStorage.m_worldMapRelativeHeightmapPixels = ((gaiaSettings.m_tilesX * currentDefaults.m_terrainSize) / currentDefaults.m_terrainSize) * currentDefaults.m_heightmapResolution / currentDefaults.m_heightmapResolution; } SyncLocalMapToWorldMap(); ShowWorldMapStampSpawner(); GaiaSessionManager.OnWorldCreated -= OnWorldMapCreate; }
/// <summary> /// Saves a unity terrain layer as asset file and returns a reference to the newly created Terrain Layerfile. /// </summary> /// <param name="terrainName">The name of the current Gaia terrain (for the filename).</param> /// <param name="layerId">The layer ID of the layer that is to be saved (for the filename).</param> /// <param name="terrainLayer">The terrain layer object to save.</param> /// <returns>Reference to the created TerrainLayer</returns> private static TerrainLayer SaveTerrainLayerAsAsset(string terrainName, string layerId, TerrainLayer terrainLayer) { #if UNITY_EDITOR GaiaSettings gaiaSettings = GaiaUtils.GetGaiaSettings(); if (gaiaSettings.m_currentTerrainLayerStoragePath == "") { Debug.LogError("Current Terrain Layer Storage Path is empty, please check the Gaia Settings file!"); return(null); } Directory.CreateDirectory(gaiaSettings.m_currentTerrainLayerStoragePath); //The combination of terrain name and layer id should be unique enough so that users don't overwrite layers between terrains. string path = gaiaSettings.m_currentTerrainLayerStoragePath + "/" + terrainName + "_" + layerId + ".asset"; AssetDatabase.CreateAsset(terrainLayer, path); AssetDatabase.SaveAssets(); return(AssetDatabase.LoadAssetAtPath <TerrainLayer>(path)); #else Debug.LogError("Runtime Gaia operation is not supported"); return(new TerrainLayer()); #endif }
/// <summary> /// Start setup /// </summary> private void Start() { if (m_gaiaSettings == null) { m_gaiaSettings = GaiaUtils.GetGaiaSettings(); } if (m_planarReflectionProbe == null) { m_planarReflectionProbe = FindObjectOfType <PlanarReflectionProbe>(); } if (m_player == null) { m_player = GetThePlayer(); } if (m_planarReflectionProbe != null) { OptimizePlanarReflections(m_planarReflectionProbe); #if UNITY_2019_1_OR_NEWER m_planarReflectionProbe.RequestRenderNextUpdate(); #else m_planarReflectionProbe.RequestRealtimeRender(); #endif } }
public override void OnInspectorGUI() { if (dropdownGUIStyle == null) { dropdownGUIStyle = new GUIStyle(EditorStyles.popup) { fixedHeight = 16f, margin = new RectOffset(0, 0, 4, 0) }; } if (m_profile != null) { Transform transform = m_profile.gameObject.transform; transform.hideFlags = HideFlags.HideInInspector | HideFlags.NotEditable; if (m_profile.m_mainCamera == null) { m_profile.m_mainCamera = GaiaUtils.GetCamera(); } } //Initialization m_editorUtils.Initialize(); // Do not remove this! if (m_gaiaSettings == null) { m_gaiaSettings = GaiaUtils.GetGaiaSettings(); } m_editorUtils.Panel("GlobalSettings", GlobalSettingsPanel, false, true, true); }
/// <summary> /// Returns the Gaia Session Directory. Will create it if it does not exist. /// </summary> /// <returns>The path to the Gaia Session directory</returns> public static string GetSessionDirectory() { GaiaSettings gaiaSettings = GaiaUtils.GetGaiaSettings(); Directory.CreateDirectory(gaiaSettings.m_sessionsDirectory); return(gaiaSettings.m_sessionsDirectory); }
/// <summary> /// Called when object selected /// </summary> void OnEnable() { //if (m_editorUtils == null) //{ // m_editorUtils = new EditorUtils(this); //} //Get the settings and update tooltips GaiaSettings settings = Gaia.GaiaUtils.GetGaiaSettings(); if (settings != null) { m_showTooltips = settings.m_showTooltips; } m_stamper = (Stamper)target; if (m_stamper != null) { m_stamper.ShowPreview(); } if (Terrain.activeTerrain != false) { float height = Terrain.activeTerrain.terrainData.size.y; float maxWidth = Mathf.Max(Terrain.activeTerrain.terrainData.size.x, Terrain.activeTerrain.terrainData.size.z); m_minX = Terrain.activeTerrain.GetPosition().x - (0.5f * maxWidth); m_maxX = m_minX + (2f * maxWidth); m_minY = Terrain.activeTerrain.GetPosition().y - (height); m_maxY = m_minY + (2f * height); m_minZ = Terrain.activeTerrain.GetPosition().z - (0.5f * maxWidth); m_maxZ = m_minZ + (2f * maxWidth); } StartEditorUpdates(); }
public static void FinalizePlayerObjectEditor(GameObject playerObj, GaiaSettings gaiaSettings) { if (playerObj != null) { playerObj.transform.SetParent(GaiaUtils.GetPlayerObject().transform); #if UNITY_EDITOR //Adjust the scene view to see the camera if (SceneView.lastActiveSceneView != null) { if (gaiaSettings.m_focusPlayerOnSetup) { SceneView.lastActiveSceneView.LookAtDirect(playerObj.transform.position, playerObj.transform.rotation); } } #endif } GaiaSessionManager session = GaiaSessionManager.GetSessionManager(); if (session != null) { if (session.m_session != null) { if (playerObj.transform.position.y < session.m_session.m_seaLevel) { playerObj.transform.position = new Vector3(playerObj.transform.position.x, session.m_session.m_seaLevel + 5f, playerObj.transform.position.z); } } } #if GAIA_PRO_PRESENT //Add the simple terrain culling script, useful in any case if (GaiaUtils.CheckIfSceneProfileExists()) { GaiaGlobal.Instance.SceneProfile.m_terrainCullingEnabled = true; } #endif bool dynamicLoadedTerrains = GaiaUtils.HasDynamicLoadedTerrains(); if (dynamicLoadedTerrains) { #if GAIA_PRO_PRESENT TerrainLoader loader = playerObj.GetComponent <TerrainLoader>(); if (loader == null) { loader = playerObj.AddComponent <TerrainLoader>(); } loader.LoadMode = LoadMode.RuntimeAlways; float tileSize = 512; if (TerrainLoaderManager.Instance.TerrainSceneStorage.m_terrainTilesSize > 0) { tileSize = TerrainLoaderManager.Instance.TerrainSceneStorage.m_terrainTilesSize; } float size = tileSize * 1.25f * 2f; loader.m_loadingBoundsRegular = new BoundsDouble(playerObj.transform.position, new Vector3(size, size, size)); loader.m_loadingBoundsImpostor = new BoundsDouble(playerObj.transform.position, new Vector3(size * 3f, size * 3f, size * 3f)); loader.m_loadingBoundsCollider = new BoundsDouble(playerObj.transform.position, new Vector3(size, size, size)); #endif } }
public static void UpdateSceneSettingsFromProfile() { GaiaSettings GaiaSettings = GaiaUtils.GetGaiaSettings(); if (GaiaSettings != null) { LoadWaterAndLighting(GaiaSettings); } }
private void OnEnable() { //Get Gaia Lighting Profile object m_profile = (GaiaGlobal)target; if (m_editorUtils == null) { // Get editor utils for this m_editorUtils = PWApp.GetEditorUtils(this); } if (m_gaiaSettings == null) { m_gaiaSettings = GaiaUtils.GetGaiaSettings(); } if (m_profile.SceneProfile == null) { m_profile.SceneProfile = ScriptableObject.CreateInstance <SceneProfile>(); } if (m_profile.SceneProfile.m_selectedLightingProfileValuesIndex > m_profile.SceneProfile.m_lightingProfiles.Count - 1) { m_profile.SceneProfile.m_selectedLightingProfileValuesIndex = 1; } if (m_profile.SceneProfile.m_selectedWaterProfileValuesIndex > m_profile.SceneProfile.m_waterProfiles.Count - 1) { m_profile.SceneProfile.m_selectedWaterProfileValuesIndex = 1; } m_profile.SceneProfile.ProfileVersion = PWApp.CONF.Version; #if GAIA_PRO_PRESENT if (ProceduralWorldsGlobalWeather.Instance != null) { LoadSettings(); } #endif if (dropdownGUIStyle == null) { dropdownGUIStyle = new GUIStyle(EditorStyles.popup) { fixedHeight = 16f, margin = new RectOffset(0, 0, 4, 0) }; } if (m_profile.SceneProfile.m_lightingProfiles.Count > 0) { if (m_profile.SceneProfile.m_selectedLightingProfileValuesIndex != -99) { GaiaLightingProfileValues profileValues = m_profile.SceneProfile.m_lightingProfiles[m_profile.SceneProfile.m_selectedLightingProfileValuesIndex]; GaiaSceneManagement.FetchSceneSettigns(m_profile.SceneProfile, profileValues); } } }
public void UpdateCulling(GaiaSettings gaiaSettings) { if (!GaiaUtils.CheckIfSceneProfileExists()) { return; } if (GaiaGlobal.Instance.m_mainCamera == null) { GaiaGlobal.Instance.m_mainCamera = GaiaUtils.GetCamera(); } float farClipPlane = 2000f; if (GaiaGlobal.Instance.m_mainCamera != null) { farClipPlane = GaiaGlobal.Instance.m_mainCamera.farClipPlane; } if (GaiaGlobal.Instance.SceneProfile.m_sunLight == null) { GaiaGlobal.Instance.SceneProfile.m_sunLight = GaiaUtils.GetMainDirectionalLight(); } Terrain terrain = TerrainHelper.GetActiveTerrain(); //Objects m_layerDistances = new float[32]; for (int i = 0; i < m_layerDistances.Length; i++) { string layerName = LayerMask.LayerToName(i); switch (layerName) { case "Default": case "Water": case "PW_VFX": m_layerDistances[i] = 0f; break; case "PW_Object_Small": m_layerDistances[i] = GaiaUtils.CalculateCameraCullingLayerValue(terrain, gaiaSettings.m_currentEnvironment, 5f); break; case "PW_Object_Medium": m_layerDistances[i] = GaiaUtils.CalculateCameraCullingLayerValue(terrain, gaiaSettings.m_currentEnvironment, 3f); break; case "PW_Object_Large": m_layerDistances[i] = GaiaUtils.CalculateCameraCullingLayerValue(terrain, gaiaSettings.m_currentEnvironment); break; default: m_layerDistances[i] = 0f; break; } } }
/// <summary> /// Create Gaia Culling System Profile asset /// </summary> #if UNITY_EDITOR public static GaiaSceneCullingProfile CreateCullingProfile() { GaiaSceneCullingProfile asset = ScriptableObject.CreateInstance <GaiaSceneCullingProfile>(); GaiaSettings gaiaSettings = GaiaUtils.GetGaiaSettings(); asset.UpdateCulling(gaiaSettings); asset.UpdateShadow(); AssetDatabase.CreateAsset(asset, "Assets/Gaia Scene Culling Profile.asset"); AssetDatabase.SaveAssets(); return(asset); }
public void Initialize() { if (m_profile == null) { GaiaSettings gaiaSettings = GaiaUtils.GetGaiaSettings(); m_profile = ScriptableObject.CreateInstance <GaiaSceneCullingProfile>(); m_profile.UpdateCulling(gaiaSettings); m_profile.UpdateShadow(); } ApplyToGameCamera(); }
public static void CreateCullingProfileMenu() { GaiaSceneCullingProfile asset = ScriptableObject.CreateInstance <GaiaSceneCullingProfile>(); GaiaSettings gaiaSettings = GaiaUtils.GetGaiaSettings(); asset.UpdateCulling(gaiaSettings); asset.UpdateShadow(); AssetDatabase.CreateAsset(asset, "Assets/Gaia Scene Culling Profile.asset"); AssetDatabase.SaveAssets(); EditorUtility.FocusProjectWindow(); Selection.activeObject = asset; }
void OnEnable() { //Get the settings and update tooltips GaiaSettings settings = Gaia.Utils.GetGaiaSettings(); if (settings != null) { m_showTooltips = settings.m_showTooltips; } //Get our resource m_session = (GaiaSession)target; }
private static void LoadWaterAndLighting(GaiaSettings settings, bool showDebug = false) { if (settings == null) { Debug.LogError("Gaia settings was not found."); return; } if (settings.m_gaiaWaterProfile == null) { Debug.LogError("Water Profile was not found!"); return; } else { Material waterMat = GaiaWater.GetGaiaOceanMaterial(); if (waterMat != null) { GameObject waterObject = GameObject.Find(GaiaConstants.waterSurfaceObject); if (waterObject != null) { GaiaUtils.GetRuntimeSceneObject(); if (GaiaGlobal.Instance != null) { GaiaWater.GetProfile(GaiaGlobal.Instance.SceneProfile.m_selectedWaterProfileValuesIndex, waterMat, GaiaGlobal.Instance.SceneProfile, true, false); } } } } if (settings.m_gaiaLightingProfile == null) { Debug.LogError("Lighting Profile was not found!"); return; } else { GameObject lightObject = GameObject.Find(GaiaConstants.gaiaLightingObject); if (lightObject != null) { if (GaiaGlobal.Instance != null) { GaiaUtils.GetRuntimeSceneObject(); GaiaLighting.GetProfile(GaiaGlobal.Instance.SceneProfile, settings.m_pipelineProfile, settings.m_pipelineProfile.m_activePipelineInstalled); } } } if (showDebug) { Debug.Log("Loading up profile settings successfully"); } }
private static GaiaConstants.EnvironmentControllerType GetCharacterControllerType() { if (m_gaiaSettings == null) { m_gaiaSettings = GaiaUtils.GetGaiaSettings(); } if (m_gaiaSettings != null) { return(m_gaiaSettings.m_currentController); } return(GaiaConstants.EnvironmentControllerType.None); }
public static string GetUserBiomeDirectory(string biomeName = "") { GaiaSettings gaiaSettings = GaiaUtils.GetGaiaSettings(); //If no biome name was passed in, return the path to the root biome user data folder if (biomeName != "") { return(CreatePathIfDoesNotExist(gaiaSettings.m_biomesDirectory + "/" + biomeName.Replace(" Biome", ""))); } else { return(CreatePathIfDoesNotExist(gaiaSettings.m_biomesDirectory)); } }
/// <summary> /// Gets player and returns if found /// </summary> /// <returns>Player</returns> public Transform GetThePlayer() { #if UNITY_EDITOR Transform thePlayer = null; if (m_gaiaSettings == null) { m_gaiaSettings = GaiaUtils.GetGaiaSettings(); } if (m_gaiaSettings.m_currentController == GaiaConstants.EnvironmentControllerType.FirstPerson) { if (GameObject.Find("FirstPersonCharacter") != null) { thePlayer = GameObject.Find("FirstPersonCharacter").transform; if (thePlayer != null) { return(thePlayer); } } } if (m_gaiaSettings.m_currentController == GaiaConstants.EnvironmentControllerType.FlyingCamera) { if (GameObject.Find("FlyCam") != null) { thePlayer = GameObject.Find("FlyCam").transform; if (thePlayer != null) { return(thePlayer); } } } if (m_gaiaSettings.m_currentController == GaiaConstants.EnvironmentControllerType.ThirdPerson) { if (GameObject.Find("Main Camera") != null) { thePlayer = GameObject.Find("Main Camera").transform; if (thePlayer != null) { return(thePlayer); } } } #endif return(null); }
void OnEnable() { //Get or create existing settings object if (m_settings == null) { m_settings = (GaiaSettings)Utils.GetAssetScriptableObject("GaiaSettings"); } //Grab the publisher name if (m_settings != null && !string.IsNullOrEmpty(m_settings.m_publisherName)) { m_publisherName = m_settings.m_publisherName; } }
public void OnEnable() { m_instance = this; WeatherPresent = CheckWeatherPresent(); if (!Application.isPlaying) { if (m_lightingProfile == null) { return; } if (m_waterProfile == null) { return; } if (m_gaiaSettings == null) { m_gaiaSettings = GaiaUtils.GetGaiaSettings(); if (m_gaiaSettings == null) { return; } } } if (m_mainCamera == null) { m_mainCamera = GaiaUtils.GetCamera(); } if (m_sunLight == null) { m_sunLight = GaiaUtils.GetMainDirectionalLight(); } if (m_moonLight == null) { GameObject moonObject = GameObject.Find("Moon Light"); if (moonObject != null) { m_moonLight = moonObject.GetComponent <Light>(); } } UpdateGaiaTimeOfDay(false); CheckPostProcessingFog(true); }
private void OnEnable() { if (instance == null) { instance = this; } else { if (instance != this) { Destroy(this); } } GaiaSettings gaiaSettings = GaiaUtils.GetGaiaSettings(); }
public Transform GetThePlayer() { #if UNITY_EDITOR GaiaSettings settings = AssetDatabase.LoadAssetAtPath <GaiaSettings>(GaiaUtils.GetAssetPath("GaiaSettings.asset")); Transform thePlayer = null; if (settings.m_currentController == GaiaConstants.EnvironmentControllerType.FirstPerson) { if (GameObject.Find("FirstPersonCharacter") != null) { thePlayer = GameObject.Find("FirstPersonCharacter").transform; if (thePlayer != null) { return(thePlayer); } } } if (settings.m_currentController == GaiaConstants.EnvironmentControllerType.FlyingCamera) { if (GameObject.Find("FlyCam") != null) { thePlayer = GameObject.Find("FlyCam").transform; if (thePlayer != null) { return(thePlayer); } } } if (settings.m_currentController == GaiaConstants.EnvironmentControllerType.ThirdPerson) { if (GameObject.Find("Main Camera") != null) { thePlayer = GameObject.Find("Main Camera").transform; if (thePlayer != null) { return(thePlayer); } } } #endif return(null); }
public void OnEnable() { //Get Gaia Lighting Profile object if (GaiaGlobal.Instance != null) { m_profile = GaiaGlobal.Instance.SceneProfile; } if (m_editorUtils == null) { // Get editor utils for this m_editorUtils = PWApp.GetEditorUtils(this); } if (m_gaiaSettings == null) { m_gaiaSettings = GaiaUtils.GetGaiaSettings(); } }
/// <summary> /// Update the terrain tiles to relate properly to each other /// </summary> /// <param name="tiles"></param> private void RemoveWorldSeams(ref Terrain[,] world) { GaiaSettings gaiaSettings = GaiaUtils.GetGaiaSettings(); //Set the neighbours of terrain to remove seams. for (int x = 0; x < gaiaSettings.m_tilesX; x++) { for (int z = 0; z < gaiaSettings.m_tilesZ; z++) { Terrain right = null; Terrain left = null; Terrain bottom = null; Terrain top = null; if (x > 0) { left = world[(x - 1), z]; } if (x < gaiaSettings.m_tilesX - 1) { right = world[(x + 1), z]; } if (z > 0) { bottom = world[x, (z - 1)]; } if (z < gaiaSettings.m_tilesZ - 1) { top = world[x, (z + 1)]; } world[x, z].SetNeighbors(left, top, right, bottom); } } }
/// <summary> /// Create a terrain tile based on these settings /// </summary> /// <param name="tx">X location</param> /// <param name="tz">Z location</param> /// <param name="world">The array managing it</param> private void CreateTile(int tx, int tz, ref Terrain[,] world, GaiaResource resources) { if (tx < 0 || tx >= m_tilesX) { Debug.LogError("X value out of bounds"); return; } if (tz < 0 || tz >= m_tilesZ) { Debug.LogError("Z value out of bounds"); return; } //Look for issues in the terrain settings and fix them GetAndFixDefaults(); //this will center terrain at origin Vector2 m_offset = new Vector2(-m_terrainSize * m_tilesX * 0.5f, -m_terrainSize * m_tilesZ * 0.5f); //create the terrains if they dont already exist if (world.Length < m_tilesX) { world = new Terrain[m_tilesX, m_tilesZ]; } //Create the terrain Terrain terrain; TerrainData terrainData = new TerrainData(); terrainData.name = string.Format("Terrain_{0}_{1}-{2:yyyyMMdd-HHmmss}", tx, tz, DateTime.Now); terrainData.alphamapResolution = m_controlTextureResolution; terrainData.baseMapResolution = m_baseMapSize; terrainData.SetDetailResolution(m_detailResolution, m_detailResolutionPerPatch); terrainData.heightmapResolution = m_heightmapResolution; //terrainData.physicsMaterial = m_physicsMaterial; terrainData.wavingGrassAmount = m_bending; terrainData.wavingGrassSpeed = m_size; terrainData.wavingGrassStrength = m_speed; terrainData.wavingGrassTint = m_grassTint; terrainData.size = new Vector3(m_terrainSize, m_terrainHeight, m_terrainSize); #if UNITY_EDITOR AssetDatabase.CreateAsset(terrainData, string.Format("Assets/{0}.asset", terrainData.name)); #endif terrain = Terrain.CreateTerrainGameObject(terrainData).GetComponent <Terrain>(); terrain.name = terrainData.name; terrain.transform.position = new Vector3(m_terrainSize * tx + m_offset.x, 0, m_terrainSize * tz + m_offset.y); terrain.basemapDistance = m_baseMapDist; #if UNITY_2019_1_OR_NEWER terrain.shadowCastingMode = m_shaodwCastingMode; #else terrain.castShadows = m_castShadows; #endif terrain.detailObjectDensity = m_detailDensity; terrain.detailObjectDistance = m_detailDistance; terrain.heightmapPixelError = m_pixelError; terrain.treeBillboardDistance = m_billboardStart; terrain.treeCrossFadeLength = m_fadeLength; terrain.treeDistance = m_treeDistance; terrain.treeMaximumFullLODCount = m_maxMeshTrees; #if UNITY_EDITOR GameObjectUtility.SetStaticEditorFlags(terrain.gameObject, StaticEditorFlags.BatchingStatic | StaticEditorFlags.NavigationStatic | StaticEditorFlags.OccludeeStatic | StaticEditorFlags.OccluderStatic | StaticEditorFlags.OffMeshLinkGeneration | StaticEditorFlags.ReflectionProbeStatic | StaticEditorFlags.LightmapStatic ); terrain.bakeLightProbesForTrees = false; #if UNITY_2018_3_OR_NEWER terrain.drawInstanced = true; #endif #endif GaiaConstants.EnvironmentRenderer rendererType = GaiaConstants.EnvironmentRenderer.BuiltIn; GaiaSettings gaiaSettings = GaiaUtils.GetGaiaSettings(); if (gaiaSettings != null) { rendererType = gaiaSettings.m_currentRenderer; #if !UNITY_2018_1_OR_NEWER rendererType = GaiaConstants.EnvironmentRenderer.BuiltIn; #endif } if (rendererType == GaiaConstants.EnvironmentRenderer.BuiltIn) { if (m_material != null) { #if UNITY_EDITOR GaiaPipelineUtils.SetupPipeline(rendererType, null, null, null, "Procedural Worlds/Simple Water", false); #endif } } else { terrain.materialType = Terrain.MaterialType.Custom; if (rendererType == GaiaConstants.EnvironmentRenderer.LightWeight2018x) { #if UNITY_EDITOR && UNITY_2018_3_OR_NEWER GaiaPipelineUtils.SetupPipeline(rendererType, "Procedural Worlds Lightweight Pipeline Profile", "Pipeline Terrain Material", "Lightweight Render Pipeline/Terrain/Lit", "Procedural Worlds/Simple Water LW", false); #else Debug.LogWarning("Lightweight Pipeline is only supposted in 2018.3 or newer"); #endif } else { #if UNITY_EDITOR && UNITY_2018_3_OR_NEWER GaiaPipelineUtils.SetupPipeline(rendererType, "Procedural Worlds HDRenderPipelineAsset", "Pipeline Terrain Material", "HDRP/TerrainLit", "Procedural Worlds/Simple Water HD", false); #else Debug.LogWarning("Lightweight Pipeline is only supposted in 2018.3 or newer"); #endif } } if (m_physicsMaterial != null) { TerrainCollider collider = terrain.GetComponent <TerrainCollider>(); if (collider != null) { collider.material = m_physicsMaterial; } else { Debug.LogWarning("Unable to assign physics material to terrain!"); } } //Assign prototypes if (resources != null) { resources.ApplyPrototypesToTerrain(terrain); } else { terrain.Flush(); } //Save the new tile world[tx, tz] = terrain; //Parent it to the environment GameObject gaiaObj = GameObject.Find("Gaia Environment"); if (gaiaObj == null) { gaiaObj = new GameObject("Gaia Environment"); } terrain.transform.parent = gaiaObj.transform; }
/// <summary> /// Create a terrain tile based on these settings /// </summary> /// <param name="tx">X location</param> /// <param name="tz">Z location</param> /// <param name="world">The array managing it</param> private void CreateTile(int tx, int tz, ref Terrain[,] world, GaiaResource resources) { if (tx < 0 || tx >= m_tilesX) { Debug.LogError("X value out of bounds"); return; } if (tz < 0 || tz >= m_tilesZ) { Debug.LogError("Z value out of bounds"); return; } //Look for issues in the terrain settings and fix them GetAndFixDefaults(); //this will center terrain at origin Vector2 m_offset = new Vector2(-m_terrainSize * m_tilesX * 0.5f, -m_terrainSize * m_tilesZ * 0.5f); //create the terrains if they dont already exist if (world.Length < m_tilesX) { world = new Terrain[m_tilesX, m_tilesZ]; } //Create the terrain Terrain terrain; TerrainData terrainData = new TerrainData(); terrainData.name = string.Format("Terrain_{0}_{1}-{2:yyyyMMdd-HHmmss}", tx, tz, DateTime.Now); terrainData.alphamapResolution = m_controlTextureResolution; terrainData.baseMapResolution = m_baseMapSize; terrainData.SetDetailResolution(m_detailResolution, m_detailResolutionPerPatch); terrainData.heightmapResolution = m_heightmapResolution; //terrainData.physicsMaterial = m_physicsMaterial; terrainData.wavingGrassAmount = m_bending; terrainData.wavingGrassSpeed = m_size; terrainData.wavingGrassStrength = m_speed; terrainData.wavingGrassTint = m_grassTint; terrainData.size = new Vector3(m_terrainSize, m_terrainHeight, m_terrainSize); #if UNITY_EDITOR AssetDatabase.CreateAsset(terrainData, string.Format("Assets/{0}.asset", terrainData.name)); #endif terrain = Terrain.CreateTerrainGameObject(terrainData).GetComponent <Terrain>(); terrain.name = terrainData.name; terrain.transform.position = new Vector3(m_terrainSize * tx + m_offset.x, 0, m_terrainSize * tz + m_offset.y); terrain.basemapDistance = m_baseMapDist; terrain.castShadows = m_castShadows; terrain.detailObjectDensity = m_detailDensity; terrain.detailObjectDistance = m_detailDistance; terrain.heightmapPixelError = m_pixelError; terrain.treeBillboardDistance = m_billboardStart; terrain.treeCrossFadeLength = m_fadeLength; terrain.treeDistance = m_treeDistance; terrain.treeMaximumFullLODCount = m_maxMeshTrees; #if UNITY_EDITOR terrain.bakeLightProbesForTrees = false; #endif GaiaConstants.EnvironmentRenderer rendererType = GaiaConstants.EnvironmentRenderer.BuiltIn; GaiaSettings gaiaSettings = Utils.GetGaiaSettings(); if (gaiaSettings != null) { rendererType = gaiaSettings.m_currentRenderer; #if !UNITY_2018_1_OR_NEWER rendererType = GaiaConstants.EnvironmentRenderer.BuiltIn; #endif } if (rendererType == GaiaConstants.EnvironmentRenderer.BuiltIn) { if (m_material != null) { terrain.materialType = Terrain.MaterialType.Custom; terrain.materialTemplate = m_material; } } else { terrain.materialType = Terrain.MaterialType.Custom; if (rendererType == GaiaConstants.EnvironmentRenderer.LightWeight2018x) { Shader terrainShader = Shader.Find("LightweightPipeline/Terrain/Standard Terrain"); Material terrainMaterial = new Material(terrainShader); terrainMaterial.name = "Lightweight-DefaultTerrain"; terrain.materialTemplate = terrainMaterial; } else { Shader terrainShader = Shader.Find("HDRenderPipeline/Terrain/Standard Terrain"); Material terrainMaterial = new Material(terrainShader); terrainMaterial.name = "HDRender-DefaultTerrain"; terrain.materialTemplate = terrainMaterial; } } if (m_physicsMaterial != null) { TerrainCollider collider = terrain.GetComponent <TerrainCollider>(); if (collider != null) { collider.material = m_physicsMaterial; } else { Debug.LogWarning("Unable to assign physics material to terrain!"); } } //Assign prototypes if (resources != null) { resources.ApplyPrototypesToTerrain(terrain); } else { terrain.Flush(); } //Save the new tile world[tx, tz] = terrain; //Parent it to the environment GameObject gaiaObj = GameObject.Find("Gaia Environment"); if (gaiaObj == null) { gaiaObj = new GameObject("Gaia Environment"); } terrain.transform.parent = gaiaObj.transform; }
public void SaveToGaiaDefault(GaiaLightingProfileValues profileValues, ProceduralWorldsGlobalWeather globalWeather) { if (profileValues == null) { return; } GaiaLightingProfileValues newProfileValues = new GaiaLightingProfileValues(); GaiaUtils.CopyFields(profileValues, newProfileValues); newProfileValues.m_userCustomProfile = false; #if UNITY_POST_PROCESSING_STACK_V2 newProfileValues.PostProcessProfileBuiltIn = profileValues.PostProcessProfileBuiltIn; newProfileValues.m_postProcessingProfileGUIDBuiltIn = profileValues.m_postProcessingProfileGUIDBuiltIn; #endif #if UPPipeline newProfileValues.PostProcessProfileURP = profileValues.PostProcessProfileURP; newProfileValues.m_postProcessingProfileGUIDURP = profileValues.m_postProcessingProfileGUIDURP; #endif #if HDPipeline newProfileValues.PostProcessProfileHDRP = profileValues.PostProcessProfileHDRP; newProfileValues.m_postProcessingProfileGUIDHDRP = profileValues.m_postProcessingProfileGUIDHDRP; newProfileValues.EnvironmentProfileHDRP = profileValues.EnvironmentProfileHDRP; newProfileValues.m_environmentProfileGUIDHDRP = profileValues.m_environmentProfileGUIDHDRP; #endif GaiaSettings gaiaSettings = GaiaUtils.GetGaiaSettings(); if (gaiaSettings != null) { GaiaLightingProfile lightingProfile = gaiaSettings.m_gaiaLightingProfile; if (lightingProfile != null) { bool addProfile = true; int indexForReplacement = 0; for (int i = 0; i < lightingProfile.m_lightingProfiles.Count; i++) { if (lightingProfile.m_lightingProfiles[i].m_typeOfLighting == newProfileValues.m_typeOfLighting) { addProfile = false; indexForReplacement = i; } } if (addProfile) { SavePWSkyAtmosphere(newProfileValues, globalWeather); SavePWSeason(newProfileValues, globalWeather); SavePWSkyCloud(newProfileValues, globalWeather); SavePWSkyWeather(newProfileValues, globalWeather); SavePWSkyWind(newProfileValues, globalWeather); SaveColorAndCubemapFields(newProfileValues, profileValues); lightingProfile.m_lightingProfiles.Add(newProfileValues); } else { #if UNITY_EDITOR if (EditorUtility.DisplayDialog("Profile Already Exists", "This profile " + newProfileValues.m_typeOfLighting + " already exists the the default Gaia lighting profile. Do you want to replace this profile?", "Yes", "No")) { GaiaUtils.CopyFields(newProfileValues, lightingProfile.m_lightingProfiles[indexForReplacement]); SavePWSkyAtmosphere(lightingProfile.m_lightingProfiles[indexForReplacement], globalWeather); SavePWSeason(lightingProfile.m_lightingProfiles[indexForReplacement], globalWeather); SavePWSkyCloud(lightingProfile.m_lightingProfiles[indexForReplacement], globalWeather); SavePWSkyWeather(lightingProfile.m_lightingProfiles[indexForReplacement], globalWeather); SavePWSkyWind(lightingProfile.m_lightingProfiles[indexForReplacement], globalWeather); SaveColorAndCubemapFields(lightingProfile.m_lightingProfiles[indexForReplacement], profileValues); #if UNITY_POST_PROCESSING_STACK_V2 lightingProfile.m_lightingProfiles[indexForReplacement].PostProcessProfileBuiltIn = profileValues.PostProcessProfileBuiltIn; lightingProfile.m_lightingProfiles[indexForReplacement].m_postProcessingProfileGUIDBuiltIn = profileValues.m_postProcessingProfileGUIDBuiltIn; #endif #if UPPipeline lightingProfile.m_lightingProfiles[indexForReplacement].PostProcessProfileURP = profileValues.PostProcessProfileURP; lightingProfile.m_lightingProfiles[indexForReplacement].m_postProcessingProfileGUIDURP = profileValues.m_postProcessingProfileGUIDURP; #endif #if HDPipeline lightingProfile.m_lightingProfiles[indexForReplacement].PostProcessProfileHDRP = profileValues.PostProcessProfileHDRP; lightingProfile.m_lightingProfiles[indexForReplacement].m_postProcessingProfileGUIDHDRP = profileValues.m_postProcessingProfileGUIDHDRP; #endif } #endif } #if UNITY_EDITOR EditorUtility.SetDirty(lightingProfile); #endif Debug.Log("Profile successfully added to the Gaia Lighting Profile. Remember to save your project to save the changes"); } } }
public void SaveToGaiaDefault(GaiaWaterProfileValues profileValues) { if (profileValues == null) { return; } GaiaWaterProfileValues newProfileValues = new GaiaWaterProfileValues(); GaiaUtils.CopyFields(profileValues, newProfileValues); newProfileValues.m_userCustomProfile = false; #if UNITY_POST_PROCESSING_STACK_V2 newProfileValues.PostProcessProfileBuiltIn = profileValues.PostProcessProfileBuiltIn; newProfileValues.m_postProcessingProfileGUIDBuiltIn = profileValues.m_postProcessingProfileGUIDBuiltIn; #endif #if UPPipeline newProfileValues.PostProcessProfileURP = profileValues.PostProcessProfileURP; newProfileValues.m_postProcessingProfileGUIDURP = profileValues.m_postProcessingProfileGUIDURP; #endif #if HDPipeline newProfileValues.PostProcessProfileHDRP = profileValues.PostProcessProfileHDRP; newProfileValues.m_postProcessingProfileGUIDHDRP = profileValues.m_postProcessingProfileGUIDHDRP; #endif GaiaSettings gaiaSettings = GaiaUtils.GetGaiaSettings(); if (gaiaSettings != null) { GaiaWaterProfile waterProfile = gaiaSettings.m_gaiaWaterProfile; if (waterProfile != null) { bool addProfile = true; int indexForReplacement = 0; for (int i = 0; i < waterProfile.m_waterProfiles.Count; i++) { if (waterProfile.m_waterProfiles[i].m_typeOfWater == newProfileValues.m_typeOfWater) { addProfile = false; indexForReplacement = i; } } if (addProfile) { SaveColorAndCubemapFields(newProfileValues, profileValues); waterProfile.m_waterProfiles.Add(newProfileValues); } else { #if UNITY_EDITOR if (EditorUtility.DisplayDialog("Profile Already Exists", "This profile " + newProfileValues.m_typeOfWater + " already exists the the default Gaia water profile. Do you want to replace this profile?", "Yes", "No")) { GaiaUtils.CopyFields(newProfileValues, waterProfile.m_waterProfiles[indexForReplacement]); SaveColorAndCubemapFields(waterProfile.m_waterProfiles[indexForReplacement], profileValues); #if UNITY_POST_PROCESSING_STACK_V2 waterProfile.m_waterProfiles[indexForReplacement].PostProcessProfileBuiltIn = profileValues.PostProcessProfileBuiltIn; waterProfile.m_waterProfiles[indexForReplacement].m_postProcessingProfileGUIDBuiltIn = profileValues.m_postProcessingProfileGUIDBuiltIn; #endif #if UPPipeline waterProfile.m_waterProfiles[indexForReplacement].PostProcessProfileURP = profileValues.PostProcessProfileURP; waterProfile.m_waterProfiles[indexForReplacement].m_postProcessingProfileGUIDURP = profileValues.m_postProcessingProfileGUIDURP; #endif #if HDPipeline waterProfile.m_waterProfiles[indexForReplacement].PostProcessProfileHDRP = profileValues.PostProcessProfileHDRP; waterProfile.m_waterProfiles[indexForReplacement].m_postProcessingProfileGUIDHDRP = profileValues.m_postProcessingProfileGUIDHDRP; #endif } #endif } #if UNITY_EDITOR EditorUtility.SetDirty(waterProfile); #endif Debug.Log("Profile successfully added to the Gaia Water Profile. Remember to save your project to save the changes"); } } }