'push'
This commit is contained in:
@@ -0,0 +1,98 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
|
||||
namespace WaveHarmonic.Crest.Editor
|
||||
{
|
||||
#if !CREST_DEBUG
|
||||
[AddComponentMenu("")]
|
||||
#endif
|
||||
[ExecuteAlways]
|
||||
sealed class AmbientLightPatcher : MonoBehaviour
|
||||
{
|
||||
[SerializeField, HideInInspector]
|
||||
#pragma warning disable 414
|
||||
int _Version = 0;
|
||||
#pragma warning restore 414
|
||||
|
||||
#if UNITY_EDITOR
|
||||
void OnEnable() => InitializeAmbientLighting();
|
||||
void Update() => InitializeAmbientLighting();
|
||||
|
||||
bool _Baked;
|
||||
|
||||
void InitializeAmbientLighting()
|
||||
{
|
||||
if (_Baked)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (UnityEditor.Lightmapping.isRunning)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (Application.isPlaying)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Throws a warning.
|
||||
if (UnityEditor.ShaderUtil.anythingCompiling)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Only do skyboxes for now.
|
||||
if (RenderSettings.ambientMode != AmbientMode.Skybox)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// NOTE: Cannot use as API introduced in 6000.0.22f1 which cannot be targeted by defines.
|
||||
// if (UnityEditor.Lightmapping.bakeOnSceneLoad == UnityEditor.Lightmapping.BakeOnSceneLoadMode.IfMissingLightingData)
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
|
||||
var bake = true;
|
||||
var probe = RenderSettings.ambientProbe;
|
||||
|
||||
// Check if the ambient probe is effectively empty.
|
||||
for (var i = 0; i < 9; i++)
|
||||
{
|
||||
if (probe[0, i] != 0 || probe[1, i] != 0 || probe[2, i] != 0)
|
||||
{
|
||||
bake = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (bake)
|
||||
{
|
||||
#if !UNITY_6000_0_OR_NEWER
|
||||
var oldWorkflow = UnityEditor.Lightmapping.giWorkflowMode;
|
||||
UnityEditor.Lightmapping.giWorkflowMode = UnityEditor.Lightmapping.GIWorkflowMode.OnDemand;
|
||||
#endif
|
||||
// Only attempt to bake once per scene load.
|
||||
_Baked = UnityEditor.Lightmapping.BakeAsync();
|
||||
#if !UNITY_6000_0_OR_NEWER
|
||||
UnityEditor.Lightmapping.giWorkflowMode = oldWorkflow;
|
||||
#endif
|
||||
|
||||
#if CREST_DEBUG
|
||||
Debug.Log($"Crest: Baked scene lighting!");
|
||||
#endif
|
||||
|
||||
if (!_Baked)
|
||||
{
|
||||
Debug.LogWarning($"Crest: Could not generate scene lighting. Lighting will look incorrect.");
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fdfa905826925432690154f06e557c79
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,120 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
#if d_UnityPostProcessing
|
||||
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering.PostProcessing;
|
||||
|
||||
namespace WaveHarmonic.Crest.Examples
|
||||
{
|
||||
// ExecuteDuringEditMode does not work with scene camera.
|
||||
#if !CREST_DEBUG
|
||||
[AddComponentMenu("")]
|
||||
#endif
|
||||
[ExecuteAlways, RequireComponent(typeof(PostProcessVolume))]
|
||||
sealed class LegacyPostProcessingVolume : MonoBehaviour
|
||||
{
|
||||
[SerializeField, HideInInspector]
|
||||
#pragma warning disable 414
|
||||
int _Version = 0;
|
||||
#pragma warning restore 414
|
||||
|
||||
[@Layer]
|
||||
[SerializeField]
|
||||
int _Layer;
|
||||
|
||||
readonly List<PostProcessVolume> _QuickVolumes = new();
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
if (!RenderPipelineHelper.IsLegacy)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_QuickVolumes.Clear();
|
||||
|
||||
foreach (var volume in GetComponents<PostProcessVolume>())
|
||||
{
|
||||
if (volume.sharedProfile == null) continue;
|
||||
_QuickVolumes.Add(PostProcessManager.instance.QuickVolume(_Layer, volume.priority, volume.sharedProfile.settings.ToArray()));
|
||||
}
|
||||
}
|
||||
|
||||
void OnDisable()
|
||||
{
|
||||
foreach (var volume in _QuickVolumes)
|
||||
{
|
||||
if (volume == null) continue;
|
||||
Helpers.Destroy(volume.profile);
|
||||
var gameObject = volume.gameObject;
|
||||
Helpers.Destroy(volume);
|
||||
Helpers.Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using WaveHarmonic.Crest.Editor;
|
||||
|
||||
namespace WaveHarmonic.Crest.Examples
|
||||
{
|
||||
#if !CREST_DEBUG
|
||||
[AddComponentMenu("")]
|
||||
#endif
|
||||
[ExecuteAlways]
|
||||
sealed class LegacyPostProcessingVolume : MonoBehaviour
|
||||
{
|
||||
[@Layer]
|
||||
[SerializeField]
|
||||
int _Layer;
|
||||
|
||||
static string s_SceneName;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
// Ask only once per scene load.
|
||||
var scene = SceneManager.GetActiveScene();
|
||||
if (!RenderPipelineHelper.IsLegacy || s_SceneName == scene.name)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
s_SceneName = scene.name;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
var install = EditorUtility.DisplayDialog
|
||||
(
|
||||
"Missing Package",
|
||||
"This sample scene requires the post-processing package when using the built-in renderer. Without it the scene will be overexposed. Would you like to install it?",
|
||||
"Install",
|
||||
"Ignore"
|
||||
);
|
||||
|
||||
if (install)
|
||||
{
|
||||
PackageManagerHelpers.AddMissingPackage("com.unity.postprocessing");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
if (!RenderPipelineHelper.IsLegacy)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Debug.LogWarning("Crest: This scene requires the post-processing package. Without it the scene will be overexposed.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c1d3923e4ad524d8997140b39308dc69
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,114 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
using MonoBehaviour = WaveHarmonic.Crest.Internal.EditorBehaviour;
|
||||
#endif
|
||||
|
||||
namespace WaveHarmonic.Crest.Editor
|
||||
{
|
||||
#if !CREST_DEBUG
|
||||
[AddComponentMenu("")]
|
||||
#endif
|
||||
[DefaultExecutionOrder(-1000)]
|
||||
[ExecuteAlways]
|
||||
sealed class LightingPatcher : MonoBehaviour
|
||||
{
|
||||
[SerializeField, HideInInspector]
|
||||
#pragma warning disable 414
|
||||
int _Version = 0;
|
||||
#pragma warning restore 414
|
||||
|
||||
#if !CREST_DEBUG
|
||||
[HideInInspector]
|
||||
#endif
|
||||
[@DecoratedField, SerializeField]
|
||||
bool _LightsUseLinearIntensity;
|
||||
|
||||
#if !CREST_DEBUG
|
||||
[HideInInspector]
|
||||
#endif
|
||||
[@DecoratedField, SerializeField]
|
||||
bool _LightsUseColorTemperature;
|
||||
|
||||
bool _CurrentLightsUseLinearIntensity;
|
||||
bool _CurrentLightsUseColorTemperature;
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
// SRP is always linear with temperature.
|
||||
if (RenderPipelineHelper.IsLegacy)
|
||||
{
|
||||
Camera.onPreCull -= OnBeginRendering;
|
||||
Camera.onPreCull += OnBeginRendering;
|
||||
Camera.onPostRender -= OnEndRendering;
|
||||
Camera.onPostRender += OnEndRendering;
|
||||
}
|
||||
else
|
||||
{
|
||||
RenderPipelineManager.beginContextRendering -= OnBeginContextRendering;
|
||||
RenderPipelineManager.beginContextRendering += OnBeginContextRendering;
|
||||
RenderPipelineManager.endContextRendering -= OnEndContextRendering;
|
||||
RenderPipelineManager.endContextRendering += OnEndContextRendering;
|
||||
}
|
||||
|
||||
_CurrentLightsUseLinearIntensity = GraphicsSettings.lightsUseLinearIntensity;
|
||||
_CurrentLightsUseColorTemperature = GraphicsSettings.lightsUseColorTemperature;
|
||||
}
|
||||
|
||||
void OnDisable()
|
||||
{
|
||||
if (RenderPipelineHelper.IsLegacy)
|
||||
{
|
||||
Camera.onPreCull -= OnBeginRendering;
|
||||
Camera.onPostRender -= OnEndRendering;
|
||||
}
|
||||
else
|
||||
{
|
||||
RenderPipelineManager.beginContextRendering -= OnBeginContextRendering;
|
||||
RenderPipelineManager.endContextRendering -= OnEndContextRendering;
|
||||
}
|
||||
}
|
||||
|
||||
void OnBeginContextRendering(ScriptableRenderContext context, List<Camera> cameras) => ChangeLighting();
|
||||
void OnEndContextRendering(ScriptableRenderContext context, List<Camera> cameras) => RestoreLighting();
|
||||
|
||||
void OnBeginRendering(Camera camera) => ChangeLighting();
|
||||
void OnEndRendering(Camera camera) => RestoreLighting();
|
||||
|
||||
void ChangeLighting()
|
||||
{
|
||||
_CurrentLightsUseLinearIntensity = GraphicsSettings.lightsUseLinearIntensity;
|
||||
_CurrentLightsUseColorTemperature = GraphicsSettings.lightsUseColorTemperature;
|
||||
GraphicsSettings.lightsUseLinearIntensity = true;
|
||||
GraphicsSettings.lightsUseColorTemperature = true;
|
||||
}
|
||||
|
||||
void RestoreLighting()
|
||||
{
|
||||
GraphicsSettings.lightsUseLinearIntensity = _CurrentLightsUseLinearIntensity;
|
||||
GraphicsSettings.lightsUseColorTemperature = _CurrentLightsUseColorTemperature;
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
private protected override void Reset()
|
||||
{
|
||||
_LightsUseLinearIntensity = GraphicsSettings.lightsUseLinearIntensity;
|
||||
_LightsUseColorTemperature = GraphicsSettings.lightsUseColorTemperature;
|
||||
|
||||
base.Reset();
|
||||
}
|
||||
|
||||
[@OnChange]
|
||||
void OnChange(string propertyPath, object previousValue)
|
||||
{
|
||||
GraphicsSettings.lightsUseLinearIntensity = _LightsUseLinearIntensity;
|
||||
GraphicsSettings.lightsUseColorTemperature = _LightsUseColorTemperature;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 41f656df4b8434812870960da35d35b4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 30
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,47 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
using UnityEditor.SceneManagement;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering.HighDefinition;
|
||||
|
||||
namespace WaveHarmonic.Crest.Editor
|
||||
{
|
||||
#if !CREST_DEBUG
|
||||
[AddComponentMenu("")]
|
||||
#endif
|
||||
[RequireComponent(typeof(Camera))]
|
||||
sealed class RenderPipelineCameraPatcher : RenderPipelinePatcher
|
||||
{
|
||||
[SerializeField, HideInInspector]
|
||||
#pragma warning disable 414
|
||||
int _Version = 0;
|
||||
#pragma warning restore 414
|
||||
|
||||
#if UNITY_EDITOR
|
||||
protected override void OnActiveRenderPipelineTypeChanged()
|
||||
{
|
||||
if (PrefabStageUtility.GetCurrentPrefabStage() != null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isActiveAndEnabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
#if d_UnityHDRP
|
||||
if (RenderPipelineHelper.IsHighDefinition)
|
||||
{
|
||||
if (TryGetComponent<HDAdditionalCameraData>(out var data))
|
||||
{
|
||||
// This component will try to modify serialized HDR & MSAA properties every frame. Disgusting.
|
||||
data.enabled = true;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2b740d83895ff4657b903a39cce9286c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,79 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
using System.Reflection;
|
||||
using UnityEditor;
|
||||
using UnityEditor.SceneManagement;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering.HighDefinition;
|
||||
|
||||
namespace WaveHarmonic.Crest.Editor
|
||||
{
|
||||
#if !CREST_DEBUG
|
||||
[AddComponentMenu("")]
|
||||
#endif
|
||||
[RequireComponent(typeof(Light))]
|
||||
[DefaultExecutionOrder(10)]
|
||||
sealed class RenderPipelineLightPatcher : RenderPipelinePatcher
|
||||
{
|
||||
[SerializeField, HideInInspector]
|
||||
#pragma warning disable 414
|
||||
int _Version = 0;
|
||||
#pragma warning restore 414
|
||||
|
||||
#if d_UnityHDRP
|
||||
// For 2023.3 onwards, HDAdditionalLightData.intensity is obsolete and returns Light.intensity.
|
||||
// It still serializes the old value so grab it via reflection.
|
||||
static readonly FieldInfo s_Intensity = typeof(HDAdditionalLightData)
|
||||
.GetField("m_Intensity", BindingFlags.Instance | BindingFlags.NonPublic);
|
||||
#endif
|
||||
|
||||
#if UNITY_EDITOR
|
||||
private protected override void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
if (!Application.isPlaying) OnActiveRenderPipelineTypeChanged();
|
||||
}
|
||||
|
||||
protected override void OnActiveRenderPipelineTypeChanged()
|
||||
{
|
||||
EditorApplication.update -= OnActiveRenderPipelineTypeChanged;
|
||||
|
||||
if (PrefabStageUtility.GetCurrentPrefabStage() != null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Can happen.
|
||||
if (this == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isActiveAndEnabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
#if d_UnityHDRP
|
||||
if (RenderPipelineHelper.IsHighDefinition)
|
||||
{
|
||||
if (TryGetComponent<Light>(out var light) && TryGetComponent<HDAdditionalLightData>(out var data))
|
||||
{
|
||||
var intensity = (float)s_Intensity.GetValue(data);
|
||||
|
||||
if (light.intensity == intensity) return;
|
||||
|
||||
// HDRP will not restore the correct intensity.
|
||||
light.intensity = intensity;
|
||||
|
||||
// Execute next frame as revert prefab interferes despite executing afterwards.
|
||||
EditorApplication.update -= OnActiveRenderPipelineTypeChanged;
|
||||
EditorApplication.update += OnActiveRenderPipelineTypeChanged;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3a245210cb0ef4c94aac318662d37252
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,31 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
using MonoBehaviour = WaveHarmonic.Crest.Internal.EditorBehaviour;
|
||||
#endif
|
||||
|
||||
namespace WaveHarmonic.Crest.Editor
|
||||
{
|
||||
[ExecuteAlways]
|
||||
abstract class RenderPipelinePatcher : MonoBehaviour
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
protected virtual void OnEnable()
|
||||
{
|
||||
RenderPipelineManager.activeRenderPipelineTypeChanged -= OnActiveRenderPipelineTypeChanged;
|
||||
RenderPipelineManager.activeRenderPipelineTypeChanged += OnActiveRenderPipelineTypeChanged;
|
||||
}
|
||||
|
||||
protected virtual void OnDisable()
|
||||
{
|
||||
RenderPipelineManager.activeRenderPipelineTypeChanged -= OnActiveRenderPipelineTypeChanged;
|
||||
}
|
||||
|
||||
protected abstract void OnActiveRenderPipelineTypeChanged();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5c5e6eb7e2ef841d38e15a82c8b83964
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,53 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
// Restores "Lighting > Environment" settings after switching from HDRP. "Lighting > Other Settings" do not need
|
||||
// restoring. We only need to restore the skybox as we use the default values for everything else.
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
namespace WaveHarmonic.Crest.Editor
|
||||
{
|
||||
#if !CREST_DEBUG
|
||||
[AddComponentMenu("")]
|
||||
#endif
|
||||
sealed class RenderPipelineSettingsPatcher : RenderPipelinePatcher
|
||||
{
|
||||
[SerializeField, HideInInspector]
|
||||
#pragma warning disable 414
|
||||
int _Version = 0;
|
||||
#pragma warning restore 414
|
||||
|
||||
[@AttachMaterialEditor]
|
||||
[@DecoratedField, SerializeField]
|
||||
Material _SkyBox;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
private protected override void Reset()
|
||||
{
|
||||
_SkyBox = RenderSettings.skybox;
|
||||
|
||||
base.Reset();
|
||||
}
|
||||
|
||||
protected override void OnEnable()
|
||||
{
|
||||
base.OnEnable();
|
||||
OnActiveRenderPipelineTypeChanged();
|
||||
}
|
||||
|
||||
protected override void OnActiveRenderPipelineTypeChanged()
|
||||
{
|
||||
if (!isActiveAndEnabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (RenderPipelineHelper.IsLegacy || RenderPipelineHelper.IsUniversal)
|
||||
{
|
||||
RenderSettings.skybox = _SkyBox;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8911488f4e1ce40e1b2766334def268b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,62 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
using UnityEditor.SceneManagement;
|
||||
using UnityEngine;
|
||||
|
||||
namespace WaveHarmonic.Crest.Editor
|
||||
{
|
||||
#if !CREST_DEBUG
|
||||
[AddComponentMenu("")]
|
||||
#endif
|
||||
sealed class RenderPipelineTerrainPatcher : RenderPipelinePatcher
|
||||
{
|
||||
[SerializeField, HideInInspector]
|
||||
#pragma warning disable 414
|
||||
int _Version = 0;
|
||||
#pragma warning restore 414
|
||||
|
||||
[SerializeField]
|
||||
Material _Material;
|
||||
|
||||
[SerializeField]
|
||||
Material _MaterialHDRP;
|
||||
|
||||
[SerializeField]
|
||||
Material _MaterialURP;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
protected override void OnEnable()
|
||||
{
|
||||
base.OnEnable();
|
||||
OnActiveRenderPipelineTypeChanged();
|
||||
}
|
||||
|
||||
protected override void OnActiveRenderPipelineTypeChanged()
|
||||
{
|
||||
if (PrefabStageUtility.GetCurrentPrefabStage() != null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isActiveAndEnabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
#if d_Unity_Terrain
|
||||
foreach (var terrain in GetComponentsInChildren<Terrain>())
|
||||
{
|
||||
terrain.materialTemplate = RenderPipelineHelper.RenderPipeline switch
|
||||
{
|
||||
RenderPipeline.Legacy => _Material,
|
||||
RenderPipeline.Universal => _MaterialURP,
|
||||
RenderPipeline.HighDefinition => _MaterialHDRP,
|
||||
_ => throw new System.NotImplementedException(),
|
||||
};
|
||||
}
|
||||
#endif // d_Unity_Terrain
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e49c7e9e3297f44b3a07573b45ec815d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences:
|
||||
- _Material: {fileID: 10650, guid: 0000000000000000f000000000000000, type: 0}
|
||||
- _MaterialHDRP: {fileID: 2100000, guid: 22ff8771d87ef27429e670136399094b, type: 2}
|
||||
- _MaterialURP: {fileID: 2100000, guid: 594ea882c5a793440b60ff72d896021e, type: 2}
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,49 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
using UnityEditor;
|
||||
using UnityEditor.SceneManagement;
|
||||
using UnityEngine;
|
||||
|
||||
namespace WaveHarmonic.Crest.Editor
|
||||
{
|
||||
#if !CREST_DEBUG
|
||||
[AddComponentMenu("")]
|
||||
#endif
|
||||
sealed class RevertPrefabOnRenderPipelineChange : RenderPipelinePatcher
|
||||
{
|
||||
[SerializeField, HideInInspector]
|
||||
#pragma warning disable 414
|
||||
int _Version = 0;
|
||||
#pragma warning restore 414
|
||||
|
||||
#if UNITY_EDITOR
|
||||
private protected override void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
if (!Application.isPlaying) OnActiveRenderPipelineTypeChanged();
|
||||
}
|
||||
|
||||
protected override void OnActiveRenderPipelineTypeChanged()
|
||||
{
|
||||
if (PrefabStageUtility.GetCurrentPrefabStage() != null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isActiveAndEnabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var item in gameObject.GetComponents<Component>())
|
||||
{
|
||||
if (item is Transform) continue;
|
||||
if (item == null) continue; // Can happen if missing packages/scripts.
|
||||
if (!PrefabUtility.IsPartOfPrefabInstance(item)) continue;
|
||||
PrefabUtility.RevertObjectOverride(item, InteractionMode.AutomatedAction);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8ee84b2ccf836471c94ceaafe58b392e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user