/// <summary> /// Saves all the settings in all profiles /// </summary> /// <param name="renderPipelineSettings"></param> public void SaveAllDefaults(AmbientSkiesConsts.RenderPipelineSettings renderPipelineSettings) { foreach (AmbientSkyboxProfile skyboxProfile in m_skyProfiles) { skyboxProfile.SaveCurrentToDefault(); } foreach (AmbientProceduralSkyboxProfile proceduralProfile in m_proceduralSkyProfiles) { proceduralProfile.SaveCurrentToDefault(); } foreach (AmbientGradientSkyboxProfile gradientProfile in m_gradientSkyProfiles) { gradientProfile.SaveCurrentToDefault(); } foreach (AmbientPostProcessingProfile processProfile in m_ppProfiles) { processProfile.SaveCurrentToDefault(renderPipelineSettings); } foreach (AmbientLightingProfile lightingProfile in m_lightingProfiles) { lightingProfile.SaveCurrentToDefault(); } Debug.Log("Saved all profiles to defaults successfully"); }
/// <summary> /// Copy settings to defaults /// </summary> /// <param name="profileIdx"></param> public void SavePostProcessingSettingsToDefault(int profileIdx, AmbientSkiesConsts.RenderPipelineSettings renderPipelineSettings) { if (profileIdx >= 0 && profileIdx < m_ppProfiles.Count) { m_ppProfiles[profileIdx].SaveCurrentToDefault(renderPipelineSettings); } }
/// <summary> /// Setup function /// </summary> private void Start() { //Find time of day component in the scene m_timeOfDay = FindObjectOfType <AmbientSkiesTimeOfDay>(); //If time of day component is not null if (m_timeOfDay != null) { //Sets the render pipeline in this system m_renderPipelineSettings = m_timeOfDay.m_timeOfDayProfile.m_renderPipeline; } }
/// <summary> /// Creates a reflection probe at current scene view camera location /// </summary> /// <param name="profile"></param> /// <param name="renderPipelineSettings"></param> public static void CreateProbeAtLocation(AmbientLightingProfile profile, AmbientSkiesConsts.RenderPipelineSettings renderPipelineSettings) { GameObject oldReflectionProbe = GameObject.Find("Global Reflection Probe"); if (oldReflectionProbe != null) { Object.DestroyImmediate(oldReflectionProbe); Debug.Log("Old Reflection Probe Destroyed"); } //Creates the probe GameObject createdProbeObject = new GameObject(profile.reflectionProbeName); //Assign scene view camera Vector3 position = SceneView.lastActiveSceneView.camera.transform.position; if (SceneView.lastActiveSceneView.pivot != position) { //Set position based on scene view camera position createdProbeObject.transform.localPosition = position; } else { Debug.LogWarning("Scene View camera not found, probe spawned at position 0, 0, 0"); } //Parent the probe object GameObject reflectionProbeParent = ReflectionProbeParenting(true); createdProbeObject.transform.SetParent(reflectionProbeParent.transform); //Add probe data ReflectionProbe probeData = createdProbeObject.AddComponent <ReflectionProbe>(); //Configure Probe settings probeData.blendDistance = profile.reflectionProbeBlendDistance; probeData.cullingMask = profile.reflectionprobeCullingMask; probeData.farClipPlane = profile.reflectionProbeClipPlaneDistance; probeData.mode = profile.reflectionProbeMode; probeData.refreshMode = profile.reflectionProbeRefresh; probeData.blendDistance = 5f; switch (profile.reflectionProbeResolution) { case AmbientSkiesConsts.ReflectionProbeResolution.Resolution16: probeData.resolution = 16; break; case AmbientSkiesConsts.ReflectionProbeResolution.Resolution32: probeData.resolution = 32; break; case AmbientSkiesConsts.ReflectionProbeResolution.Resolution64: probeData.resolution = 64; break; case AmbientSkiesConsts.ReflectionProbeResolution.Resolution128: probeData.resolution = 128; break; case AmbientSkiesConsts.ReflectionProbeResolution.Resolution256: probeData.resolution = 256; break; case AmbientSkiesConsts.ReflectionProbeResolution.Resolution512: probeData.resolution = 512; break; case AmbientSkiesConsts.ReflectionProbeResolution.Resolution1024: probeData.resolution = 1024; break; case AmbientSkiesConsts.ReflectionProbeResolution.Resolution2048: probeData.resolution = 2048; break; } probeData.shadowDistance = profile.reflectionProbeShadowDistance; probeData.size = profile.reflectionProbeScale; probeData.timeSlicingMode = profile.reflectionProbeTimeSlicingMode; probeData.hdr = true; probeData.shadowDistance = profile.reflectionProbeShadowDistance; //If HDRP if (renderPipelineSettings == AmbientSkiesConsts.RenderPipelineSettings.HighDefinition) { #if HDPipeline && UNITY_2018_3_OR_NEWER HDAdditionalReflectionData reflectionData = createdProbeObject.GetComponent <HDAdditionalReflectionData>(); if (reflectionData == null) { reflectionData = createdProbeObject.AddComponent <HDAdditionalReflectionData>(); reflectionData.multiplier = 1f; } else { reflectionData.multiplier = 1f; } #endif } m_currentProbeCount++; SceneView.lastActiveSceneView.Repaint(); EditorGUIUtility.PingObject(createdProbeObject); }
/// <summary> /// Setup for the automatically probe spawning /// </summary> /// <param name="profile"></param> public static void CreateAutomaticProbes(AmbientLightingProfile profile, AmbientSkiesConsts.RenderPipelineSettings renderPipelineSettings) { GameObject oldReflectionProbe = GameObject.Find("Global Reflection Probe"); if (oldReflectionProbe != null) { Object.DestroyImmediate(oldReflectionProbe); Debug.Log("Old Reflection Probe Destroyed"); } GameObject relfectionParentObject = ReflectionProbeParenting(true); int numberTerrains = Terrain.activeTerrains.Length; if (numberTerrains == 0) { Debug.LogError("Unable to initiate probe spawning systen. No terrain found"); return; } else { if (profile.reflectionProbesPerRow < 2) { Debug.LogError("Please set Probes Per Row to a value of 2 or higher"); return; } else { m_currentProbeCount = 0; float seaLevel = 0f; bool seaLevelActive = false; #if GAIA_PRESENT Gaia.GaiaSessionManager gaiaSession = Object.FindObjectOfType <Gaia.GaiaSessionManager>(); if (gaiaSession != null) { seaLevel = profile.seaLevel; seaLevelActive = true; } #else seaLevel = profile.seaLevel; #endif for (int terrainIdx = 0; terrainIdx < numberTerrains; terrainIdx++) { Terrain terrain = Terrain.activeTerrains[terrainIdx]; Vector3 terrainSize = terrain.terrainData.size; for (int row = 0; row < profile.reflectionProbesPerRow; ++row) { for (int columns = 0; columns < profile.reflectionProbesPerRow; ++columns) { GameObject probeObject = new GameObject("Global Generated Reflection Probe"); Vector3 newPosition = probeObject.transform.position; newPosition.x = ((columns + 1) * terrainSize.x / profile.reflectionProbesPerRow) - terrainSize.x / profile.reflectionProbesPerRow / 2f + terrain.transform.position.x; newPosition.z = ((row + 1) * terrainSize.z / profile.reflectionProbesPerRow) - terrainSize.z / profile.reflectionProbesPerRow / 2f + terrain.transform.position.z; float sampledHeight = terrain.SampleHeight(newPosition); ReflectionProbe probeData = probeObject.AddComponent <ReflectionProbe>(); probeData.enabled = false; probeData.blendDistance = 0f; probeData.cullingMask = profile.reflectionprobeCullingMask; probeData.farClipPlane = profile.reflectionProbeClipPlaneDistance; probeData.mode = profile.reflectionProbeMode; probeData.refreshMode = profile.reflectionProbeRefresh; if (seaLevelActive) { newPosition.y = 500f + seaLevel + 0.2f; } else { newPosition.y = sampledHeight + profile.reflectionProbeOffset; probeData.center = new Vector3(0f, 0f - profile.reflectionProbeOffset - sampledHeight, 0f); } probeObject.transform.position = newPosition; probeObject.transform.SetParent(relfectionParentObject.transform); switch (profile.reflectionProbeResolution) { case AmbientSkiesConsts.ReflectionProbeResolution.Resolution16: probeData.resolution = 16; break; case AmbientSkiesConsts.ReflectionProbeResolution.Resolution32: probeData.resolution = 32; break; case AmbientSkiesConsts.ReflectionProbeResolution.Resolution64: probeData.resolution = 64; break; case AmbientSkiesConsts.ReflectionProbeResolution.Resolution128: probeData.resolution = 128; break; case AmbientSkiesConsts.ReflectionProbeResolution.Resolution256: probeData.resolution = 256; break; case AmbientSkiesConsts.ReflectionProbeResolution.Resolution512: probeData.resolution = 512; break; case AmbientSkiesConsts.ReflectionProbeResolution.Resolution1024: probeData.resolution = 1024; break; case AmbientSkiesConsts.ReflectionProbeResolution.Resolution2048: probeData.resolution = 2048; break; } probeData.shadowDistance = 80f; probeData.size = new Vector3(terrainSize.x / profile.reflectionProbesPerRow, terrainSize.y, terrainSize.z / profile.reflectionProbesPerRow); probeData.timeSlicingMode = profile.reflectionProbeTimeSlicingMode; probeData.hdr = true; probeData.shadowDistance = profile.reflectionProbeShadowDistance; //If HDRP if (renderPipelineSettings == AmbientSkiesConsts.RenderPipelineSettings.HighDefinition) { #if HDPipeline && UNITY_2018_3_OR_NEWER HDAdditionalReflectionData reflectionData = probeObject.GetComponent <HDAdditionalReflectionData>(); if (reflectionData == null) { reflectionData = probeObject.AddComponent <HDAdditionalReflectionData>(); reflectionData.multiplier = 1f; } else { reflectionData.multiplier = 1f; } #endif } m_storedProbes.Add(probeData); m_currentProbeCount++; } } } #if HDPipeline && GAIA_PRESENT if (seaLevelActive) { GameObject planarObject = GameObject.Find("Gaia Water Planar Reflections Object"); if (planarObject == null) { planarObject = new GameObject("Gaia Water Planar Reflections Object"); PlanarReflectionProbe planar = planarObject.AddComponent <PlanarReflectionProbe>(); planar.mode = ProbeSettings.Mode.Realtime; planar.realtimeMode = ProbeSettings.RealtimeMode.OnEnable; planar.influenceVolume.shape = InfluenceShape.Box; planar.influenceVolume.boxSize = new Vector3(10000f, 5f, 10000f); planarObject.transform.position = new Vector3(0f, profile.seaLevel + 0.2f, 0f); planarObject.transform.SetParent(relfectionParentObject.transform); } } #endif m_probeRenderActive = true; } } }
public override void OnInspectorGUI() { //Initialization //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; } //Get AmientSkiesOrigamiPlugin object AmientSkiesAPI ambientSkiesSettings = (AmientSkiesAPI)target; m_settings = ambientSkiesSettings; m_creationToolSettings = AssetDatabase.LoadAssetAtPath <CreationToolsSettings>(SkyboxUtils.GetAssetPath("Ambient Skies Creation Tool Settings")); //Monitor for changes EditorGUI.BeginChangeCheck(); GUILayout.BeginVertical("Profile Configuration", m_boxStyle); GUILayout.Space(25f); //Load settings LoadAmbientSkiesProfiles(); //Sets scripting define and sets selected pipeline ApplyScriptingDefine(); #region Local Variables //Values List <AmbientSkyProfiles> profileList = ambientSkiesSettings.m_profileList; int newProfileListIndex = ambientSkiesSettings.newProfileListIndex; int profileListIndex = ambientSkiesSettings.m_profileListIndex; int newSkyboxSelection = m_creationToolSettings.m_selectedHDRI; int newProceduralSkyboxSelection = m_creationToolSettings.m_selectedProcedural; int newGradientSkyboxSelection = m_creationToolSettings.m_selectedGradient; int newppSelection = m_creationToolSettings.m_selectedPostProcessing; List <string> profileChoices = ambientSkiesSettings.profileChoices; List <string> skyboxChoices = ambientSkiesSettings.skyboxChoices; List <string> proceduralSkyboxChoices = ambientSkiesSettings.proceduralSkyboxChoices; #if UNITY_2018_3_OR_NEWER List <string> gradientSkyboxChoices = ambientSkiesSettings.gradientSkyboxChoices; #endif List <string> ppChoices = ambientSkiesSettings.ppChoices; List <string> lightmappingChoices = ambientSkiesSettings.lightmappingChoices; AmbientSkyProfiles profiles = ambientSkiesSettings.m_profiles; AmbientSkiesConsts.SystemTypes systemtype = profiles.m_systemTypes; AmbientSkiesConsts.RenderPipelineSettings renderPipelineSettings = ambientSkiesSettings.m_renderPipelineSelected; #endregion #region System selection EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Select System", GUILayout.Width(146f)); newProfileListIndex = EditorGUILayout.Popup(profileListIndex, profileChoices.ToArray(), GUILayout.ExpandWidth(true), GUILayout.Height(16f)); EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); if (newProfileListIndex != profileListIndex) { profileListIndex = newProfileListIndex; profiles = AssetDatabase.LoadAssetAtPath <AmbientSkyProfiles>(SkyboxUtils.GetAssetPath(profileList[profileListIndex].name)); EditorPrefs.SetString("AmbientSkiesActiveProfile_", profileList[profileListIndex].name); m_creationToolSettings.m_selectedSystem = profileListIndex; newSkyboxSelection = 0; newProceduralSkyboxSelection = 0; newGradientSkyboxSelection = 0; #region Load List Profiles //Add skies profile names m_settings.skyboxChoices.Clear(); foreach (var profile in m_settings.m_profiles.m_skyProfiles) { m_settings.skyboxChoices.Add(profile.name); } //Add procedural skies profile names m_settings.proceduralSkyboxChoices.Clear(); foreach (var profile in m_settings.m_profiles.m_proceduralSkyProfiles) { m_settings.proceduralSkyboxChoices.Add(profile.name); } #if UNITY_2018_3_OR_NEWER //Add gradient skies profile names m_settings.gradientSkyboxChoices.Clear(); foreach (var profile in m_settings.m_profiles.m_gradientSkyProfiles) { m_settings.gradientSkyboxChoices.Add(profile.name); } #endif //Add post processing profile names m_settings.ppChoices.Clear(); foreach (var profile in m_settings.m_profiles.m_ppProfiles) { m_settings.ppChoices.Add(profile.name); } //Add lightmaps profile names m_settings.lightmappingChoices.Clear(); foreach (var profile in m_settings.m_profiles.m_lightingProfiles) { m_settings.lightmappingChoices.Add(profile.name); } #endregion Repaint(); } #endregion #region Profile Selection GUILayout.BeginVertical("Skybox Profile Selection", m_boxStyle); GUILayout.Space(25f); if (systemtype == AmbientSkiesConsts.SystemTypes.AmbientHDRISkies) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Select Skybox", GUILayout.Width(146f)); newSkyboxSelection = EditorGUILayout.Popup(ambientSkiesSettings.m_selectedSkyboxProfileIndex, skyboxChoices.ToArray(), GUILayout.ExpandWidth(true), GUILayout.Height(16f)); EditorGUILayout.EndHorizontal(); //Prev / Next EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (newSkyboxSelection == 0) { GUI.enabled = false; } if (GUILayout.Button("Prev")) { newSkyboxSelection--; } GUI.enabled = true; if (newSkyboxSelection == skyboxChoices.Count - 1) { GUI.enabled = false; } if (GUILayout.Button("Next")) { newSkyboxSelection++; } GUI.enabled = true; EditorGUILayout.EndHorizontal(); } else if (systemtype == AmbientSkiesConsts.SystemTypes.AmbientProceduralSkies) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Select Skybox", GUILayout.Width(146f)); newProceduralSkyboxSelection = EditorGUILayout.Popup(ambientSkiesSettings.m_selectedProceduralSkyboxProfileIndex, proceduralSkyboxChoices.ToArray(), GUILayout.ExpandWidth(true), GUILayout.Height(16f)); EditorGUILayout.EndHorizontal(); //Prev / Next EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (newProceduralSkyboxSelection == 0) { GUI.enabled = false; } if (GUILayout.Button("Prev")) { newProceduralSkyboxSelection--; } GUI.enabled = true; if (newProceduralSkyboxSelection == skyboxChoices.Count - 1) { GUI.enabled = false; } if (GUILayout.Button("Next")) { newProceduralSkyboxSelection++; } GUI.enabled = true; EditorGUILayout.EndHorizontal(); } else { #if UNITY_2018_3_OR_NEWER EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Select Skybox", GUILayout.Width(146f)); newGradientSkyboxSelection = EditorGUILayout.Popup(ambientSkiesSettings.m_selectedGradientSkyboxProfileIndex, gradientSkyboxChoices.ToArray(), GUILayout.ExpandWidth(true), GUILayout.Height(16f)); EditorGUILayout.EndHorizontal(); //Prev / Next EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (newGradientSkyboxSelection == 0) { GUI.enabled = false; } if (GUILayout.Button("Prev")) { newGradientSkyboxSelection--; } GUI.enabled = true; if (newGradientSkyboxSelection == gradientSkyboxChoices.Count - 1) { GUI.enabled = false; } if (GUILayout.Button("Next")) { newGradientSkyboxSelection++; } GUI.enabled = true; EditorGUILayout.EndHorizontal(); #endif } EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Select Post Processing", GUILayout.Width(146f)); newppSelection = EditorGUILayout.Popup(ambientSkiesSettings.m_selectedPostProcessingProfileIndex, ppChoices.ToArray(), GUILayout.ExpandWidth(true), GUILayout.Height(16f)); EditorGUILayout.EndHorizontal(); //Prev / Next EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (newppSelection == 0) { GUI.enabled = false; } if (GUILayout.Button("Prev")) { newppSelection--; } GUI.enabled = true; if (newppSelection == ppChoices.Count - 1) { GUI.enabled = false; } if (GUILayout.Button("Next")) { newppSelection++; } GUI.enabled = true; EditorGUILayout.EndHorizontal(); #endregion GUILayout.EndVertical(); #region Buttons if (GUILayout.Button("Apply Changes")) { //Apply sky settings ApplySkies(); //Apply post processing settings ApplyPostProcessing(); } if (GUILayout.Button("Open Ambient Skies Editor")) { //Opens up Ambient Skies window ShowMenu(); } #endregion GUILayout.EndHorizontal(); //Check for changes, make undo record, make changes and let editor know we are dirty if (EditorGUI.EndChangeCheck()) { #region Apply Changes Undo.RecordObject(ambientSkiesSettings, "Made camera culling changes"); EditorUtility.SetDirty(ambientSkiesSettings); ambientSkiesSettings.m_profileList = profileList; ambientSkiesSettings.newProfileListIndex = newProfileListIndex; ambientSkiesSettings.m_profileListIndex = profileListIndex; m_creationToolSettings.m_selectedSystem = profileListIndex; ambientSkiesSettings.newSkyboxSelection = newSkyboxSelection; ambientSkiesSettings.newProceduralSkyboxSelection = newProceduralSkyboxSelection; ambientSkiesSettings.newGradientSkyboxSelection = newGradientSkyboxSelection; ambientSkiesSettings.m_selectedSkyboxProfileIndex = newSkyboxSelection; ambientSkiesSettings.m_selectedProceduralSkyboxProfileIndex = newProceduralSkyboxSelection; ambientSkiesSettings.m_selectedGradientSkyboxProfileIndex = newGradientSkyboxSelection; ambientSkiesSettings.m_selectedPostProcessingProfileIndex = newppSelection; m_creationToolSettings.m_selectedHDRI = newSkyboxSelection; m_creationToolSettings.m_selectedProcedural = newProceduralSkyboxSelection; m_creationToolSettings.m_selectedGradient = newGradientSkyboxSelection; m_creationToolSettings.m_selectedPostProcessing = newppSelection; ambientSkiesSettings.profileChoices = profileChoices; ambientSkiesSettings.skyboxChoices = skyboxChoices; ambientSkiesSettings.proceduralSkyboxChoices = proceduralSkyboxChoices; #if UNITY_2018_3_OR_NEWER ambientSkiesSettings.gradientSkyboxChoices = gradientSkyboxChoices; #endif ambientSkiesSettings.ppChoices = ppChoices; ambientSkiesSettings.lightmappingChoices = lightmappingChoices; ambientSkiesSettings.m_profiles = profiles; profiles.m_systemTypes = systemtype; ambientSkiesSettings.m_renderPipelineSelected = renderPipelineSettings; #endregion } }
/// <summary> /// Saves all the settings in all profiles /// </summary> /// <param name="renderPipelineSettings"></param> public void RevertAllDefaults(AmbientSkiesConsts.RenderPipelineSettings renderPipelineSettings) { #if UNITY_EDITOR EditorUtility.SetDirty(this); m_systemTypes = AmbientSkiesConsts.SystemTypes.ThirdParty; m_useTimeOfDay = AmbientSkiesConsts.DisableAndEnable.Disable; m_useSkies = false; m_usePostFX = false; m_useLighting = false; m_editSettings = false; m_showDebug = false; m_showFunctionDebugsOnly = false; m_showHasChangedDebug = false; m_showTimersInDebug = false; m_smartConsoleClean = false; GameObject postProcessObject = GameObject.Find("Global Post Processing"); if (postProcessObject != null) { DestroyImmediate(postProcessObject); } GameObject hdrpPPVolume = GameObject.Find("Post Processing HDRP Volume"); if (hdrpPPVolume != null) { DestroyImmediate(hdrpPPVolume); } foreach (AmbientSkyboxProfile skyboxProfile in m_skyProfiles) { skyboxProfile.RevertToDefault(); } foreach (AmbientProceduralSkyboxProfile proceduralProfile in m_proceduralSkyProfiles) { proceduralProfile.RevertToDefault(); } foreach (AmbientGradientSkyboxProfile gradientProfile in m_gradientSkyProfiles) { gradientProfile.RevertToDefault(); } foreach (AmbientPostProcessingProfile processProfile in m_ppProfiles) { processProfile.RevertToDefault(renderPipelineSettings); } foreach (AmbientLightingProfile lightingProfile in m_lightingProfiles) { lightingProfile.RevertToDefault(); } if (m_selectedRenderPipeline == AmbientSkiesConsts.RenderPipelineSettings.BuiltIn) { UpdateAllFogType(AmbientSkiesConsts.VolumeFogType.Linear); } else if (m_selectedRenderPipeline == AmbientSkiesConsts.RenderPipelineSettings.Lightweight) { UpdateAllFogType(AmbientSkiesConsts.VolumeFogType.Linear); } else { UpdateAllFogType(AmbientSkiesConsts.VolumeFogType.Volumetric); } m_CreationToolSettings = AssetDatabase.LoadAssetAtPath <CreationToolsSettings>(GetAssetPath("Ambient Skies Creation Tool Settings")); if (m_CreationToolSettings != null) { EditorUtility.SetDirty(m_CreationToolSettings); m_CreationToolSettings.RevertToFactorySettings(); } Material skyMaterial = AssetDatabase.LoadAssetAtPath <Material>(GetAssetPath("Ambient Skies Skybox")); if (skyMaterial != null) { skyMaterial.shader = Shader.Find("Skybox/Procedural"); skyMaterial.SetFloat("_SunDisk", 2f); skyMaterial.EnableKeyword("_SUNDISK_HIGH_QUALITY"); } DestroyParent("Ambient Skies Environment"); Debug.Log("Reverted to factory settings successfully"); #endif }