private void OnEnable() { WaterReflections = (PWS_WaterSystem)target; if (m_editorUtils == null) { // Get editor utils for this m_editorUtils = PWApp.GetEditorUtils(this); } }
/// <summary> /// Configures water to LWRP /// </summary> /// <param name="profile"></param> private static void ConfigureWater(UnityPipelineProfile profile, GaiaSettings gaiaSettings) { if (gaiaSettings == null) { Debug.LogError("Gaia settings could not be found. Please make sure gaia settings is import into your project"); } else { if (profile.m_underwaterHorizonMaterial != null) { profile.m_underwaterHorizonMaterial.shader = Shader.Find(profile.m_lightweightHorizonObjectShader); } //Increasing Water mesh quality for LWRP gaiaSettings.m_gaiaWaterProfile.m_customMeshQuality = 8; if (GaiaGlobal.Instance != null) { GaiaWater.UpdateWaterMeshQuality(GaiaGlobal.Instance.SceneProfile, GaiaGlobal.Instance.SceneProfile.m_waterPrefab); } GameObject waterObject = GameObject.Find(gaiaSettings.m_gaiaWaterProfile.m_waterPrefab.name); if (waterObject != null) { Material waterMat = GaiaWater.GetGaiaOceanMaterial(); if (waterMat != null) { if (GaiaGlobal.Instance != null) { GaiaWater.GetProfile(0, waterMat, GaiaGlobal.Instance.SceneProfile, true, false); } } else { Debug.Log("Material could not be found"); } } } PWS_WaterSystem reflection = Object.FindObjectOfType <PWS_WaterSystem>(); if (reflection != null) { Object.DestroyImmediate(reflection); } }
/// <summary> /// Setup for the automatically probe spawning /// </summary> /// <param name="profile"></param> public static void CreateAutomaticProbes(ReflectionProbeData profile) { int numberTerrains = Terrain.activeTerrains.Length; if (numberTerrains == 0) { Debug.LogError("Unable to initiate probe spawning systen. No terrain found"); } else { if (profile.lightProbesPerRow < 2) { Debug.LogError("Please set Light Probes Per Row to a value of 2 or higher"); } else { LoadProbesFromScene(); m_probeLocations = null; ClearCreatedLightProbes(); float seaLevel = 0f; PWS_WaterSystem gaiawater = GameObject.FindObjectOfType <PWS_WaterSystem>(); if (gaiawater != null) { seaLevel = gaiawater.SeaLevel; } if (GaiaUtils.HasDynamicLoadedTerrains()) { Action <Terrain> terrAction = (t) => GenerateProbesOnTerrain(t, profile, seaLevel); GaiaUtils.CallFunctionOnDynamicLoadedTerrains(terrAction, true, null, "Generating Light Probes"); } else { foreach (var activeTerrain in Terrain.activeTerrains) { GenerateProbesOnTerrain(activeTerrain, profile, seaLevel); } } } } }
/// <summary> /// Custom editor for PWS_WaterReflections /// </summary public override void OnInspectorGUI() { EditorGUI.BeginChangeCheck(); //Initialization m_editorUtils.Initialize(); // Do not remove this! if (WaterReflections == null) { WaterReflections = (PWS_WaterSystem)target; } m_editorUtils.Panel("GlobalSettings", GlobalSettings, true); if (EditorGUI.EndChangeCheck()) { EditorUtility.SetDirty(WaterReflections); } }
/// <summary> /// Setup for the automatically probe spawning /// </summary> /// <param name="reflectionProbeData"></param> public static void CreateAutomaticProbes(ReflectionProbeData reflectionProbeData, GaiaConstants.EnvironmentRenderer renderPipelineSettings) { if (reflectionProbeData == null) { return; } if (reflectionProbeData.reflectionProbeRefresh == GaiaConstants.ReflectionProbeRefreshModePW.ProbeManager && reflectionProbeData.reflectionProbeMode == ReflectionProbeMode.Realtime) { #if GAIA_PRO_PRESENT ReflectionProbeManager manager = ReflectionProbeManager.GetOrCreateProbeManager(); if (manager != null) { manager.ProbeLayerMask = reflectionProbeData.reflectionprobeCullingMask; } #endif } else { #if GAIA_PRO_PRESENT ReflectionProbeManager.RemoveReflectionProbeManager(); #endif } ClearCreatedReflectionProbes(); GameObject oldReflectionProbe = GameObject.Find("Global Reflection Probe"); if (oldReflectionProbe != null) { UnityEngine.Object.DestroyImmediate(oldReflectionProbe); Debug.Log("Old Reflection Probe Destroyed"); } if (reflectionProbeData.reflectionProbesPerRow < 2) { Debug.LogError("Please set Probes Per Row to a value of 2 or higher"); } else { m_currentProbeCount = 0; float seaLevel = 0f; bool seaLevelActive = false; PWS_WaterSystem gaiawater = GameObject.FindObjectOfType <PWS_WaterSystem>(); if (gaiawater != null) { seaLevel = gaiawater.SeaLevel; seaLevelActive = true; } if (GaiaUtils.HasDynamicLoadedTerrains()) { Action <Terrain> terrAction = (t) => GenerateProbesOnTerrain(t, reflectionProbeData, seaLevelActive, seaLevel, renderPipelineSettings); GaiaUtils.CallFunctionOnDynamicLoadedTerrains(terrAction, true, null, "Generating Reflection Probes"); } else { if (Terrain.activeTerrains.Length < 1) { Debug.LogError("No terrains we're found, unable to generate reflection probes."); } else { foreach (var activeTerrain in Terrain.activeTerrains) { GenerateProbesOnTerrain(activeTerrain, reflectionProbeData, seaLevelActive, seaLevel, renderPipelineSettings); } } } m_probeRenderActive = true; } }
/// <summary> /// Cleans up LWRP components in the scene /// </summary> public static void CleanUpURP(UnityPipelineProfile profile, GaiaSettings gaiaSettings) { try { #if UPPipeline UniversalAdditionalCameraData[] camerasData = GameObject.FindObjectsOfType <UniversalAdditionalCameraData>(); GaiaURPRuntimeUtils.ClearUPCameraData(camerasData); UniversalAdditionalLightData[] lightsData = GameObject.FindObjectsOfType <UniversalAdditionalLightData>(); GaiaURPRuntimeUtils.ClearUPLightData(lightsData); GameObject volumeObject = GameObject.Find("Global Post Processing"); if (volumeObject != null) { GameObject.DestroyImmediate(volumeObject); } Camera camera = GaiaUtils.GetCamera(); if (camera != null) { UniversalAdditionalCameraData cameraData = camera.GetComponent <UniversalAdditionalCameraData>(); if (cameraData == null) { cameraData = camera.gameObject.AddComponent <UniversalAdditionalCameraData>(); } cameraData.renderPostProcessing = false; } #endif if (profile.m_underwaterHorizonMaterial != null) { profile.m_underwaterHorizonMaterial.shader = Shader.Find(profile.m_builtInHorizonObjectShader); } GameObject waterPrefab = GameObject.Find(gaiaSettings.m_gaiaWaterProfile.m_waterPrefab.name); if (waterPrefab != null) { //reverting default water mesh quality gaiaSettings.m_gaiaWaterProfile.m_customMeshQuality = 2; if (GaiaGlobal.Instance != null) { GaiaWater.UpdateWaterMeshQuality(GaiaGlobal.Instance.SceneProfile, gaiaSettings.m_gaiaWaterProfile.m_waterPrefab); } PWS_WaterSystem reflection = waterPrefab.GetComponent <PWS_WaterSystem>(); if (reflection == null) { reflection = waterPrefab.AddComponent <PWS_WaterSystem>(); } } Terrain[] terrains = Terrain.activeTerrains; if (terrains != null) { foreach (Terrain terrain in terrains) { #if !UNITY_2019_2_OR_NEWER terrain.materialType = Terrain.MaterialType.BuiltInStandard; #else terrain.materialTemplate = profile.m_builtInTerrainMaterial; #endif } } Terrain terrainDetail = Terrain.activeTerrain; if (terrainDetail != null) { if (terrainDetail.detailObjectDensity == 0f) { if (EditorUtility.DisplayDialog("Detail Density Disabled!", "Details density is disabled on your terrain would you like to activate it?", "Yes", "No")) { terrainDetail.detailObjectDensity = 0.3f; } } } GameObject LWRPReflections = GameObject.Find("URP Water Reflection Probe"); if (LWRPReflections != null) { Object.DestroyImmediate(LWRPReflections); } GraphicsSettings.renderPipelineAsset = null; QualitySettings.renderPipeline = null; if (GaiaGlobal.Instance != null) { //GaiaUtils.GetRuntimeSceneObject(); if (GaiaGlobal.Instance.SceneProfile != null && GaiaGlobal.Instance.SceneProfile.m_lightingProfiles.Count > 0) { GaiaLighting.GetProfile(GaiaGlobal.Instance.SceneProfile, gaiaSettings.m_pipelineProfile, GaiaConstants.EnvironmentRenderer.BuiltIn); } } //Clean up the UPR post processing objects in the underwater effects //We need to look for transform instead of GameObjects, since the GOs can be disabled and won't be found then GameObject uwe = GameObject.Find(GaiaConstants.underwaterEffectsName); if (uwe != null) { Transform utoTransform = uwe.transform.Find(GaiaConstants.underwaterTransitionObjectName); if (utoTransform != null) { Object.DestroyImmediate(utoTransform.gameObject); } Transform uppTransform = uwe.transform.Find(GaiaConstants.underwaterPostProcessingName); if (uppTransform != null) { Object.DestroyImmediate(uppTransform.gameObject); } Transform horizonTransform = uwe.transform.Find(GaiaConstants.underwaterHorizonName); if (horizonTransform != null) { Object.DestroyImmediate(horizonTransform.gameObject); } } if (waterPrefab != null) { Material waterMat = GaiaWater.GetGaiaOceanMaterial(); if (waterMat != null) { if (GaiaGlobal.Instance != null) { GaiaWater.GetProfile(gaiaSettings.m_gaiaWaterProfile.m_selectedWaterProfileValuesIndex, waterMat, GaiaGlobal.Instance.SceneProfile, true, false); } } else { Debug.Log("Material could not be found"); } } MarkSceneDirty(false); EditorUtility.SetDirty(profile); profile.m_activePipelineInstalled = GaiaConstants.EnvironmentRenderer.BuiltIn; GaiaManagerEditor manager = EditorWindow.GetWindow <Gaia.GaiaManagerEditor>(false, "Gaia Manager"); if (manager != null) { manager.GaiaManagerStatusCheck(true); } bool isChanged = false; string currBuildSettings = PlayerSettings.GetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup); if (currBuildSettings.Contains("UPPipeline")) { currBuildSettings = currBuildSettings.Replace("UPPipeline;", ""); currBuildSettings = currBuildSettings.Replace("UPPipeline", ""); isChanged = true; } if (isChanged) { PlayerSettings.SetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup, currBuildSettings); } } catch (Exception e) { Console.WriteLine(e); throw; } }
/// <summary> /// Cleans up LWRP components in the scene /// </summary> public static void CleanUpLWRP(UnityPipelineProfile profile, GaiaSettings gaiaSettings) { #if LWPipeline LWRPAdditionalCameraData[] camerasData = Object.FindObjectsOfType <LWRPAdditionalCameraData>(); if (camerasData != null) { foreach (LWRPAdditionalCameraData data in camerasData) { Object.DestroyImmediate(data); } } LWRPAdditionalLightData[] lightsData = Object.FindObjectsOfType <LWRPAdditionalLightData>(); if (lightsData != null) { foreach (LWRPAdditionalLightData data in lightsData) { Object.DestroyImmediate(data); } } #endif if (profile.m_underwaterHorizonMaterial != null) { profile.m_underwaterHorizonMaterial.shader = Shader.Find(profile.m_builtInHorizonObjectShader); } //reverting default water mesh quality gaiaSettings.m_gaiaWaterProfile.m_customMeshQuality = 2; if (GaiaGlobal.Instance != null) { GaiaWater.UpdateWaterMeshQuality(GaiaGlobal.Instance.SceneProfile, gaiaSettings.m_gaiaWaterProfile.m_waterPrefab); } GameObject waterPrefab = GameObject.Find(gaiaSettings.m_gaiaWaterProfile.m_waterPrefab.name); if (waterPrefab != null) { PWS_WaterSystem reflection = waterPrefab.GetComponent <PWS_WaterSystem>(); if (reflection == null) { reflection = waterPrefab.AddComponent <PWS_WaterSystem>(); } } Terrain[] terrains = Terrain.activeTerrains; if (terrains != null) { foreach (Terrain terrain in terrains) { #if !UNITY_2019_2_OR_NEWER terrain.materialType = Terrain.MaterialType.BuiltInStandard; #else terrain.materialTemplate = profile.m_builtInTerrainMaterial; #endif } } Terrain terrainDetail = Terrain.activeTerrain; if (terrainDetail != null) { if (terrainDetail.detailObjectDensity == 0f) { if (EditorUtility.DisplayDialog("Detail Density Disabled!", "Details density is disabled on your terrain would you like to activate it?", "Yes", "No")) { terrainDetail.detailObjectDensity = 0.3f; } } } GameObject LWRPReflections = GameObject.Find("LWRP Water Reflection Probe"); if (LWRPReflections != null) { Object.DestroyImmediate(LWRPReflections); } GraphicsSettings.renderPipelineAsset = null; if (GaiaGlobal.Instance != null) { GaiaUtils.GetRuntimeSceneObject(); GaiaLighting.GetProfile(GaiaGlobal.Instance.SceneProfile, gaiaSettings.m_pipelineProfile, GaiaConstants.EnvironmentRenderer.BuiltIn); } if (waterPrefab != null) { Material waterMat = GaiaWater.GetGaiaOceanMaterial(); if (waterMat != null) { if (GaiaGlobal.Instance != null) { GaiaWater.GetProfile(0, waterMat, GaiaGlobal.Instance.SceneProfile, true, false); } } else { Debug.Log("Material could not be found"); } } MarkSceneDirty(false); EditorUtility.SetDirty(profile); profile.m_activePipelineInstalled = GaiaConstants.EnvironmentRenderer.BuiltIn; GaiaManagerEditor manager = EditorWindow.GetWindow <Gaia.GaiaManagerEditor>(false, "Gaia Manager"); if (manager != null) { manager.GaiaManagerStatusCheck(true); } bool isChanged = false; string currBuildSettings = PlayerSettings.GetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup); if (currBuildSettings.Contains("LWPipeline")) { currBuildSettings = currBuildSettings.Replace("LWPipeline;", ""); currBuildSettings = currBuildSettings.Replace("LWPipeline", ""); isChanged = true; } if (isChanged) { PlayerSettings.SetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup, currBuildSettings); } }