/// <summary> /// Start function /// </summary> void Start() { #if UNITY_POST_PROCESSING_STACK_V2 transitionPostFX = GameObject.Find("Underwater Transition PostFX").GetComponent <PostProcessVolume>(); underwaterPostFX = GameObject.Find("Underwater PostFX").GetComponent <PostProcessVolume>(); if (Application.isPlaying) { if (transitionPostFX != null) { transitionPostFX.enabled = true; } if (underwaterPostFX != null) { underwaterPostFX.enabled = true; } } else { if (transitionPostFX != null) { transitionPostFX.enabled = false; } if (underwaterPostFX != null) { underwaterPostFX.enabled = false; } } #endif if (m_gaiaSettings == null) { m_gaiaSettings = GaiaUtils.GetGaiaSettings(); } if (m_gaiaSceneInfo == null) { m_gaiaSceneInfo = GaiaSceneInfo.GetSceneInfo(); } if (m_gaiaSettings != null) { m_currentRenderer = m_gaiaSettings.m_currentRenderer; } #if HDPipeline if (m_currentRenderer == GaiaConstants.EnvironmentRenderer.HighDefinition2018x) { GameObject underwaterProbe = GameObject.Find("Underwater Reflection Probe"); if (underwaterProbe != null) { m_underwaterProbe = GameObject.Find("Underwater Reflection Probe").GetComponent <ReflectionProbe>(); } } #endif GameObject waterPlanar = GameObject.Find("Water Planar Reflections"); if (waterPlanar != null) { ReflectionProbe reflection = GameObject.Find("Water Planar Reflections").GetComponent <ReflectionProbe>(); { if (reflection != null) { reflection.mode = UnityEngine.Rendering.ReflectionProbeMode.Custom; } #if HDPipeline HDAdditionalReflectionData reflectionData = GameObject.Find("Water Planar Reflections").GetComponent <HDAdditionalReflectionData>(); if (reflectionData != null) { #if !UNITY_2019_1_OR_NEWER reflectionData.mode = UnityEngine.Rendering.ReflectionProbeMode.Custom; #else reflectionData.mode = ProbeSettings.Mode.Realtime; #endif } #endif } } #if HDPipeline if (m_underwaterProbe != null) { m_underwaterProbe.enabled = false; } #endif mainlight = gameObject.GetComponent <Light>(); mainlight.cookie = null; causticsObject = gameObject.transform; partentObject = GetOrCreateEnvironmentParent().transform; if (m_currentRenderer == GaiaConstants.EnvironmentRenderer.HighDefinition2018x) { #if UNITY_2019_1_OR_NEWER && HDPipeline postVolume = GameObject.Find("Gaia HDRP Post Processing").GetComponent <Volume>(); volume = GameObject.Find("High Definition Environment Volume").GetComponent <Volume>(); if (volume != null) { VolumeProfile profile = volume.sharedProfile; if (profile != null) { VolumetricFog fog; if (profile.TryGet(out fog)) { storedFogColor = fog.albedo.value; storedFogDistance = fog.meanFreePath.value; } } } #endif } else { storedFogColor = RenderSettings.fogColor; storedFogDistance = RenderSettings.fogEndDistance; } ambientAudio = null; if (ambientAudio == null) { ambientAudio = GameObject.Find("Ambient Audio"); } underwaterAudio = null; if (underwaterAudio == null) { underwaterAudio = GameObject.Find("Underwater SoundFX"); } #if UNITY_EDITOR if (player == null) { player = GetThePlayer(); } #endif if (m_gaiaSceneInfo != null) { m_sealevel = m_gaiaSceneInfo.m_seaLevel; } if (m_useHorizonFix) { horizonObject = GameObject.Find("Ambient Underwater Horizon"); if (horizonObjectStored != null) { horizonObject = Instantiate(horizonObjectStored); horizonObject.name = "Ambient Underwater Horizon"; if (partentObject != null) { horizonObject.transform.parent = partentObject; } MeshRenderer[] theRenders = horizonObject.GetComponentsInChildren <MeshRenderer>(); foreach (MeshRenderer rends in theRenders) { rends.enabled = false; } } } if (m_useUnderwaterparticles) { underwaterParticles = GameObject.Find("Underwater Particles Effects"); if (underwaterParticlesStored != null) { underwaterParticles = Instantiate(underwaterParticlesStored); underwaterParticles.name = "Underwater Particles Effects"; underwaterParticles.SetActive(false); if (partentObject != null) { underwaterParticles.transform.parent = partentObject; } } } if (gameObject.GetComponent <AudioSource>() == null) { gameObject.AddComponent <AudioSource>(); objectAudioSource = gameObject.GetComponent <AudioSource>(); objectAudioSource.volume = m_waterSubmergeSounfFXVolume; } else { objectAudioSource = gameObject.GetComponent <AudioSource>(); objectAudioSource.volume = m_waterSubmergeSounfFXVolume; } if (mainlight.type == LightType.Directional) { mainlight.cookieSize = m_causticsSize; } StopAllCoroutines(); }
/// <summary> /// On Enable /// </summary> private void OnEnable() { #if UNITY_EDITOR m_gaiaSettings = GaiaUtils.GetGaiaSettings(); m_gaiaSceneInfo = GaiaSceneInfo.GetSceneInfo(); if (m_gaiaSettings != null) { m_currentRenderer = m_gaiaSettings.m_currentRenderer; } #if UNITY_POST_PROCESSING_STACK_V2 transitionPostFX = GameObject.Find("Underwater Transition PostFX").GetComponent <PostProcessVolume>(); underwaterPostFX = GameObject.Find("Underwater PostFX").GetComponent <PostProcessVolume>(); if (Application.isPlaying) { transitionPostFX = GameObject.Find("Underwater Transition PostFX").GetComponent <PostProcessVolume>(); if (transitionPostFX != null) { transitionPostFX.enabled = true; } underwaterPostFX = GameObject.Find("Underwater PostFX").GetComponent <PostProcessVolume>(); if (underwaterPostFX != null) { underwaterPostFX.enabled = true; } } else { transitionPostFX = GameObject.Find("Underwater Transition PostFX").GetComponent <PostProcessVolume>(); if (transitionPostFX != null) { transitionPostFX.enabled = false; } underwaterPostFX = GameObject.Find("Underwater PostFX").GetComponent <PostProcessVolume>(); if (underwaterPostFX != null) { underwaterPostFX.enabled = false; } } #endif #if UNITY_2019_1_OR_NEWER && HDPipeline if (m_currentRenderer == GaiaConstants.EnvironmentRenderer.HighDefinition2018x) { if (m_aboveWaterProfile == null) { m_aboveWaterProfile = AssetDatabase.LoadAssetAtPath <VolumeProfile>(GaiaPipelineUtils.GetAssetPath("Gaia HDRP Post Processing Profile")); } if (m_underwaterProfile == null) { m_underwaterProfile = AssetDatabase.LoadAssetAtPath <VolumeProfile>(GaiaPipelineUtils.GetAssetPath("Gaia HDRP Underwater Post Processing Profile")); } } #endif #endif }
/// <summary> /// Returns the Gaia User Stamp directory. Will create it if it does not exist. /// </summary> /// <returns>The path to the Gaia Stamps directory</returns> public static string GetUserStampDirectory() { GaiaSettings gaiaSettings = GaiaUtils.GetGaiaSettings(); return(CreatePathIfDoesNotExist(gaiaSettings.m_userStampsDirectory)); }
/// <summary> /// On Enable /// </summary> private void OnEnable() { #if UNITY_EDITOR m_gaiaSettings = GaiaUtils.GetGaiaSettings(); m_gaiaSceneInfo = GaiaSceneInfo.GetSceneInfo(); if (m_gaiaSettings != null) { m_currentRenderer = m_gaiaSettings.m_currentRenderer; } #if UNITY_POST_PROCESSING_STACK_V2 transitionPostFX = GameObject.Find("Underwater Transition PostFX").GetComponent <PostProcessVolume>(); underwaterPostFX = GameObject.Find("Underwater PostFX").GetComponent <PostProcessVolume>(); if (Application.isPlaying) { transitionPostFX = GameObject.Find("Underwater Transition PostFX").GetComponent <PostProcessVolume>(); if (transitionPostFX != null) { transitionPostFX.enabled = true; } underwaterPostFX = GameObject.Find("Underwater PostFX").GetComponent <PostProcessVolume>(); if (underwaterPostFX != null) { underwaterPostFX.enabled = true; } } else { transitionPostFX = GameObject.Find("Underwater Transition PostFX").GetComponent <PostProcessVolume>(); if (transitionPostFX != null) { transitionPostFX.enabled = false; } underwaterPostFX = GameObject.Find("Underwater PostFX").GetComponent <PostProcessVolume>(); if (underwaterPostFX != null) { underwaterPostFX.enabled = false; } } #endif #if UNITY_2019_1_OR_NEWER && HDPipeline if (m_currentRenderer == GaiaConstants.EnvironmentRenderer.HighDefinition2018x) { if (m_aboveWaterProfile == null) { m_aboveWaterProfile = AssetDatabase.LoadAssetAtPath <VolumeProfile>(GaiaPipelineUtils.GetAssetPath("Gaia HDRP Post Processing Profile")); } if (m_underwaterProfile == null) { m_underwaterProfile = AssetDatabase.LoadAssetAtPath <VolumeProfile>(GaiaPipelineUtils.GetAssetPath("Gaia HDRP Underwater Post Processing Profile")); } } #endif #endif if (m_currentRenderer == GaiaConstants.EnvironmentRenderer.HighDefinition2018x) { GameObject volumeObject = GameObject.Find("High Definition Environment Volume"); if (volumeObject != null) { #if !UNITY_2019_1_OR_NEWER && HDPipeline if (volume == null) { volume = GameObject.Find("High Definition Environment Volume").GetComponent <Volume>(); if (volume != null) { VolumeProfile profile = volume.sharedProfile; if (profile != null) { VolumetricFog fog; if (profile.TryGet(out fog)) { storedFogColor = fog.albedo.value; storedFogDistance = fog.meanFreePath.value; } } } } #endif } else { Debug.LogWarning("Unabled to find a HDRP environment volume in the scene. Please insure one is set in this scene."); } } #if UNITY_2019_1_OR_NEWER && HDPipeline postVolume = GameObject.Find("Gaia HDRP Post Processing").GetComponent <Volume>(); #endif }
public static void ShowWorldMapStampSpawner() { Terrain worldMapTerrain = TerrainHelper.GetWorldMapTerrain(); if (worldMapTerrain == null) { Debug.LogError("No world map created yet! Please create a world map first before opening the random terrain generator"); return; } GaiaSessionManager gsm = GaiaSessionManager.GetSessionManager(false); //Get the Gaia Settings GaiaSettings settings = GaiaUtils.GetGaiaSettings(); //Create or find the stamper GameObject spawnerObj = GaiaUtils.GetOrCreateWorldDesigner(); Spawner spawner = spawnerObj.GetComponent <WorldDesigner>(); if (spawner == null) { spawner = spawnerObj.AddComponent <WorldDesigner>(); if (settings != null) { if (settings.m_defaultStampSpawnSettings != null) { spawner.LoadSettings(settings.m_defaultStampSpawnSettings); } } spawner.m_settings.m_isWorldmapSpawner = true; spawner.m_worldMapTerrain = worldMapTerrain; //set up the export settings with the current Gaia Settings / defaults spawner.m_worldCreationSettings.m_targeSizePreset = settings.m_targeSizePreset; spawner.m_worldCreationSettings.m_xTiles = settings.m_tilesX; spawner.m_worldCreationSettings.m_zTiles = settings.m_tilesZ; spawner.m_worldTileSize = GaiaUtils.IntToEnvironmentSize(settings.m_currentDefaults.m_terrainSize); spawner.m_worldCreationSettings.m_tileSize = settings.m_currentDefaults.m_terrainSize; spawner.m_worldCreationSettings.m_tileHeight = settings.m_currentDefaults.m_terrainHeight; spawner.m_worldCreationSettings.m_createInScene = settings.m_createTerrainScenes; spawner.m_worldCreationSettings.m_autoUnloadScenes = settings.m_unloadTerrainScenes; spawner.m_worldCreationSettings.m_applyFloatingPointFix = settings.m_floatingPointFix; spawner.m_worldCreationSettings.m_qualityPreset = settings.m_currentEnvironment; if (spawner.m_worldCreationSettings.m_gaiaDefaults == null) { spawner.m_worldCreationSettings.m_gaiaDefaults = settings.m_currentDefaults; } spawner.StoreWorldSize(); //spawner.StoreHeightmapResolution(); //Check if we do have an existing terrain already, if yes, we would want to re-use it for the world map -> terrain export if (GaiaUtils.HasTerrains()) { spawner.m_useExistingTerrainForWorldMapExport = true; } else { //No terrains yet - set up the terrain tiles in the session according to the current world creation settings //so that the stamp previews will come out right. TerrainLoaderManager.Instance.TerrainSceneStorage.m_terrainTilesX = settings.m_tilesX; TerrainLoaderManager.Instance.TerrainSceneStorage.m_terrainTilesZ = settings.m_tilesZ; } spawner.FitToTerrain(); spawner.UpdateMinMaxHeight(); } else { spawner.m_settings.m_isWorldmapSpawner = true; spawner.m_worldMapTerrain = worldMapTerrain; spawner.FitToTerrain(); spawner.UpdateMinMaxHeight(); } gsm.m_session.m_worldBiomeMaskSettings = spawner.m_settings; TerrainLoaderManager.Instance.SwitchToWorldMap(); #if UNITY_EDITOR Selection.activeGameObject = spawnerObj; #endif }
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); }
private void SimpleLayerCulling(bool helpEnabled) { EditorGUI.BeginChangeCheck(); m_simpleCameraLayerCulling.m_applyToGameCamera = m_editorUtils.Toggle("ApplyToGameCamera", m_simpleCameraLayerCulling.m_applyToGameCamera); m_simpleCameraLayerCulling.m_applyToSceneCamera = m_editorUtils.Toggle("ApplyToSceneCamera", m_simpleCameraLayerCulling.m_applyToSceneCamera); if (m_simpleCameraLayerCulling.m_profile != null) { EditorGUILayout.Space(); m_editorUtils.LabelField("ObjectCullingSettings", EditorStyles.boldLabel); EditorGUI.indentLevel++; m_editorUtils.InlineHelp("ObjectCullingSettings", helpEnabled); for (int i = 0; i < m_simpleCameraLayerCulling.m_profile.m_layerDistances.Length; i++) { string layerName = LayerMask.LayerToName(i); if (!string.IsNullOrEmpty(layerName)) { m_simpleCameraLayerCulling.m_profile.m_layerDistances[i] = EditorGUILayout.FloatField(string.Format("[{0}] {1}", i, layerName), m_simpleCameraLayerCulling.m_profile.m_layerDistances[i]); } } EditorGUI.indentLevel--; if (m_editorUtils.Button("RevertCullingToDefaults")) { GaiaSettings gaiaSettings = GaiaUtils.GetGaiaSettings(); m_simpleCameraLayerCulling.m_profile.UpdateCulling(gaiaSettings); EditorUtility.SetDirty(m_simpleCameraLayerCulling.m_profile); } EditorGUILayout.Space(); m_editorUtils.LabelField("ShadowCullingSettings", EditorStyles.boldLabel); EditorGUI.indentLevel++; m_editorUtils.InlineHelp("ShadowCullingSettings", helpEnabled); for (int i = 0; i < m_simpleCameraLayerCulling.m_profile.m_shadowLayerDistances.Length; i++) { string layerName = LayerMask.LayerToName(i); if (!string.IsNullOrEmpty(layerName)) { m_simpleCameraLayerCulling.m_profile.m_shadowLayerDistances[i] = EditorGUILayout.FloatField(string.Format("[{0}] {1}", i, layerName), m_simpleCameraLayerCulling.m_profile.m_shadowLayerDistances[i]); } } EditorGUI.indentLevel--; if (m_editorUtils.Button("RevertShadowToDefaults")) { m_simpleCameraLayerCulling.m_profile.UpdateShadow(); EditorUtility.SetDirty(m_simpleCameraLayerCulling.m_profile); } EditorGUI.indentLevel--; } if (EditorGUI.EndChangeCheck()) { EditorUtility.SetDirty(m_simpleCameraLayerCulling); ApplyToSceneCamera(); m_simpleCameraLayerCulling.ApplyToGameCamera(); m_simpleCameraLayerCulling.ResetDirectionalLight(); SceneView.RepaintAll(); } }