升级6.4.升级水,升级天气
This commit is contained in:
@@ -117,6 +117,11 @@ namespace WaveHarmonic.Crest.Editor.Build
|
||||
ProjectSettings _Settings;
|
||||
WaterResources _Resources;
|
||||
|
||||
static readonly string[] s_LightMapKeywords =
|
||||
{
|
||||
"LIGHTMAP_ON", "DIRLIGHTMAP_COMBINED", "DYNAMICLIGHTMAP_ON", "LIGHTMAP_SHADOW_MIXING", "SHADOWS_SHADOWMASK"
|
||||
};
|
||||
|
||||
void Logger(string message)
|
||||
{
|
||||
Debug.Log(message);
|
||||
@@ -210,6 +215,24 @@ namespace WaveHarmonic.Crest.Editor.Build
|
||||
}
|
||||
}
|
||||
|
||||
// Strip lightmap variants.
|
||||
// Unity strips these unless they are used by any shader once in the scene, then
|
||||
// they are always included. Seems like a bug. To test, make sure lightmaps are
|
||||
// set up, and there is a static object in the scene. Or set the following:
|
||||
// Project Settings > Graphics > Shader Stripping > Lightmap Modes
|
||||
foreach (var keyword in keywords)
|
||||
{
|
||||
if (s_LightMapKeywords.Contains(keyword.name))
|
||||
{
|
||||
if (_Settings.LogStrippedVariants)
|
||||
{
|
||||
Logger($"Stripping Keyword: {keyword.name}");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -66,12 +66,16 @@ namespace WaveHarmonic.Crest.Editor
|
||||
message += $"Scale: {target.CalcLodScale(i)}\n";
|
||||
message += $"Texel: {2f * 2f * target.CalcLodScale(i) / target.LodResolution}\n";
|
||||
message += $"Minimum Slice: {Mathf.Floor(Mathf.Log(Mathf.Max(i / baseTexelSize, 1f), 2f))}";
|
||||
if (i < target.LodLevels - 1) message += "\n\n";
|
||||
message += "\n\n";
|
||||
}
|
||||
|
||||
message += $"Scale: {target.Scale}\n";
|
||||
|
||||
message += "\n";
|
||||
|
||||
if (target.Surface.Material.HasVector(WaterRenderer.ShaderIDs.s_Absorption))
|
||||
{
|
||||
message += $"\n\nDepth Fog Density: {target.Surface.Material.GetVector(WaterRenderer.ShaderIDs.s_Absorption)}";
|
||||
message += $"Depth Fog Density: {target.Surface.Material.GetVector(WaterRenderer.ShaderIDs.s_Absorption)}";
|
||||
}
|
||||
|
||||
EditorGUILayout.HelpBox(message, MessageType.None);
|
||||
@@ -106,7 +110,7 @@ namespace WaveHarmonic.Crest.Editor
|
||||
|
||||
ValidatedHelper.ExecuteValidators(target, ValidatedHelper.DebugLog);
|
||||
|
||||
foreach (var component in FindObjectsByType<EditorBehaviour>(FindObjectsSortMode.None))
|
||||
foreach (var component in Helpers.FindObjectsByType<EditorBehaviour>())
|
||||
{
|
||||
if (component is WaterRenderer) continue;
|
||||
ValidatedHelper.ExecuteValidators(component, ValidatedHelper.DebugLog);
|
||||
@@ -116,6 +120,17 @@ namespace WaveHarmonic.Crest.Editor
|
||||
|
||||
ManualValidation = false;
|
||||
}
|
||||
|
||||
#if CREST_DEBUG
|
||||
if (GUILayout.Button("Pause Time"))
|
||||
{
|
||||
var time = Undo.AddComponent<CustomTimeProvider>(target.gameObject);
|
||||
time.Paused = true;
|
||||
time.OverrideTime = true;
|
||||
target._TimeProvider = time;
|
||||
target.TimeProviders.Push(time);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,12 +143,27 @@ namespace WaveHarmonic.Crest.Editor
|
||||
"Fully developed sea with infinite fetch.",
|
||||
};
|
||||
|
||||
static readonly GUIContent s_TimeScaleLabel = new("Time Scale");
|
||||
|
||||
System.Type _HostComponentType = null;
|
||||
public void SetTypeOfHostComponent(System.Type hostComponentType)
|
||||
enum WaveModel
|
||||
{
|
||||
_HostComponentType = hostComponentType;
|
||||
None,
|
||||
FFT,
|
||||
Gerstner,
|
||||
}
|
||||
WaveModel _WaveModel;
|
||||
object _Host;
|
||||
|
||||
public void SetHostComponent(object host)
|
||||
{
|
||||
_Host = host;
|
||||
}
|
||||
|
||||
public void SetTypeOfHostComponent(System.Type host)
|
||||
{
|
||||
_WaveModel = host == typeof(ShapeGerstner)
|
||||
? WaveModel.Gerstner
|
||||
: host == typeof(ShapeFFT)
|
||||
? WaveModel.FFT
|
||||
: WaveModel.None;
|
||||
}
|
||||
|
||||
protected override void OnEnable()
|
||||
@@ -164,7 +194,7 @@ namespace WaveHarmonic.Crest.Editor
|
||||
{
|
||||
// Display a notice if its being edited as a standalone asset (not embedded in a component) because
|
||||
// it displays the FFT-interface.
|
||||
if (_HostComponentType == null)
|
||||
if (_WaveModel is WaveModel.None)
|
||||
{
|
||||
EditorGUILayout.HelpBox("This editor is displaying the FFT spectrum settings. " +
|
||||
"To edit settings specific to the ShapeGerstner component, assign this asset to a ShapeGerstner component " +
|
||||
@@ -176,22 +206,16 @@ namespace WaveHarmonic.Crest.Editor
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
var beingEditedOnGerstnerComponent = _HostComponentType == typeof(ShapeGerstner);
|
||||
|
||||
var showAdvancedControls = false;
|
||||
if (beingEditedOnGerstnerComponent)
|
||||
if (_WaveModel is WaveModel.Gerstner)
|
||||
{
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(WaveSpectrum._GravityScale)));
|
||||
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(WaveSpectrum._WaveDirectionVariance)));
|
||||
}
|
||||
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(WaveSpectrum._ShowAdvancedControls)));
|
||||
showAdvancedControls = serializedObject.FindProperty(nameof(WaveSpectrum._ShowAdvancedControls)).boolValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(WaveSpectrum._GravityScale)), s_TimeScaleLabel);
|
||||
}
|
||||
EditorGUILayout.Space(10);
|
||||
|
||||
var advancedControls = serializedObject.FindProperty(nameof(WaveSpectrum._ShowAdvancedControls));
|
||||
EditorGUILayout.PropertyField(advancedControls);
|
||||
var showAdvancedControls = advancedControls.boolValue;
|
||||
|
||||
var spSpectrumModel = serializedObject.FindProperty(nameof(WaveSpectrum._Model));
|
||||
var spectraIndex = serializedObject.FindProperty(nameof(WaveSpectrum._Model)).enumValueIndex;
|
||||
@@ -222,6 +246,7 @@ namespace WaveHarmonic.Crest.Editor
|
||||
var spPower = serializedObject.FindProperty(nameof(WaveSpectrum._PowerLogarithmicScales));
|
||||
var spChopScales = serializedObject.FindProperty(nameof(WaveSpectrum._ChopScales));
|
||||
var spGravScales = serializedObject.FindProperty(nameof(WaveSpectrum._GravityScales));
|
||||
var spAttenuation = serializedObject.FindProperty(nameof(WaveSpectrum._Attenuation));
|
||||
|
||||
// Disable sliders if authoring with model.
|
||||
var canEditSpectrum = spectrumModel == WaveSpectrum.SpectrumModel.None;
|
||||
@@ -247,7 +272,7 @@ namespace WaveHarmonic.Crest.Editor
|
||||
// Disable slider if authoring with model.
|
||||
using (new EditorGUI.DisabledGroupScope(!canEditSpectrum || spDisabled_i.boolValue))
|
||||
{
|
||||
powerValue = EditorGUILayout.Slider(" Power", powerValue, WaveSpectrum.s_MinimumPowerLog, WaveSpectrum.s_MaximumPowerLog);
|
||||
powerValue = EditorGUILayout.Slider(" Power", powerValue, WaveSpectrum.s_MinimumPowerLog, WaveSpectrum.s_MaximumPowerLog);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -273,8 +298,10 @@ namespace WaveHarmonic.Crest.Editor
|
||||
|
||||
if (showAdvancedControls)
|
||||
{
|
||||
EditorGUILayout.Slider(spChopScales.GetArrayElementAtIndex(i), 0f, 4f, " Chop Scale");
|
||||
EditorGUILayout.Slider(spGravScales.GetArrayElementAtIndex(i), 0f, 4f, " Grav Scale");
|
||||
var timeText = _WaveModel is WaveModel.Gerstner ? " Gravity Scale" : " Time Scale";
|
||||
EditorGUILayout.Slider(spChopScales.GetArrayElementAtIndex(i), 0f, 4f, " Chop Scale");
|
||||
EditorGUILayout.Slider(spGravScales.GetArrayElementAtIndex(i), 0f, 4f, timeText);
|
||||
EditorGUILayout.Slider(spAttenuation.GetArrayElementAtIndex(i), 0f, 1f, " Attenuation Scale");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -289,6 +316,19 @@ namespace WaveHarmonic.Crest.Editor
|
||||
|
||||
EditorGUILayout.Space();
|
||||
EditorGUILayout.HelpBox(s_ModelDescriptions[(int)spectrumModel], MessageType.Info);
|
||||
if (_Host is not null and ShapeWaves waves)
|
||||
{
|
||||
var windSpeedSource = waves.GetWindSpeedSource();
|
||||
|
||||
if (windSpeedSource != ShapeWaves.WindSpeedSource.None)
|
||||
{
|
||||
EditorHelpers.RichTextHelpBox
|
||||
(
|
||||
GetWindSpeedText(waves, windSpeedSource) + GetWindSpeedFixText(windSpeedSource),
|
||||
MessageType.Info
|
||||
);
|
||||
}
|
||||
}
|
||||
EditorGUILayout.Space();
|
||||
|
||||
if (spectrumModel == WaveSpectrum.SpectrumModel.None)
|
||||
@@ -326,6 +366,35 @@ namespace WaveHarmonic.Crest.Editor
|
||||
EditorUtility.SetDirty(spec);
|
||||
}
|
||||
}
|
||||
|
||||
internal override GUIContent OnCustomLabel(SerializedProperty property, GUIContent label, DecoratedDrawer drawer)
|
||||
{
|
||||
label = base.OnCustomLabel(property, label, drawer);
|
||||
|
||||
var isFFT = _WaveModel is WaveModel.FFT;
|
||||
|
||||
if (isFFT && property.name == "_GravityScale")
|
||||
{
|
||||
label.text = "Time Scale";
|
||||
label.tooltip = "More time means faster waves.";
|
||||
}
|
||||
|
||||
return label;
|
||||
}
|
||||
|
||||
internal static string GetWindSpeedText(ShapeWaves target, ShapeWaves.WindSpeedSource source)
|
||||
{
|
||||
var text = source == ShapeWaves.WindSpeedSource.WaterRenderer ? $"the {nameof(WaterRenderer).Pretty().Italic()}" : "this component";
|
||||
return $"The wave spectrum is currently limited by {nameof(ShapeWaves.WindSpeed).Pretty().Italic()} on {text} to {target.WindSpeedKPH} KPH, and will not be fully developed.";
|
||||
}
|
||||
|
||||
internal static string GetWindSpeedFixText(ShapeWaves.WindSpeedSource source)
|
||||
{
|
||||
var text = source == ShapeWaves.WindSpeedSource.WaterRenderer
|
||||
? $"either override the {nameof(ShapeWaves.WindSpeed).Pretty().Italic()} on this component or increase the {nameof(WaterRenderer.WindSpeed).Pretty().Italic()} on the {nameof(WaterRenderer).Pretty().Italic()}"
|
||||
: $"then increase the {nameof(ShapeWaves.WindSpeed).Pretty().Italic()} on this component";
|
||||
return $"If you want fully developed waves (ie large waves), {text}.";
|
||||
}
|
||||
}
|
||||
|
||||
[CustomEditor(typeof(LodSettings), true)]
|
||||
@@ -366,6 +435,7 @@ namespace WaveHarmonic.Crest.Editor
|
||||
var boundsXZ = new Bounds(target._UnexpandedBoundsXZ.center.XNZ(), target._UnexpandedBoundsXZ.size.XNZ());
|
||||
EditorGUILayout.BoundsField("Bounds XZ", boundsXZ);
|
||||
EditorGUILayout.BoundsField("Expanded Bounds", _Renderer.bounds);
|
||||
EditorGUILayout.IntField("Sibling Index", target._SiblingIndex);
|
||||
GUI.enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e7b81340420aa49ed9bd65a5a9c558ad
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,173 @@
|
||||
// <auto-generated/>
|
||||
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
namespace WaveHarmonic.Crest.Editor.Settings
|
||||
{
|
||||
partial class PlatformSettings
|
||||
{
|
||||
public bool AlbedoSimulation => _Default || _OverrideAlbedoSimulation ? _AlbedoSimulation : Default.AlbedoSimulation;
|
||||
public bool AbsorptionSimulation => _Default || _OverrideAbsorptionSimulation ? _AbsorptionSimulation : Default.AbsorptionSimulation;
|
||||
public bool ScatteringSimulation => _Default || _OverrideScatteringSimulation ? _ScatteringSimulation : Default.ScatteringSimulation;
|
||||
public bool ShadowSimulation => _Default || _OverrideShadowSimulation ? _ShadowSimulation : Default.ShadowSimulation;
|
||||
public bool OutScattering => _Default || _OverrideOutScattering ? _OutScattering : Default.OutScattering;
|
||||
public bool NormalMaps => _Default || _OverrideNormalMaps ? _NormalMaps : Default.NormalMaps;
|
||||
public bool PlanarReflections => _Default || _OverridePlanarReflections ? _PlanarReflections : Default.PlanarReflections;
|
||||
public bool PlanarReflectionsApplySmoothness => _Default || _OverridePlanarReflectionsApplySmoothness ? _PlanarReflectionsApplySmoothness : Default.PlanarReflectionsApplySmoothness;
|
||||
public WaveHarmonic.Crest.Editor.Settings.SamplingMethod FoamSampling => _Default || _OverrideFoamSampling ? _FoamSampling : Default.FoamSampling;
|
||||
public bool FoamBioluminescence => _Default || _OverrideFoamBioluminescence ? _FoamBioluminescence : Default.FoamBioluminescence;
|
||||
public bool CausticsForceDistortion => _Default || _OverrideCausticsForceDistortion ? _CausticsForceDistortion : Default.CausticsForceDistortion;
|
||||
public bool AdditionalLights => _Default || _OverrideAdditionalLights ? _AdditionalLights : Default.AdditionalLights;
|
||||
public bool SimpleTransparency => _Default || _OverrideSimpleTransparency ? _SimpleTransparency : Default.SimpleTransparency;
|
||||
}
|
||||
}
|
||||
|
||||
namespace WaveHarmonic.Crest.Editor
|
||||
{
|
||||
partial class ShaderSettingsAndroid
|
||||
{
|
||||
public static int s_CrestAlbedoSimulation = Settings.AlbedoSimulation ? 1 : 0;
|
||||
public static int s_CrestAbsorptionSimulation = Settings.AbsorptionSimulation ? 1 : 0;
|
||||
public static int s_CrestScatteringSimulation = Settings.ScatteringSimulation ? 1 : 0;
|
||||
public static int s_CrestShadowSimulation = Settings.ShadowSimulation ? 1 : 0;
|
||||
public static int s_CrestOutScattering = Settings.OutScattering ? 1 : 0;
|
||||
public static int s_CrestNormalMaps = Settings.NormalMaps ? 1 : 0;
|
||||
public static int s_CrestPlanarReflections = Settings.PlanarReflections ? 1 : 0;
|
||||
public static int s_CrestPlanarReflectionsApplySmoothness = Settings.PlanarReflectionsApplySmoothness ? 1 : 0;
|
||||
public static int s_CrestFoamSamplingMultiScale = Settings.FoamSampling.HasFlag(WaveHarmonic.Crest.Editor.Settings.SamplingMethod.MultiScale) ? 1 : 0;
|
||||
public static int s_CrestFoamSamplingStochastic = Settings.FoamSampling.HasFlag(WaveHarmonic.Crest.Editor.Settings.SamplingMethod.Stochastic) ? 1 : 0;
|
||||
public static int s_CrestFoamBioluminescence = Settings.FoamBioluminescence ? 1 : 0;
|
||||
public static int s_CrestCausticsForceDistortion = Settings.CausticsForceDistortion ? 1 : 0;
|
||||
public static int s_CrestAdditionalLights = Settings.AdditionalLights ? 1 : 0;
|
||||
public static int s_CrestSimpleTransparency = Settings.SimpleTransparency ? 1 : 0;
|
||||
}
|
||||
|
||||
partial class ShaderSettingsDefault
|
||||
{
|
||||
public static int s_CrestAlbedoSimulation = Settings.AlbedoSimulation ? 1 : 0;
|
||||
public static int s_CrestAbsorptionSimulation = Settings.AbsorptionSimulation ? 1 : 0;
|
||||
public static int s_CrestScatteringSimulation = Settings.ScatteringSimulation ? 1 : 0;
|
||||
public static int s_CrestShadowSimulation = Settings.ShadowSimulation ? 1 : 0;
|
||||
public static int s_CrestOutScattering = Settings.OutScattering ? 1 : 0;
|
||||
public static int s_CrestNormalMaps = Settings.NormalMaps ? 1 : 0;
|
||||
public static int s_CrestPlanarReflections = Settings.PlanarReflections ? 1 : 0;
|
||||
public static int s_CrestPlanarReflectionsApplySmoothness = Settings.PlanarReflectionsApplySmoothness ? 1 : 0;
|
||||
public static int s_CrestFoamSamplingMultiScale = Settings.FoamSampling.HasFlag(WaveHarmonic.Crest.Editor.Settings.SamplingMethod.MultiScale) ? 1 : 0;
|
||||
public static int s_CrestFoamSamplingStochastic = Settings.FoamSampling.HasFlag(WaveHarmonic.Crest.Editor.Settings.SamplingMethod.Stochastic) ? 1 : 0;
|
||||
public static int s_CrestFoamBioluminescence = Settings.FoamBioluminescence ? 1 : 0;
|
||||
public static int s_CrestCausticsForceDistortion = Settings.CausticsForceDistortion ? 1 : 0;
|
||||
public static int s_CrestAdditionalLights = Settings.AdditionalLights ? 1 : 0;
|
||||
public static int s_CrestSimpleTransparency = Settings.SimpleTransparency ? 1 : 0;
|
||||
}
|
||||
|
||||
partial class ShaderSettingsIOS
|
||||
{
|
||||
public static int s_CrestAlbedoSimulation = Settings.AlbedoSimulation ? 1 : 0;
|
||||
public static int s_CrestAbsorptionSimulation = Settings.AbsorptionSimulation ? 1 : 0;
|
||||
public static int s_CrestScatteringSimulation = Settings.ScatteringSimulation ? 1 : 0;
|
||||
public static int s_CrestShadowSimulation = Settings.ShadowSimulation ? 1 : 0;
|
||||
public static int s_CrestOutScattering = Settings.OutScattering ? 1 : 0;
|
||||
public static int s_CrestNormalMaps = Settings.NormalMaps ? 1 : 0;
|
||||
public static int s_CrestPlanarReflections = Settings.PlanarReflections ? 1 : 0;
|
||||
public static int s_CrestPlanarReflectionsApplySmoothness = Settings.PlanarReflectionsApplySmoothness ? 1 : 0;
|
||||
public static int s_CrestFoamSamplingMultiScale = Settings.FoamSampling.HasFlag(WaveHarmonic.Crest.Editor.Settings.SamplingMethod.MultiScale) ? 1 : 0;
|
||||
public static int s_CrestFoamSamplingStochastic = Settings.FoamSampling.HasFlag(WaveHarmonic.Crest.Editor.Settings.SamplingMethod.Stochastic) ? 1 : 0;
|
||||
public static int s_CrestFoamBioluminescence = Settings.FoamBioluminescence ? 1 : 0;
|
||||
public static int s_CrestCausticsForceDistortion = Settings.CausticsForceDistortion ? 1 : 0;
|
||||
public static int s_CrestAdditionalLights = Settings.AdditionalLights ? 1 : 0;
|
||||
public static int s_CrestSimpleTransparency = Settings.SimpleTransparency ? 1 : 0;
|
||||
}
|
||||
|
||||
partial class ShaderSettingsServer
|
||||
{
|
||||
public static int s_CrestAlbedoSimulation = Settings.AlbedoSimulation ? 1 : 0;
|
||||
public static int s_CrestAbsorptionSimulation = Settings.AbsorptionSimulation ? 1 : 0;
|
||||
public static int s_CrestScatteringSimulation = Settings.ScatteringSimulation ? 1 : 0;
|
||||
public static int s_CrestShadowSimulation = Settings.ShadowSimulation ? 1 : 0;
|
||||
public static int s_CrestOutScattering = Settings.OutScattering ? 1 : 0;
|
||||
public static int s_CrestNormalMaps = Settings.NormalMaps ? 1 : 0;
|
||||
public static int s_CrestPlanarReflections = Settings.PlanarReflections ? 1 : 0;
|
||||
public static int s_CrestPlanarReflectionsApplySmoothness = Settings.PlanarReflectionsApplySmoothness ? 1 : 0;
|
||||
public static int s_CrestFoamSamplingMultiScale = Settings.FoamSampling.HasFlag(WaveHarmonic.Crest.Editor.Settings.SamplingMethod.MultiScale) ? 1 : 0;
|
||||
public static int s_CrestFoamSamplingStochastic = Settings.FoamSampling.HasFlag(WaveHarmonic.Crest.Editor.Settings.SamplingMethod.Stochastic) ? 1 : 0;
|
||||
public static int s_CrestFoamBioluminescence = Settings.FoamBioluminescence ? 1 : 0;
|
||||
public static int s_CrestCausticsForceDistortion = Settings.CausticsForceDistortion ? 1 : 0;
|
||||
public static int s_CrestAdditionalLights = Settings.AdditionalLights ? 1 : 0;
|
||||
public static int s_CrestSimpleTransparency = Settings.SimpleTransparency ? 1 : 0;
|
||||
}
|
||||
|
||||
partial class ShaderSettingsStandalone
|
||||
{
|
||||
public static int s_CrestAlbedoSimulation = Settings.AlbedoSimulation ? 1 : 0;
|
||||
public static int s_CrestAbsorptionSimulation = Settings.AbsorptionSimulation ? 1 : 0;
|
||||
public static int s_CrestScatteringSimulation = Settings.ScatteringSimulation ? 1 : 0;
|
||||
public static int s_CrestShadowSimulation = Settings.ShadowSimulation ? 1 : 0;
|
||||
public static int s_CrestOutScattering = Settings.OutScattering ? 1 : 0;
|
||||
public static int s_CrestNormalMaps = Settings.NormalMaps ? 1 : 0;
|
||||
public static int s_CrestPlanarReflections = Settings.PlanarReflections ? 1 : 0;
|
||||
public static int s_CrestPlanarReflectionsApplySmoothness = Settings.PlanarReflectionsApplySmoothness ? 1 : 0;
|
||||
public static int s_CrestFoamSamplingMultiScale = Settings.FoamSampling.HasFlag(WaveHarmonic.Crest.Editor.Settings.SamplingMethod.MultiScale) ? 1 : 0;
|
||||
public static int s_CrestFoamSamplingStochastic = Settings.FoamSampling.HasFlag(WaveHarmonic.Crest.Editor.Settings.SamplingMethod.Stochastic) ? 1 : 0;
|
||||
public static int s_CrestFoamBioluminescence = Settings.FoamBioluminescence ? 1 : 0;
|
||||
public static int s_CrestCausticsForceDistortion = Settings.CausticsForceDistortion ? 1 : 0;
|
||||
public static int s_CrestAdditionalLights = Settings.AdditionalLights ? 1 : 0;
|
||||
public static int s_CrestSimpleTransparency = Settings.SimpleTransparency ? 1 : 0;
|
||||
}
|
||||
|
||||
partial class ShaderSettingsTVOS
|
||||
{
|
||||
public static int s_CrestAlbedoSimulation = Settings.AlbedoSimulation ? 1 : 0;
|
||||
public static int s_CrestAbsorptionSimulation = Settings.AbsorptionSimulation ? 1 : 0;
|
||||
public static int s_CrestScatteringSimulation = Settings.ScatteringSimulation ? 1 : 0;
|
||||
public static int s_CrestShadowSimulation = Settings.ShadowSimulation ? 1 : 0;
|
||||
public static int s_CrestOutScattering = Settings.OutScattering ? 1 : 0;
|
||||
public static int s_CrestNormalMaps = Settings.NormalMaps ? 1 : 0;
|
||||
public static int s_CrestPlanarReflections = Settings.PlanarReflections ? 1 : 0;
|
||||
public static int s_CrestPlanarReflectionsApplySmoothness = Settings.PlanarReflectionsApplySmoothness ? 1 : 0;
|
||||
public static int s_CrestFoamSamplingMultiScale = Settings.FoamSampling.HasFlag(WaveHarmonic.Crest.Editor.Settings.SamplingMethod.MultiScale) ? 1 : 0;
|
||||
public static int s_CrestFoamSamplingStochastic = Settings.FoamSampling.HasFlag(WaveHarmonic.Crest.Editor.Settings.SamplingMethod.Stochastic) ? 1 : 0;
|
||||
public static int s_CrestFoamBioluminescence = Settings.FoamBioluminescence ? 1 : 0;
|
||||
public static int s_CrestCausticsForceDistortion = Settings.CausticsForceDistortion ? 1 : 0;
|
||||
public static int s_CrestAdditionalLights = Settings.AdditionalLights ? 1 : 0;
|
||||
public static int s_CrestSimpleTransparency = Settings.SimpleTransparency ? 1 : 0;
|
||||
}
|
||||
|
||||
partial class ShaderSettingsVisionOS
|
||||
{
|
||||
public static int s_CrestAlbedoSimulation = Settings.AlbedoSimulation ? 1 : 0;
|
||||
public static int s_CrestAbsorptionSimulation = Settings.AbsorptionSimulation ? 1 : 0;
|
||||
public static int s_CrestScatteringSimulation = Settings.ScatteringSimulation ? 1 : 0;
|
||||
public static int s_CrestShadowSimulation = Settings.ShadowSimulation ? 1 : 0;
|
||||
public static int s_CrestOutScattering = Settings.OutScattering ? 1 : 0;
|
||||
public static int s_CrestNormalMaps = Settings.NormalMaps ? 1 : 0;
|
||||
public static int s_CrestPlanarReflections = Settings.PlanarReflections ? 1 : 0;
|
||||
public static int s_CrestPlanarReflectionsApplySmoothness = Settings.PlanarReflectionsApplySmoothness ? 1 : 0;
|
||||
public static int s_CrestFoamSamplingMultiScale = Settings.FoamSampling.HasFlag(WaveHarmonic.Crest.Editor.Settings.SamplingMethod.MultiScale) ? 1 : 0;
|
||||
public static int s_CrestFoamSamplingStochastic = Settings.FoamSampling.HasFlag(WaveHarmonic.Crest.Editor.Settings.SamplingMethod.Stochastic) ? 1 : 0;
|
||||
public static int s_CrestFoamBioluminescence = Settings.FoamBioluminescence ? 1 : 0;
|
||||
public static int s_CrestCausticsForceDistortion = Settings.CausticsForceDistortion ? 1 : 0;
|
||||
public static int s_CrestAdditionalLights = Settings.AdditionalLights ? 1 : 0;
|
||||
public static int s_CrestSimpleTransparency = Settings.SimpleTransparency ? 1 : 0;
|
||||
}
|
||||
|
||||
partial class ShaderSettingsWeb
|
||||
{
|
||||
public static int s_CrestAlbedoSimulation = Settings.AlbedoSimulation ? 1 : 0;
|
||||
public static int s_CrestAbsorptionSimulation = Settings.AbsorptionSimulation ? 1 : 0;
|
||||
public static int s_CrestScatteringSimulation = Settings.ScatteringSimulation ? 1 : 0;
|
||||
public static int s_CrestShadowSimulation = Settings.ShadowSimulation ? 1 : 0;
|
||||
public static int s_CrestOutScattering = Settings.OutScattering ? 1 : 0;
|
||||
public static int s_CrestNormalMaps = Settings.NormalMaps ? 1 : 0;
|
||||
public static int s_CrestPlanarReflections = Settings.PlanarReflections ? 1 : 0;
|
||||
public static int s_CrestPlanarReflectionsApplySmoothness = Settings.PlanarReflectionsApplySmoothness ? 1 : 0;
|
||||
public static int s_CrestFoamSamplingMultiScale = Settings.FoamSampling.HasFlag(WaveHarmonic.Crest.Editor.Settings.SamplingMethod.MultiScale) ? 1 : 0;
|
||||
public static int s_CrestFoamSamplingStochastic = Settings.FoamSampling.HasFlag(WaveHarmonic.Crest.Editor.Settings.SamplingMethod.Stochastic) ? 1 : 0;
|
||||
public static int s_CrestFoamBioluminescence = Settings.FoamBioluminescence ? 1 : 0;
|
||||
public static int s_CrestCausticsForceDistortion = Settings.CausticsForceDistortion ? 1 : 0;
|
||||
public static int s_CrestAdditionalLights = Settings.AdditionalLights ? 1 : 0;
|
||||
public static int s_CrestSimpleTransparency = Settings.SimpleTransparency ? 1 : 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a76b369d4084d4397a84d1586f34c0d2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -132,6 +132,25 @@ namespace WaveHarmonic.Crest.Editor
|
||||
}
|
||||
}
|
||||
|
||||
[DrawGizmo(GizmoType.Selected)]
|
||||
static void DrawGizmos(LevelLodInput target, GizmoType type)
|
||||
{
|
||||
if (!target.Enabled) return;
|
||||
if (target.Data is not LodInputData data) return;
|
||||
|
||||
var bounds = data.Bounds;
|
||||
|
||||
if (target.OverrideHeight)
|
||||
{
|
||||
var minimum = target.HeightRange.x;
|
||||
var maximum = target.HeightRange.y;
|
||||
bounds.size = bounds.size.XNZ(Mathf.Abs(minimum - maximum));
|
||||
bounds.center = bounds.center.XNZ(Mathf.Lerp(minimum, maximum, 0.5f));
|
||||
}
|
||||
|
||||
bounds.GizmosDraw();
|
||||
}
|
||||
|
||||
[DrawGizmo(GizmoType.Selected)]
|
||||
static void DrawWatertightHullGizmos(WatertightHull target, GizmoType type)
|
||||
{
|
||||
@@ -317,9 +336,12 @@ namespace WaveHarmonic.Crest.Editor
|
||||
[DrawGizmo(GizmoType.Selected | GizmoType.NonSelected)]
|
||||
static void DrawGizmos(WaterChunkRenderer target, GizmoType type)
|
||||
{
|
||||
if (target._DrawRenderBounds)
|
||||
if ((target._DrawRenderBounds || type.HasFlag(GizmoType.Selected)) && target.Rend != null)
|
||||
{
|
||||
Gizmos.color = type.HasFlag(GizmoType.Selected) ? Color.green : Color.white;
|
||||
Handles.Label(target.transform.position, $"{target._LodIndex},{target._SiblingIndex}");
|
||||
target.Rend.bounds.GizmosDraw();
|
||||
Gizmos.color = Color.white;
|
||||
}
|
||||
|
||||
if (!type.HasFlag(GizmoType.Selected))
|
||||
@@ -327,11 +349,6 @@ namespace WaveHarmonic.Crest.Editor
|
||||
return;
|
||||
}
|
||||
|
||||
if (target.Rend != null)
|
||||
{
|
||||
target.Rend.bounds.GizmosDraw();
|
||||
}
|
||||
|
||||
if (WaterBody.WaterBodies.Count > 0)
|
||||
{
|
||||
Gizmos.color = Color.green;
|
||||
|
||||
@@ -6,20 +6,23 @@
|
||||
using Gaia;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using WaveHarmonic.Crest.ShallowWater;
|
||||
|
||||
namespace WaveHarmonic.Crest
|
||||
{
|
||||
sealed class GRC_Crest : GaiaRuntimeComponent
|
||||
{
|
||||
#pragma warning disable CS0414
|
||||
[SerializeField]
|
||||
bool _Wind = true;
|
||||
#pragma warning restore CS0414
|
||||
|
||||
[SerializeField]
|
||||
bool _Swell = true;
|
||||
|
||||
#pragma warning disable CS0414
|
||||
[SerializeField]
|
||||
bool _ShallowWater = true;
|
||||
#pragma warning restore CS0414
|
||||
|
||||
GUIContent _HelpLink;
|
||||
GUIContent _PanelLabel;
|
||||
@@ -67,8 +70,10 @@ namespace WaveHarmonic.Crest
|
||||
_Swell = EditorGUILayout.Toggle("Swell Waves", _Swell);
|
||||
DisplayHelp("Whether to add swell waves to the scene. Swell waves will come from conditions far away from the scene. Modify the component after creation to customize.");
|
||||
|
||||
#if d_UnityModuleWind
|
||||
_Wind = EditorGUILayout.Toggle("Wind Waves", _Wind);
|
||||
DisplayHelp("Whether to add wind waves to the scene. These waves are based on local wind conditions. Requires Gaia's Wind Zone (note that the defaul wind value will produce no waves). Modify the component after creation to customize.");
|
||||
#endif
|
||||
|
||||
#if d_WaveHarmonic_Crest_ShallowWater
|
||||
_ShallowWater = EditorGUILayout.Toggle("Shoreline Simulation", _ShallowWater);
|
||||
@@ -94,7 +99,7 @@ namespace WaveHarmonic.Crest
|
||||
public override void AddToScene()
|
||||
{
|
||||
// Re-initialize to keep user's changes.
|
||||
var water = FindFirstObjectByType<WaterRenderer>(FindObjectsInactive.Include);
|
||||
var water = FindAnyObjectByType<WaterRenderer>(FindObjectsInactive.Include);
|
||||
|
||||
if (water == null)
|
||||
{
|
||||
@@ -115,21 +120,23 @@ namespace WaveHarmonic.Crest
|
||||
|
||||
managed.SetParent(water.transform, worldPositionStays: false);
|
||||
|
||||
#if d_UnityModuleWind
|
||||
// Wind
|
||||
if (_Wind)
|
||||
{
|
||||
var wind = FindFirstObjectByType<WindManager>();
|
||||
var wind = FindAnyObjectByType<WindManager>();
|
||||
|
||||
if (wind != null)
|
||||
{
|
||||
water.WindZone = wind.GetComponent<WindZone>();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// Depth
|
||||
water.DepthLod.IncludeTerrainHeight = false;
|
||||
|
||||
foreach (var terrain in FindObjectsByType<Terrain>(FindObjectsInactive.Include, FindObjectsSortMode.None))
|
||||
foreach (var terrain in Helpers.FindObjectsByType<Terrain>(FindObjectsInactive.Include))
|
||||
{
|
||||
var dp = terrain.GetComponentInChildren<DepthProbe>(includeInactive: true);
|
||||
|
||||
@@ -152,12 +159,14 @@ namespace WaveHarmonic.Crest
|
||||
dp.Populate();
|
||||
}
|
||||
|
||||
#if d_UnityModuleWind
|
||||
// Wind Waves
|
||||
if (_Wind && water.WindZone != null)
|
||||
{
|
||||
GetOrAddComponentToScene<ShapeFFT>(managed, "WaterWindWaves", out _);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
RemoveComponentFromScene<ShapeFFT>(managed);
|
||||
}
|
||||
@@ -193,7 +202,7 @@ namespace WaveHarmonic.Crest
|
||||
{
|
||||
water.FlowLod.Enabled = true;
|
||||
|
||||
if (GetOrAddComponentToScene<ShallowWaterSimulation>(managed, "ShorelineSimulation", out var sws))
|
||||
if (GetOrAddComponentToScene<ShallowWater.ShallowWaterSimulation>(managed, "ShorelineSimulation", out var sws))
|
||||
{
|
||||
water.Surface.Material = AssetDatabase.LoadAssetAtPath<Material>("Packages/com.waveharmonic.crest/Runtime/Materials/Water (Flow).mat");
|
||||
sws.Width = 256;
|
||||
@@ -206,13 +215,13 @@ namespace WaveHarmonic.Crest
|
||||
|
||||
dp.GenerateSignedDistanceField = false;
|
||||
|
||||
sws.Preset = ShallowWaterSimulationPreset.Shoreline;
|
||||
sws.Preset = ShallowWater.ShallowWaterSimulationPreset.Shoreline;
|
||||
sws.Placement = Placement.Viewpoint;
|
||||
sws.DynamicSeabed = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
RemoveComponentFromScene<ShallowWaterSimulation>(managed);
|
||||
RemoveComponentFromScene<ShallowWater.ShallowWaterSimulation>(managed);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -246,10 +255,10 @@ namespace WaveHarmonic.Crest
|
||||
/// <inheritdoc/>
|
||||
public override void RemoveFromScene()
|
||||
{
|
||||
var water = FindFirstObjectByType<WaterRenderer>(FindObjectsInactive.Include);
|
||||
var water = FindAnyObjectByType<WaterRenderer>(FindObjectsInactive.Include);
|
||||
if (water != null) DestroyImmediate(water.gameObject);
|
||||
|
||||
foreach (var terrain in FindObjectsByType<Terrain>(FindObjectsInactive.Include, FindObjectsSortMode.None))
|
||||
foreach (var terrain in Helpers.FindObjectsByType<Terrain>(FindObjectsInactive.Include))
|
||||
{
|
||||
var depthCache = terrain.GetComponentInChildren<DepthProbe>(includeInactive: true);
|
||||
if (depthCache != null) DestroyImmediate(depthCache.gameObject);
|
||||
|
||||
@@ -22,6 +22,11 @@
|
||||
"GAIA_2023"
|
||||
],
|
||||
"versionDefines": [
|
||||
{
|
||||
"name": "com.unity.modules.wind",
|
||||
"expression": "",
|
||||
"define": "d_UnityModuleWind"
|
||||
},
|
||||
{
|
||||
"name": "com.waveharmonic.crest.shallow-water",
|
||||
"expression": "",
|
||||
|
||||
@@ -7,6 +7,7 @@ using UnityEditor;
|
||||
using UnityEditor.Rendering;
|
||||
using UnityEditor.Rendering.HighDefinition;
|
||||
using UnityEngine;
|
||||
using WaveHarmonic.Crest.Editor.Settings;
|
||||
|
||||
namespace WaveHarmonic.Crest.Editor
|
||||
{
|
||||
@@ -27,6 +28,13 @@ namespace WaveHarmonic.Crest.Editor
|
||||
{ "_Crest_HeightsOnly", "Treats the texture as a heightmap and reads from the R channel" },
|
||||
}
|
||||
},
|
||||
{
|
||||
"Crest/Inputs/Dynamic Waves/Add Bump", new()
|
||||
{
|
||||
{ "_Crest_Amplitude", "The vertical radius of the bump. How much the surface will rise or fall." },
|
||||
{ "_Crest_Radius", "The horizontal radius of the bump." },
|
||||
}
|
||||
},
|
||||
{
|
||||
"Crest/Inputs/Flow/Add From Texture", new()
|
||||
{
|
||||
@@ -66,16 +74,24 @@ namespace WaveHarmonic.Crest.Editor
|
||||
WaterShaderUtility.k_ShaderName, new()
|
||||
{
|
||||
{ "_Crest_NormalsStrengthOverall", "Strength of the final surface normal (both wave normal and normal map)" },
|
||||
{ "_Crest_ApplyDisplacementNormals", "Whether to sample the displacement maps (Animated Waves and Dynamic Waves) for normal contributions." },
|
||||
{ "_Crest_NormalMapEnabled", "Whether to add normal detail from a texture. Can be used to add visual detail to the water surface" },
|
||||
{ "_Crest_NormalMapTexture", "Normal map texture" },
|
||||
{ "_Crest_NormalMapStrength", "Strength of normal map influence" },
|
||||
{ "_Crest_NormalMapScale", "Base scale of multi-scale normal map texture" },
|
||||
{ "_Crest_NormalMapScrollSpeed", "Speed of the normal maps scrolling" },
|
||||
{ "_Crest_NormalMapTurbulenceEnabled", "Increase chance of sparkles where water is turbulent" },
|
||||
{ "_Crest_NormalMapTurbulenceStrength", "Strength of the normal map influence where turbulent" },
|
||||
{ "_Crest_NormalMapTurbulenceCoverage", "The threshold where turbulence triggers this effect.\n\nValues above 0.9 may be too high for calmer wave conditions, as it will trigger the effect where water is not turbulent. Furthermore, a value of one or very close one can cause a pop when weighing out waves to zero" },
|
||||
{ "_Crest_AbsorptionColor", "Works as a color (ie red adds red rather than subtracts red). This value is converted to real absorption values (proportion of light getting absorbed by water in atoms per meter). Alpha channel is for density. High alpha and darker color reduces transparency" },
|
||||
{ "_Crest_Scattering", "Light scattered by the water towards the viewer (in-scattered) per meter. Brighter color reduces transparency" },
|
||||
{ "_Crest_Anisotropy", "The directionality of the scattering where zero means scattered in all directions. The further towards one, the less visible soft shadows will be" },
|
||||
{ "_Crest_DirectTerm", "Scale direct light contribution to volume lighting" },
|
||||
{ "_Crest_DirectTermAdditional", "Scale additional lights contribution to volume lighting" },
|
||||
{ "_Crest_AmbientTerm", "Scale ambient light contribution to volume lighting" },
|
||||
{ "_Crest_ShadowsAffectsAmbientFactor", "How much shadows affect ambient lighting. Typically this not required, but can help scenes with large shadowed areas" },
|
||||
{ "_Crest_AdditionalLightsBlend", "How much the additional light contributions blend with scattering." },
|
||||
{ "_Crest_ApplyFresnelToVolumeLighting", "Applies the fresnel to volume lighting to help the surface blend with the horizon in the form of being a mirror. Typically, only suitable with full smoothness (unless skybox is designed for water rather than earth)." },
|
||||
{ "_Crest_SSSEnabled", "Whether to to emulate light scattering through waves" },
|
||||
{ "_Crest_SSSIntensity", "Direct light contribution intensity. Applied to the scattering color. This effect is best if subtle" },
|
||||
{ "_Crest_SSSPinchMinimum", "Higher the value the more scattering is towards the peaks of the waves" },
|
||||
@@ -85,6 +101,7 @@ namespace WaveHarmonic.Crest.Editor
|
||||
{ "_Crest_Specular", "Strength of specular lighting response" },
|
||||
{ "_Crest_Occlusion", "Strength of reflection" },
|
||||
{ "_Crest_OcclusionUnderwater", "Strength of reflection when underwater. Keep this at zero to avoid skybox reflections which look incorrect when underwater, unless you want reflections from Planar Reflections or probes" },
|
||||
{ "_Crest_Fresnel", "The fresnel power. Decrease to increase strength of reflections." },
|
||||
{ "_Crest_Smoothness", "Smoothness of surface. A value of one is ideal for flat water only" },
|
||||
{ "_Crest_SmoothnessFar", "Material smoothness at far distance from camera. Helps to spread out specular highlight in mid-to-background. From a theory point of view, models transfer of normal detail to microfacets in BRDF" },
|
||||
{ "_Crest_SmoothnessFarDistance", "Definition of far distance" },
|
||||
@@ -93,6 +110,7 @@ namespace WaveHarmonic.Crest.Editor
|
||||
{ "_Crest_PlanarReflectionsEnabled", "Dynamically rendered 'reflection plane' style reflections. Requires Reflections to be enabled on the Water Renderer" },
|
||||
{ "_Crest_PlanarReflectionsIntensity", "Intensity of the planar reflections" },
|
||||
{ "_Crest_PlanarReflectionsDistortion", "How much the water normal affects the planar reflection" },
|
||||
{ "_Crest_PlanarReflectionsApplySmoothness", "Whether to apply smoothness to planar reflection sample via mip-map blending. Enabling will likely incur artifacts with most perturbed water" },
|
||||
{ "_Crest_PlanarReflectionsRoughness", "Controls the mipmap range" },
|
||||
{ "_Crest_RefractionStrength", "How strongly light is refracted when passing through water surface" },
|
||||
{ "_Crest_RefractiveIndexOfWater", "Index of refraction of water - typically left at 1.333. Changing this value can increase/decrease the size of the Snell's window" },
|
||||
@@ -107,6 +125,16 @@ namespace WaveHarmonic.Crest.Editor
|
||||
{ "_Crest_FoamIntensityAlbedo", "Scale intensity of diffuse lighting" },
|
||||
{ "_Crest_FoamSmoothness", "Smoothness of foam material" },
|
||||
{ "_Crest_FoamNormalStrength", "Strength of the generated normals" },
|
||||
{ "_Crest_FoamBioluminescenceEnabled", "Enables a foam-based bioluminescence. This reuses the foam sample" },
|
||||
{ "_Crest_FoamBioluminescenceColor", "The color and intensity of the bioluminescence" },
|
||||
{ "_Crest_FoamBioluminescenceIntensity", "The intensity of the bioluminescent foam" },
|
||||
{ "_Crest_FoamBioluminescenceMaximumDepth", "The maximum water depth where bioluminescence can appear. This can be used to keep bioluminescence localized to the shoreline" },
|
||||
{ "_Crest_FoamBioluminescenceSeaLevelOnly", "Only render foam bioluminescence at sea level. This will fade bioluminescence to be fully gone at 1m from sea level." },
|
||||
{ "_Crest_FoamBioluminescenceGlowIntensity", "The intensity of the bioluminescent glow" },
|
||||
{ "_Crest_FoamBioluminescenceGlowCoverage", "The coverage of the bioluminescent glow. Glow is based on raw foam data which makes it more present than foam" },
|
||||
{ "_Crest_FoamBioluminescenceSparklesEnabled", "Whether to apply bioluminescent sparkles. This uses the green channel of the foam texture as an emissive map" },
|
||||
{ "_Crest_FoamBioluminescenceSparklesIntensity", "The intensity of the bioluminescent sparkles" },
|
||||
{ "_Crest_FoamBioluminescenceSparklesCoverage", "The coverage of the bioluminescent sparkles. Sparkles placement is based on raw foam data which makes it more present than foam" },
|
||||
{ "_Crest_CausticsEnabled", "Approximate rays being focused/defocused on underwater surfaces" },
|
||||
{ "_Crest_CausticsTexture", "Caustics texture" },
|
||||
{ "_Crest_CausticsStrength", "Intensity of caustics effect" },
|
||||
@@ -115,13 +143,15 @@ namespace WaveHarmonic.Crest.Editor
|
||||
{ "_Crest_CausticsTextureAverage", "The 'mid' value of the caustics texture, around which the caustic texture values are scaled. Decreasing this value will reduce the caustics darkening underwater surfaces" },
|
||||
{ "_Crest_CausticsFocalDepth", "The depth at which the caustics are in focus" },
|
||||
{ "_Crest_CausticsDepthOfField", "The range of depths over which the caustics are in focus" },
|
||||
{ "_Crest_CausticsForceDistortion", "Forces the distortion texture to be applied for above water. This can be used to distort caustics even when there is no waves" },
|
||||
{ "_Crest_CausticsDistortionTexture", "Texture to distort caustics. Only applicable to underwater effect for now" },
|
||||
{ "_Crest_CausticsDistortionStrength", "How much the caustics texture is distorted" },
|
||||
{ "_Crest_CausticsDistortionScale", "The scale of the distortion pattern used to distort the caustics" },
|
||||
{ "_Crest_CausticsMotionBlur", "How much caustics are blurred when advected by flow" },
|
||||
{ "CREST_FLOW", "Flow is horizontal motion of water. Flow must be enabled on the Water Renderer to generate flow data" },
|
||||
{ "_CREST_FLOW_LOD", "Flow is horizontal motion of water. Flow must be enabled on the Water Renderer to generate flow data" },
|
||||
{ "_Crest_AlbedoEnabled", "Enable the Albedo simulation layer. Albedo must be enabled on the Water" },
|
||||
{ "_Crest_AlbedoIgnoreFoam", "Whether Albedo renders over the top of foam or not." },
|
||||
{ "_Crest_TransparencyMinimumAlpha", "The minimum alpha value for transparency. Makes water contribution to the final image stronger instead of the scene behind it" },
|
||||
}
|
||||
},
|
||||
};
|
||||
@@ -147,6 +177,25 @@ namespace WaveHarmonic.Crest.Editor
|
||||
}
|
||||
}
|
||||
|
||||
internal static readonly List<string> s_HiddenCategories = new();
|
||||
static bool s_Initialized;
|
||||
internal static void FilterCategories()
|
||||
{
|
||||
// Only need to do it once after compile.
|
||||
if (s_Initialized)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var settings = ProjectSettings.Instance.CurrentPlatformSettings;
|
||||
s_HiddenCategories.Clear();
|
||||
if (!settings.AlbedoSimulation) s_HiddenCategories.Add("Albedo");
|
||||
if (!settings.FoamBioluminescence) s_HiddenCategories.Add("Bioluminescence");
|
||||
if (!settings.PlanarReflections) s_HiddenCategories.Add("Reflections (Planar)");
|
||||
if (!settings.SimpleTransparency) s_HiddenCategories.Add("Simple Transparency");
|
||||
s_Initialized = true;
|
||||
}
|
||||
|
||||
internal static MaterialProperty[] FilterProperties(MaterialProperty[] properties)
|
||||
{
|
||||
// Show specular control.
|
||||
@@ -166,9 +215,25 @@ namespace WaveHarmonic.Crest.Editor
|
||||
}
|
||||
#endif
|
||||
|
||||
return properties
|
||||
.Where(x => (specular || x.name != "_Crest_Specular") && x.name != "_Crest_Absorption")
|
||||
.ToArray();
|
||||
var settings = ProjectSettings.Instance.CurrentPlatformSettings;
|
||||
var filtered = properties.Where(x => (specular || x.name != "_Crest_Specular") && x.name != "_Crest_Absorption");
|
||||
|
||||
if (!settings.CausticsForceDistortion)
|
||||
{
|
||||
filtered = filtered.Where(x => x.name != "_Crest_CausticsForceDistortion");
|
||||
}
|
||||
|
||||
if (!settings.NormalMaps)
|
||||
{
|
||||
filtered = filtered.Where(x => !x.name.StartsWithNoAlloc("_Crest_NormalMap"));
|
||||
}
|
||||
|
||||
if (!settings.ShadowSimulation)
|
||||
{
|
||||
filtered = filtered.Where(x => x.name != "_Crest_ShadowsAffectsAmbientFactor");
|
||||
}
|
||||
|
||||
return filtered.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -232,7 +297,8 @@ namespace WaveHarmonic.Crest.Editor
|
||||
|
||||
protected override void DrawSurfaceInputs(Material material)
|
||||
{
|
||||
ShaderGraphPropertyDrawers.DrawShaderGraphGUI(_Editor, _Properties, MaterialTooltips.s_Grouped[_ShaderName]);
|
||||
WaterShaderUtility.FilterCategories();
|
||||
ShaderGraphPropertyDrawers.DrawShaderGraphGUI(_Editor, _Properties, MaterialTooltips.s_Grouped[_ShaderName], WaterShaderUtility.s_HiddenCategories);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -274,7 +340,8 @@ namespace WaveHarmonic.Crest.Editor
|
||||
|
||||
public override void DrawSurfaceInputs(Material material)
|
||||
{
|
||||
ShaderGraphPropertyDrawers.DrawShaderGraphGUI(_Editor, _Properties, MaterialTooltips.s_Grouped[_ShaderName]);
|
||||
WaterShaderUtility.FilterCategories();
|
||||
ShaderGraphPropertyDrawers.DrawShaderGraphGUI(_Editor, _Properties, MaterialTooltips.s_Grouped[_ShaderName], WaterShaderUtility.s_HiddenCategories);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -307,8 +374,10 @@ namespace WaveHarmonic.Crest.Editor
|
||||
return;
|
||||
}
|
||||
|
||||
WaterShaderUtility.FilterCategories();
|
||||
|
||||
var name = (materialEditor.customShaderGUI as HighDefinitionCustomShaderGUI)._ShaderName;
|
||||
ShaderGraphPropertyDrawers.DrawShaderGraphGUI(materialEditor, properties, MaterialTooltips.s_Grouped[name]);
|
||||
ShaderGraphPropertyDrawers.DrawShaderGraphGUI(materialEditor, properties, MaterialTooltips.s_Grouped[name], WaterShaderUtility.s_HiddenCategories);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,238 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using WaveHarmonic.Crest.Editor.Settings;
|
||||
|
||||
namespace WaveHarmonic.Crest.Editor
|
||||
{
|
||||
static partial class MaterialUpgrader
|
||||
{
|
||||
[InitializeOnLoadMethod]
|
||||
static void OnLoad()
|
||||
{
|
||||
EditorApplication.update += OnEditorUpdate;
|
||||
}
|
||||
|
||||
static void OnEditorUpdate()
|
||||
{
|
||||
if (Time.renderedFrameCount <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (EditorApplication.isUpdating)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (ProjectSettings.Instance._MaterialVersion > 0)
|
||||
{
|
||||
EditorApplication.update -= OnEditorUpdate;
|
||||
return;
|
||||
}
|
||||
|
||||
UpgradeMaterials(force: false);
|
||||
|
||||
EditorApplication.update -= OnEditorUpdate;
|
||||
}
|
||||
|
||||
[MenuItem("Edit/Crest/Materials/Upgrade Materials")]
|
||||
static void OnMenuSelect()
|
||||
{
|
||||
UpgradeMaterials(force: true);
|
||||
}
|
||||
|
||||
static void UpgradeMaterials(bool force)
|
||||
{
|
||||
var dirty = false;
|
||||
var version = force ? 0 : ProjectSettings.Instance._MaterialVersion;
|
||||
|
||||
AssetDatabase.StartAssetEditing();
|
||||
try
|
||||
{
|
||||
foreach (var guid in AssetDatabase.FindAssets("t:Material"))
|
||||
{
|
||||
var material = AssetDatabase.LoadAssetAtPath<Material>(AssetDatabase.GUIDToAssetPath(guid));
|
||||
dirty |= UpgradeMaterial(material, version);
|
||||
}
|
||||
|
||||
ProjectSettings.Instance._MaterialVersion = k_MaterialVersion;
|
||||
ProjectSettings.Save();
|
||||
|
||||
if (dirty)
|
||||
{
|
||||
AssetDatabase.SaveAssets();
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
AssetDatabase.StopAssetEditing();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static partial class MaterialUpgrader
|
||||
{
|
||||
enum SerializedType
|
||||
{
|
||||
Boolean,
|
||||
Integer,
|
||||
Float,
|
||||
Vector,
|
||||
Color,
|
||||
Texture,
|
||||
Keyword,
|
||||
}
|
||||
|
||||
static bool TryFindBase(SerializedObject material, SerializedType type, out SerializedProperty propertyBase)
|
||||
{
|
||||
propertyBase = material.FindProperty("m_SavedProperties");
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case SerializedType.Integer:
|
||||
propertyBase = propertyBase.FindPropertyRelative("m_Ints");
|
||||
return true;
|
||||
case SerializedType.Boolean:
|
||||
case SerializedType.Float:
|
||||
propertyBase = propertyBase.FindPropertyRelative("m_Floats");
|
||||
return true;
|
||||
case SerializedType.Color:
|
||||
case SerializedType.Vector:
|
||||
propertyBase = propertyBase.FindPropertyRelative("m_Colors");
|
||||
return true;
|
||||
case SerializedType.Texture:
|
||||
propertyBase = propertyBase.FindPropertyRelative("m_TexEnvs");
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static SerializedProperty FindBase(SerializedObject material, SerializedType type)
|
||||
{
|
||||
if (!TryFindBase(material, type, out var root))
|
||||
{
|
||||
throw new System.ArgumentException($"Unknown SerializedType {type}");
|
||||
}
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
static bool TryFindProperty(SerializedObject material, string name, SerializedType type, out SerializedProperty property, out int index, SerializedProperty root)
|
||||
{
|
||||
var isKeyword = type == SerializedType.Keyword;
|
||||
|
||||
property = null;
|
||||
var size = root.arraySize;
|
||||
for (index = 0; index < size; ++index)
|
||||
{
|
||||
property = root.GetArrayElementAtIndex(index);
|
||||
if (isKeyword ? property.stringValue == name : property.FindPropertyRelative("first").stringValue == name)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (index == size)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!isKeyword)
|
||||
{
|
||||
property = property.FindPropertyRelative("second");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool TryFindProperty(SerializedObject material, string name, SerializedType type, out SerializedProperty property, out int index, out SerializedProperty root)
|
||||
{
|
||||
if (type == SerializedType.Keyword)
|
||||
{
|
||||
root = material.FindProperty("m_ValidKeywords");
|
||||
if (TryFindProperty(material, name, type, out property, out index, root))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
root = material.FindProperty("m_InvalidKeywords");
|
||||
if (TryFindProperty(material, name, type, out property, out index, root))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
root = FindBase(material, type);
|
||||
return TryFindProperty(material, name, type, out property, out index, root);
|
||||
}
|
||||
|
||||
static bool RenameFloat(SerializedObject so, Material material, string old, string @new)
|
||||
{
|
||||
if (!TryFindProperty(so, old, SerializedType.Float, out var oldProperty, out var oldIndex, out var parent))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var oldValue = oldProperty.floatValue;
|
||||
parent.DeleteArrayElementAtIndex(oldIndex);
|
||||
parent.InsertArrayElementAtIndex(0);
|
||||
var newProperty = parent.GetArrayElementAtIndex(0);
|
||||
newProperty.FindPropertyRelative("first").stringValue = @new;
|
||||
newProperty.FindPropertyRelative("second").floatValue = oldValue;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool RenameKeyword(SerializedObject so, Material material, string old, string @new)
|
||||
{
|
||||
if (!TryFindProperty(so, old, SerializedType.Keyword, out var oldProperty, out var oldIndex, out var parent))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
parent.DeleteArrayElementAtIndex(oldIndex);
|
||||
parent.InsertArrayElementAtIndex(0);
|
||||
var keyword = parent.GetArrayElementAtIndex(0);
|
||||
keyword.stringValue = @new;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Upgrades
|
||||
static partial class MaterialUpgrader
|
||||
{
|
||||
public const int k_MaterialVersion = 1;
|
||||
|
||||
static bool UpgradeMaterial(Material material, int version)
|
||||
{
|
||||
var so = new SerializedObject(material);
|
||||
var dirty = false;
|
||||
|
||||
// Upgrade materials.
|
||||
// Version is for all materials.
|
||||
if (version < 1)
|
||||
{
|
||||
switch (material.shader.name)
|
||||
{
|
||||
case "Crest/Water":
|
||||
dirty |= RenameKeyword(so, material, "CREST_FLOW_ON", "_CREST_FLOW_LOD");
|
||||
dirty |= RenameFloat(so, material, "CREST_FLOW", "_CREST_FLOW_LOD");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (dirty)
|
||||
{
|
||||
so.ApplyModifiedPropertiesWithoutUndo();
|
||||
EditorUtility.SetDirty(material);
|
||||
}
|
||||
|
||||
return dirty;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c96ae7831f600451a8b0c5326b10ac54
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -2,6 +2,7 @@
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using WaveHarmonic.Crest.Editor.Settings;
|
||||
|
||||
namespace WaveHarmonic.Crest.Editor
|
||||
{
|
||||
@@ -29,6 +30,21 @@ namespace WaveHarmonic.Crest.Editor
|
||||
_ => throw new System.NotImplementedException(),
|
||||
};
|
||||
|
||||
internal bool GetProjectSettingToggle() => PropertyName switch
|
||||
{
|
||||
nameof(WaterRenderer._AbsorptionLod) => ProjectSettings.Instance.CurrentPlatformSettings.AbsorptionSimulation,
|
||||
nameof(WaterRenderer._AlbedoLod) => ProjectSettings.Instance.CurrentPlatformSettings.AlbedoSimulation,
|
||||
nameof(WaterRenderer._AnimatedWavesLod) => true,
|
||||
nameof(WaterRenderer._ClipLod) => true,
|
||||
nameof(WaterRenderer._DepthLod) => true,
|
||||
nameof(WaterRenderer._DynamicWavesLod) => true,
|
||||
nameof(WaterRenderer._FlowLod) => true,
|
||||
nameof(WaterRenderer._FoamLod) => true,
|
||||
nameof(WaterRenderer._LevelLod) => true,
|
||||
nameof(WaterRenderer._ScatteringLod) => ProjectSettings.Instance.CurrentPlatformSettings.ScatteringSimulation,
|
||||
nameof(WaterRenderer._ShadowLod) => ProjectSettings.Instance.CurrentPlatformSettings.ShadowSimulation,
|
||||
_ => throw new System.NotImplementedException(),
|
||||
};
|
||||
|
||||
// Optional. Not all simulations will have a corresponding keyword.
|
||||
internal bool HasMaterialToggle => !string.IsNullOrEmpty(MaterialProperty);
|
||||
@@ -36,7 +52,7 @@ namespace WaveHarmonic.Crest.Editor
|
||||
// Needed as clip surface material toggle is Alpha Clipping.
|
||||
internal virtual string MaterialProperty => _MaterialProperty;
|
||||
internal virtual string MaterialPropertyPath => $"{PropertyLabel} > Enabled";
|
||||
internal virtual string MaterialKeyword => $"{MaterialProperty}_ON";
|
||||
internal virtual string MaterialKeyword => MaterialProperty;
|
||||
|
||||
internal static OptionalLod Get(System.Type type)
|
||||
{
|
||||
@@ -94,7 +110,7 @@ namespace WaveHarmonic.Crest.Editor
|
||||
{
|
||||
PropertyLabel = "Flow",
|
||||
PropertyName = nameof(WaterRenderer._FlowLod),
|
||||
_MaterialProperty = "CREST_FLOW",
|
||||
_MaterialProperty = "_CREST_FLOW_LOD",
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -110,9 +126,7 @@ namespace WaveHarmonic.Crest.Editor
|
||||
{
|
||||
PropertyLabel = "Water Level",
|
||||
PropertyName = nameof(WaterRenderer._LevelLod),
|
||||
_MaterialProperty = "_Crest_LevelEnabled",
|
||||
Dependency = typeof(AnimatedWavesLod),
|
||||
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -153,7 +167,13 @@ namespace WaveHarmonic.Crest.Editor
|
||||
// BIRP SG has prefixes for Unity properties but other RPs do not. These prefixes
|
||||
// are for serialisation only and are not used in the shader.
|
||||
internal override string MaterialPropertyPath => "Alpha Clipping";
|
||||
internal override string MaterialProperty => (RenderPipelineHelper.IsLegacy ? "_BUILTIN" : "") + "_AlphaClip";
|
||||
internal override string MaterialProperty => RenderPipelineHelper.RenderPipeline switch
|
||||
{
|
||||
RenderPipeline.Legacy => "_BUILTIN_AlphaClip",
|
||||
RenderPipeline.HighDefinition => "_AlphaCutoffEnable",
|
||||
RenderPipeline.Universal => "_AlphaClip",
|
||||
_ => throw new System.NotImplementedException(),
|
||||
};
|
||||
internal override string MaterialKeyword => (RenderPipelineHelper.IsLegacy ? "_BUILTIN" : "") + "_ALPHATEST_ON";
|
||||
}
|
||||
|
||||
|
||||
@@ -57,10 +57,10 @@ namespace WaveHarmonic.Crest.Editor
|
||||
|
||||
public override void OnPreviewGUI(Rect rect, GUIStyle background)
|
||||
{
|
||||
var texture = Lod.DataTexture;
|
||||
var texture = (RenderTexture)OriginalTexture;
|
||||
var descriptor = texture.descriptor;
|
||||
_TemporaryTexture = RenderTexture.GetTemporary(descriptor);
|
||||
_TemporaryTexture.name = "Crest Preview (Temporary)";
|
||||
_TemporaryTexture.name = texture.name;
|
||||
Graphics.CopyTexture(texture, _TemporaryTexture);
|
||||
|
||||
if (VisualizeNegatives)
|
||||
@@ -80,15 +80,16 @@ namespace WaveHarmonic.Crest.Editor
|
||||
if (ForceAlpha)
|
||||
{
|
||||
// Set alpha to one otherwise it shows nothing when set to RGB.
|
||||
var clear = WaterResources.Instance.Compute._Clear;
|
||||
if (clear != null)
|
||||
if (WaterResources.Instance.Compute._Clear != null)
|
||||
{
|
||||
clear.SetTexture(0, ShaderIDs.s_Target, _TemporaryTexture);
|
||||
clear.SetVector(ShaderIDs.s_ClearMask, Color.black);
|
||||
clear.SetVector(ShaderIDs.s_ClearColor, Color.black);
|
||||
clear.Dispatch
|
||||
var compute = WaterResources.Instance._ComputeLibrary._ClearCompute;
|
||||
var wrapper = new PropertyWrapperComputeStandalone(compute._Shader, compute._KernelClearTarget);
|
||||
compute.SetVariantForFormat(wrapper, _TemporaryTexture.graphicsFormat);
|
||||
wrapper.SetTexture(ShaderIDs.s_Target, _TemporaryTexture);
|
||||
wrapper.SetVector(ShaderIDs.s_ClearMask, Color.black);
|
||||
wrapper.SetVector(ShaderIDs.s_ClearColor, Color.black);
|
||||
wrapper.Dispatch
|
||||
(
|
||||
0,
|
||||
Lod.Resolution / Lod.k_ThreadGroupSizeX,
|
||||
Lod.Resolution / Lod.k_ThreadGroupSizeY,
|
||||
Lod.Slices
|
||||
@@ -290,7 +291,16 @@ namespace WaveHarmonic.Crest.Editor
|
||||
|
||||
public override GUIContent GetPreviewTitle() => new("Water Reflections");
|
||||
protected override Texture OriginalTexture => (target as WaterRenderer)._Reflections._Enabled
|
||||
? (target as WaterRenderer)._Reflections.ReflectionTexture
|
||||
? (target as WaterRenderer)._Reflections.ColorTexture
|
||||
: s_DefaultReflection?.GetValue(null) as Texture;
|
||||
}
|
||||
|
||||
#if CREST_DEBUG
|
||||
[CustomPreview(typeof(WaterRenderer))]
|
||||
sealed class ReflectionDepthPreview : TexturePreview
|
||||
{
|
||||
public override GUIContent GetPreviewTitle() => new("Water Reflections (Depth)");
|
||||
protected override Texture OriginalTexture => (target as WaterRenderer)._Reflections.DepthTexture;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -1,23 +1,196 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using UnityEditor;
|
||||
using UnityEditor.Build;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace WaveHarmonic.Crest.Editor.Settings
|
||||
{
|
||||
[FilePath(k_Path, FilePathAttribute.Location.ProjectFolder)]
|
||||
sealed class ProjectSettings : ScriptableSingleton<ProjectSettings>
|
||||
[System.Flags]
|
||||
enum SamplingMethod
|
||||
{
|
||||
[SerializeField, HideInInspector]
|
||||
#pragma warning disable 414
|
||||
int _Version = 0;
|
||||
#pragma warning restore 414
|
||||
Nothing = 0,
|
||||
|
||||
[InspectorName("Multi-Scale")]
|
||||
MultiScale = 1 << 0,
|
||||
|
||||
Stochastic = 1 << 1,
|
||||
|
||||
Everything = ~0,
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
sealed partial class PlatformSettings
|
||||
{
|
||||
const string k_OverrideTooltip = "Override the feature for this platform";
|
||||
|
||||
[HideInInspector]
|
||||
[SerializeField]
|
||||
internal bool _Default;
|
||||
|
||||
|
||||
[@Heading("Simulations", alwaysVisible: true)]
|
||||
|
||||
[Tooltip(k_OverrideTooltip)]
|
||||
[@Hide(nameof(_Default))]
|
||||
[@InlineToggle]
|
||||
[SerializeField]
|
||||
internal bool _OverrideAlbedoSimulation;
|
||||
|
||||
[@Label("Albedo")]
|
||||
[@DecoratedField]
|
||||
[SerializeField]
|
||||
internal bool _AlbedoSimulation = true;
|
||||
|
||||
[Tooltip(k_OverrideTooltip)]
|
||||
[@Hide(nameof(_Default))]
|
||||
[@InlineToggle]
|
||||
[SerializeField]
|
||||
internal bool _OverrideAbsorptionSimulation;
|
||||
|
||||
[@Label("Absorption")]
|
||||
[@DecoratedField]
|
||||
[SerializeField]
|
||||
internal bool _AbsorptionSimulation = true;
|
||||
|
||||
[Tooltip(k_OverrideTooltip)]
|
||||
[@Hide(nameof(_Default))]
|
||||
[@InlineToggle]
|
||||
[SerializeField]
|
||||
internal bool _OverrideScatteringSimulation;
|
||||
|
||||
[@Label("Scattering")]
|
||||
[@DecoratedField]
|
||||
[SerializeField]
|
||||
internal bool _ScatteringSimulation = true;
|
||||
|
||||
[Tooltip(k_OverrideTooltip)]
|
||||
[@Hide(nameof(_Default))]
|
||||
[@InlineToggle]
|
||||
[SerializeField]
|
||||
internal bool _OverrideShadowSimulation;
|
||||
|
||||
[@Label("Shadow")]
|
||||
[@DecoratedField]
|
||||
[SerializeField]
|
||||
internal bool _ShadowSimulation = true;
|
||||
|
||||
|
||||
[@Heading("Water Material", alwaysVisible: true)]
|
||||
|
||||
[Tooltip(k_OverrideTooltip)]
|
||||
[@Hide(nameof(_Default))]
|
||||
[@InlineToggle]
|
||||
[SerializeField]
|
||||
internal bool _OverrideOutScattering;
|
||||
|
||||
[@Label("Out-Scattering")]
|
||||
[Tooltip("Disables out-scattering for the surface and volume.\n\nOut-scattering darkens the water with depth.")]
|
||||
[@DecoratedField]
|
||||
[SerializeField]
|
||||
internal bool _OutScattering = true;
|
||||
|
||||
|
||||
[@Heading("Surface Material", alwaysVisible: true)]
|
||||
|
||||
[Tooltip(k_OverrideTooltip)]
|
||||
[@Hide(nameof(_Default))]
|
||||
[@InlineToggle]
|
||||
[SerializeField]
|
||||
internal bool _OverrideNormalMaps;
|
||||
|
||||
[@DecoratedField]
|
||||
[SerializeField]
|
||||
internal bool _NormalMaps = true;
|
||||
|
||||
[Tooltip(k_OverrideTooltip)]
|
||||
[@Hide(nameof(_Default))]
|
||||
[@InlineToggle]
|
||||
[SerializeField]
|
||||
internal bool _OverridePlanarReflections;
|
||||
|
||||
[@DecoratedField]
|
||||
[SerializeField]
|
||||
internal bool _PlanarReflections = true;
|
||||
|
||||
[Tooltip(k_OverrideTooltip)]
|
||||
[@Hide(nameof(_Default))]
|
||||
[@InlineToggle]
|
||||
[SerializeField]
|
||||
internal bool _OverridePlanarReflectionsApplySmoothness;
|
||||
|
||||
[@DecoratedField]
|
||||
[SerializeField]
|
||||
internal bool _PlanarReflectionsApplySmoothness = true;
|
||||
|
||||
[Tooltip(k_OverrideTooltip)]
|
||||
[@Hide(nameof(_Default))]
|
||||
[@InlineToggle]
|
||||
[@SerializeField]
|
||||
internal bool _OverrideFoamSampling;
|
||||
|
||||
[Tooltip("Which sampling method to use for foam.\n\nThese additional sampling techniques can be used together. Be wary that this will increase texture samples significantly.\n\nNothing: Uses the sampler set on the foam texture.\n\nMulti-Scale: Scales the foam texture by LOD to make foam pattern more visible at distances and reduces repetitive patterns. Doubles the foam texture samples.\n\nStochastic: reduces repetitive patterns. Triples the foam texture samples.")]
|
||||
[@DecoratedField]
|
||||
[@SerializeField]
|
||||
internal SamplingMethod _FoamSampling = SamplingMethod.MultiScale;
|
||||
|
||||
[Tooltip(k_OverrideTooltip)]
|
||||
[@Hide(nameof(_Default))]
|
||||
[@InlineToggle]
|
||||
[SerializeField]
|
||||
internal bool _OverrideFoamBioluminescence;
|
||||
|
||||
[@DecoratedField]
|
||||
[SerializeField]
|
||||
internal bool _FoamBioluminescence = true;
|
||||
|
||||
[Tooltip(k_OverrideTooltip)]
|
||||
[@Hide(nameof(_Default))]
|
||||
[@InlineToggle]
|
||||
[SerializeField]
|
||||
internal bool _OverrideCausticsForceDistortion;
|
||||
|
||||
[@DecoratedField]
|
||||
[SerializeField]
|
||||
internal bool _CausticsForceDistortion = true;
|
||||
|
||||
[Tooltip(k_OverrideTooltip)]
|
||||
[@Hide(nameof(_Default))]
|
||||
[@InlineToggle]
|
||||
[SerializeField]
|
||||
internal bool _OverrideAdditionalLights;
|
||||
|
||||
[Tooltip("Whether to calculate scattering from additional lights.")]
|
||||
[@DecoratedField]
|
||||
[SerializeField]
|
||||
internal bool _AdditionalLights = true;
|
||||
|
||||
|
||||
[@Heading("Rendering", alwaysVisible: true)]
|
||||
|
||||
[Tooltip(k_OverrideTooltip)]
|
||||
[@Hide(nameof(_Default))]
|
||||
[@InlineToggle]
|
||||
[SerializeField]
|
||||
internal bool _OverrideSimpleTransparency;
|
||||
|
||||
[Tooltip("Refraction like transparency without requiring the Opaque or Depth Texture.\n\nRequires a populated Water Depth Simulation to render correctly. See the Main sample for a working scene.")]
|
||||
[@DecoratedField]
|
||||
[SerializeField]
|
||||
internal bool _SimpleTransparency;
|
||||
|
||||
PlatformSettings Default => ProjectSettings.Instance._PlatformSettings;
|
||||
}
|
||||
|
||||
[FilePath(k_Path, FilePathAttribute.Location.ProjectFolder)]
|
||||
sealed partial class ProjectSettings : ScriptableSingleton<ProjectSettings>
|
||||
{
|
||||
#pragma warning disable IDE0032 // Use auto property
|
||||
|
||||
[@Heading("Variant Stripping", Heading.Style.Settings)]
|
||||
@@ -27,7 +200,7 @@ namespace WaveHarmonic.Crest.Editor.Settings
|
||||
[@DecoratedField, SerializeField]
|
||||
bool _DebugEnableStrippingLogging;
|
||||
|
||||
[@Predicated(nameof(_DebugEnableStrippingLogging))]
|
||||
[@Enable(nameof(_DebugEnableStrippingLogging))]
|
||||
[@DecoratedField, SerializeField]
|
||||
bool _DebugOnlyLogRemainingVariants;
|
||||
|
||||
@@ -47,10 +220,90 @@ namespace WaveHarmonic.Crest.Editor.Settings
|
||||
[@DecoratedField, SerializeField]
|
||||
bool _RenderAtmosphericScatteringWhenUnderWater;
|
||||
|
||||
[Tooltip("Renders the underwater effect after transparency and uses the more expensive mask.\n\nYou may need this if rendering the underwater to multiple cameras. The other benefit is that transparent objects will be fogged (albeit incorrectly).\n\nThe downsides are that there can be artifacts if waves are very choppy, has a less impressive meniscus, and generally more expensive to execute.")]
|
||||
[Tooltip("Renders the underwater effect after transparency and uses the more expensive mask.\n\nOne benefit is that transparent objects will be fogged (albeit incorrectly).\n\nThe downsides are that there can be artifacts if waves are very choppy, has a less impressive meniscus, and generally more expensive to execute.")]
|
||||
[@DecoratedField, SerializeField]
|
||||
bool _LegacyUnderwater;
|
||||
|
||||
[@Space(10)]
|
||||
|
||||
[@PlatformTabs]
|
||||
[SerializeField]
|
||||
internal int _Platforms;
|
||||
|
||||
[@Label("Overriden Settings for Windows, Mac and Linux")]
|
||||
[@Show(nameof(_Platforms), (int)BuildTargetGroup.Standalone)]
|
||||
[@Stripped(Stripped.Style.PlatformTab, indent: true)]
|
||||
[SerializeField]
|
||||
internal PlatformSettings _PlatformSettingsDesktop = new();
|
||||
|
||||
[@Label("Overriden Settings for Dedicated Server")]
|
||||
[@Show(nameof(_Platforms), -2)]
|
||||
[@Stripped(Stripped.Style.PlatformTab, indent: true)]
|
||||
[SerializeField]
|
||||
internal PlatformSettings _PlatformSettingsServer = new();
|
||||
|
||||
[@Label("Overriden Settings for Android")]
|
||||
[@Show(nameof(_Platforms), (int)BuildTargetGroup.Android)]
|
||||
[@Stripped(Stripped.Style.PlatformTab, indent: true)]
|
||||
[SerializeField]
|
||||
internal PlatformSettings _PlatformSettingsAndroid = new();
|
||||
|
||||
[@Label("Overriden Settings for iOS")]
|
||||
[@Show(nameof(_Platforms), (int)BuildTargetGroup.iOS)]
|
||||
[@Stripped(Stripped.Style.PlatformTab, indent: true)]
|
||||
[SerializeField]
|
||||
internal PlatformSettings _PlatformSettingsIOS = new();
|
||||
|
||||
[@Label("Overriden Settings for tvOS")]
|
||||
[@Show(nameof(_Platforms), (int)BuildTargetGroup.tvOS)]
|
||||
[@Stripped(Stripped.Style.PlatformTab, indent: true)]
|
||||
[SerializeField]
|
||||
internal PlatformSettings _PlatformSettingsTVOS = new();
|
||||
|
||||
[@Label("Overriden Settings for visionOS")]
|
||||
[@Show(nameof(_Platforms), (int)BuildTargetGroup.VisionOS)]
|
||||
[@Stripped(Stripped.Style.PlatformTab, indent: true)]
|
||||
[SerializeField]
|
||||
internal PlatformSettings _PlatformSettingsVisionOS = new();
|
||||
|
||||
// Web has hard limitations on number of sampled textures. Set defaults with that
|
||||
// in mind so the surface renders.
|
||||
[@Label("Overriden Settings for Web")]
|
||||
[@Show(nameof(_Platforms), (int)BuildTargetGroup.WebGL)]
|
||||
[@Stripped(Stripped.Style.PlatformTab, indent: true)]
|
||||
[SerializeField]
|
||||
internal PlatformSettings _PlatformSettingsWeb = new()
|
||||
{
|
||||
_OverrideAbsorptionSimulation = true,
|
||||
_AbsorptionSimulation = false,
|
||||
_OverrideAlbedoSimulation = true,
|
||||
_AlbedoSimulation = false,
|
||||
_OverrideScatteringSimulation = true,
|
||||
_ScatteringSimulation = false,
|
||||
_OverrideShadowSimulation = true,
|
||||
_ShadowSimulation = false,
|
||||
|
||||
_OverrideCausticsForceDistortion = true,
|
||||
_CausticsForceDistortion = false,
|
||||
_OverridePlanarReflections = true,
|
||||
_PlanarReflections = false,
|
||||
_OverrideFoamBioluminescence = true,
|
||||
_FoamBioluminescence = false,
|
||||
};
|
||||
|
||||
// This will show if nothing else shows.
|
||||
[@Label("Default Settings")]
|
||||
[@Hide(nameof(_Platforms), (int)BuildTargetGroup.Standalone)]
|
||||
[@Hide(nameof(_Platforms), Reflected.BuildTargetGroup.k_Server)]
|
||||
[@Hide(nameof(_Platforms), (int)BuildTargetGroup.Android)]
|
||||
[@Hide(nameof(_Platforms), (int)BuildTargetGroup.iOS)]
|
||||
[@Hide(nameof(_Platforms), (int)BuildTargetGroup.WebGL)]
|
||||
[@Hide(nameof(_Platforms), (int)BuildTargetGroup.tvOS)]
|
||||
[@Hide(nameof(_Platforms), (int)BuildTargetGroup.VisionOS)]
|
||||
[@Stripped(Stripped.Style.PlatformTab, indent: true)]
|
||||
[SerializeField]
|
||||
internal PlatformSettings _PlatformSettings = new() { _Default = true };
|
||||
|
||||
#pragma warning restore IDE0032 // Use auto property
|
||||
|
||||
internal const string k_Path = "ProjectSettings/Packages/com.waveharmonic.crest/Settings.asset";
|
||||
@@ -72,11 +325,38 @@ namespace WaveHarmonic.Crest.Editor.Settings
|
||||
internal bool RenderAtmosphericScatteringWhenUnderWater => _RenderAtmosphericScatteringWhenUnderWater;
|
||||
internal bool LegacyUnderwater => _LegacyUnderwater;
|
||||
|
||||
internal PlatformSettings CurrentPlatformSettings =>
|
||||
#if PLATFORM_STANDALONE
|
||||
_PlatformSettingsDesktop;
|
||||
#elif PLATFORM_SERVER
|
||||
_PlatformSettingsServer;
|
||||
#elif PLATFORM_ANDROID
|
||||
_PlatformSettingsAndroid;
|
||||
#elif PLATFORM_IOS
|
||||
_PlatformSettingsIOS;
|
||||
#elif PLATFORM_TVOS
|
||||
_PlatformSettingsTVOS;
|
||||
#elif PLATFORM_VISIONOS
|
||||
_PlatformSettingsVisionOS;
|
||||
#else
|
||||
_PlatformSettings;
|
||||
#endif
|
||||
|
||||
internal bool _IsPlatformTabChange;
|
||||
readonly Dictionary<NamedBuildTarget, PlatformSettings> _PlatformSettingsMap = new();
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
// Fixes not being editable.
|
||||
hideFlags = HideFlags.HideAndDontSave & ~HideFlags.NotEditable;
|
||||
|
||||
_PlatformSettingsMap.Clear();
|
||||
_PlatformSettingsMap.Add(NamedBuildTarget.Standalone, _PlatformSettingsDesktop);
|
||||
_PlatformSettingsMap.Add(NamedBuildTarget.Server, _PlatformSettingsServer);
|
||||
_PlatformSettingsMap.Add(NamedBuildTarget.Android, _PlatformSettingsAndroid);
|
||||
_PlatformSettingsMap.Add(NamedBuildTarget.iOS, _PlatformSettingsIOS);
|
||||
_PlatformSettingsMap.Add(NamedBuildTarget.tvOS, _PlatformSettingsTVOS);
|
||||
_PlatformSettingsMap.Add(NamedBuildTarget.VisionOS, _PlatformSettingsVisionOS);
|
||||
}
|
||||
|
||||
|
||||
@@ -88,6 +368,14 @@ namespace WaveHarmonic.Crest.Editor.Settings
|
||||
[@OnChange(skipIfInactive: false)]
|
||||
void OnChange(string path, object previous)
|
||||
{
|
||||
_IsPlatformTabChange = path == nameof(_Platforms);
|
||||
|
||||
if (path.StartsWithNoAlloc("_PlatformSettings"))
|
||||
{
|
||||
UpdateSymbols();
|
||||
return;
|
||||
}
|
||||
|
||||
switch (path)
|
||||
{
|
||||
case nameof(_FullPrecisionDisplacementOnHalfPrecisionPlatforms):
|
||||
@@ -100,7 +388,15 @@ namespace WaveHarmonic.Crest.Editor.Settings
|
||||
|
||||
void UpdateScriptingSymbols()
|
||||
{
|
||||
ScriptingSymbols.Set(ProjectSymbols.k_LegacyUnderwaterScriptingSymbol, _LegacyUnderwater);
|
||||
foreach (var build in _PlatformSettingsMap.Keys)
|
||||
{
|
||||
ScriptingSymbols.s_OverrideCurrentNamedBuildTarget = true;
|
||||
ScriptingSymbols.s_CurrentNamedBuildTargetOverride = build;
|
||||
ScriptingSymbols.Set(ProjectSymbols.k_LegacyUnderwaterScriptingSymbol, _LegacyUnderwater);
|
||||
ScriptingSymbols.Set(ProjectSymbols.k_SimpleTransparencyScriptingSymbol, _PlatformSettingsMap[build].SimpleTransparency);
|
||||
ScriptingSymbols.Set(ProjectSymbols.k_PlanarReflectionApplySmoothnessScriptingSymbol, !_PlatformSettingsMap[build].PlanarReflectionsApplySmoothness);
|
||||
ScriptingSymbols.s_OverrideCurrentNamedBuildTarget = false;
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateSymbols()
|
||||
@@ -111,7 +407,10 @@ namespace WaveHarmonic.Crest.Editor.Settings
|
||||
|
||||
sealed class ProjectSymbols : AssetModificationProcessor
|
||||
{
|
||||
// The default value should not produce a symbol.
|
||||
public const string k_LegacyUnderwaterScriptingSymbol = "d_Crest_LegacyUnderwater";
|
||||
public const string k_SimpleTransparencyScriptingSymbol = "d_Crest_SimpleTransparency";
|
||||
public const string k_PlanarReflectionApplySmoothnessScriptingSymbol = "d_Crest_DisablePlanarReflectionApplySmoothness";
|
||||
|
||||
static FileSystemWatcher s_Watcher;
|
||||
|
||||
@@ -142,6 +441,11 @@ namespace WaveHarmonic.Crest.Editor.Settings
|
||||
{
|
||||
EditorApplication.delayCall += () =>
|
||||
{
|
||||
if (Instance != null && Instance._IsPlatformTabChange)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Destroy instance to reflect changes.
|
||||
Helpers.Destroy(Instance);
|
||||
typeof(ScriptableSingleton<ProjectSettings>)
|
||||
@@ -220,31 +524,17 @@ namespace WaveHarmonic.Crest.Editor.Settings
|
||||
return;
|
||||
}
|
||||
|
||||
// Reset foldout values.
|
||||
DecoratedDrawer.s_IsFoldout = false;
|
||||
DecoratedDrawer.s_IsFoldoutOpen = false;
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
// Pad similar to settings header.
|
||||
var style = new GUIStyle();
|
||||
style.padding.left = 8;
|
||||
EditorGUILayout.BeginVertical(style);
|
||||
|
||||
// Same label with as other settings.
|
||||
EditorGUIUtility.labelWidth = 251;
|
||||
|
||||
EditorGUILayout.BeginVertical(style);
|
||||
_Editor.OnInspectorGUI();
|
||||
EditorGUILayout.EndVertical();
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
// Commit all changes. Normally settings are written when user hits save or exits
|
||||
// without any undo/redo entry and dirty state. No idea how to do the same.
|
||||
// SaveChanges and hasUnsavedChanges on custom editor did not work.
|
||||
// Not sure if hooking into EditorSceneManager.sceneSaving is correct.
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
ProjectSettings.Save();
|
||||
}
|
||||
_Editor.OnInspectorGUI();
|
||||
|
||||
GUILayout.Space(10 * 2);
|
||||
|
||||
@@ -256,6 +546,8 @@ namespace WaveHarmonic.Crest.Editor.Settings
|
||||
AssetDatabase.ImportAsset(path);
|
||||
}
|
||||
}
|
||||
|
||||
EditorGUILayout.EndVertical();
|
||||
}
|
||||
|
||||
[SettingsProvider]
|
||||
@@ -272,4 +564,43 @@ namespace WaveHarmonic.Crest.Editor.Settings
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
[CustomEditor(typeof(ProjectSettings))]
|
||||
sealed class ProjectSettingsEditor : Inspector
|
||||
{
|
||||
protected override void OnChange()
|
||||
{
|
||||
base.OnChange();
|
||||
|
||||
// Commit all changes. Normally settings are written when user hits save or exits
|
||||
// without any undo/redo entry and dirty state. No idea how to do the same.
|
||||
// SaveChanges and hasUnsavedChanges on custom editor did not work.
|
||||
// Not sure if hooking into EditorSceneManager.sceneSaving is correct.
|
||||
ProjectSettings.Save();
|
||||
}
|
||||
}
|
||||
|
||||
partial class ProjectSettings : ISerializationCallbackReceiver
|
||||
{
|
||||
[SerializeField, HideInInspector]
|
||||
int _Version = 0;
|
||||
|
||||
[SerializeField, HideInInspector]
|
||||
internal int _MaterialVersion = MaterialUpgrader.k_MaterialVersion;
|
||||
|
||||
public void OnAfterDeserialize()
|
||||
{
|
||||
if (_Version == 0)
|
||||
{
|
||||
_MaterialVersion = 0;
|
||||
}
|
||||
|
||||
_Version = 1;
|
||||
}
|
||||
|
||||
public void OnBeforeSerialize()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,37 +14,37 @@
|
||||
"versionDefines": [
|
||||
{
|
||||
"name": "com.waveharmonic.crest.cpu-queries",
|
||||
"expression": "(,1.0.8)",
|
||||
"expression": "(,1.0.9)",
|
||||
"define": "d_UpdateCPUQueries"
|
||||
},
|
||||
{
|
||||
"name": "com.waveharmonic.crest.paint",
|
||||
"expression": "(,1.2.3)",
|
||||
"expression": "(,1.3.3)",
|
||||
"define": "d_UpdatePaint"
|
||||
},
|
||||
{
|
||||
"name": "com.waveharmonic.crest.portals",
|
||||
"expression": "(,1.2.8)",
|
||||
"expression": "(,1.3.1)",
|
||||
"define": "d_UpdatePortals"
|
||||
},
|
||||
{
|
||||
"name": "com.waveharmonic.crest.shallow-water",
|
||||
"expression": "(,1.3.3)",
|
||||
"expression": "(,1.4.2)",
|
||||
"define": "d_UpdateShallowWater"
|
||||
},
|
||||
{
|
||||
"name": "com.waveharmonic.crest.shifting-origin",
|
||||
"expression": "(,1.3.0)",
|
||||
"expression": "(,1.3.1)",
|
||||
"define": "d_UpdateShiftingOrigin"
|
||||
},
|
||||
{
|
||||
"name": "com.waveharmonic.crest.splines",
|
||||
"expression": "(,1.4.4)",
|
||||
"expression": "(,1.6.0)",
|
||||
"define": "d_UpdateSplines"
|
||||
},
|
||||
{
|
||||
"name": "com.waveharmonic.crest.whirlpool",
|
||||
"expression": "(,1.0.3)",
|
||||
"expression": "(,1.1.1)",
|
||||
"define": "d_UpdateWhirlpool"
|
||||
}
|
||||
],
|
||||
|
||||
@@ -10,6 +10,9 @@ using WaveHarmonic.Crest.Editor.Settings;
|
||||
|
||||
namespace WaveHarmonic.Crest.Editor
|
||||
{
|
||||
[System.AttributeUsage(System.AttributeTargets.Class)]
|
||||
sealed class GenerateShaderSettings : System.Attribute { }
|
||||
|
||||
static class ShaderSettingsGenerator
|
||||
{
|
||||
[DidReloadScripts]
|
||||
@@ -51,7 +54,7 @@ namespace WaveHarmonic.Crest.Editor
|
||||
|
||||
sealed class AssetPostProcessor : AssetPostprocessor
|
||||
{
|
||||
const string k_SettingsPath = "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Settings.Crest.hlsl";
|
||||
const string k_SettingsPath = "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Settings/";
|
||||
|
||||
static async void OnPostprocessAllAssets(string[] imported, string[] deleted, string[] movedTo, string[] movedFrom, bool domainReload)
|
||||
{
|
||||
@@ -61,7 +64,7 @@ namespace WaveHarmonic.Crest.Editor
|
||||
if (EditorApplication.isCompiling)
|
||||
{
|
||||
#if CREST_DEBUG
|
||||
if (imported.Contains(k_SettingsPath))
|
||||
if (imported.Count(x => x.StartsWithNoAlloc(k_SettingsPath)) > 0)
|
||||
{
|
||||
UnityEngine.Debug.Log($"Crest: Settings.Crest.hlsl changed during compilation!");
|
||||
}
|
||||
@@ -72,7 +75,7 @@ namespace WaveHarmonic.Crest.Editor
|
||||
if (EditorApplication.isUpdating)
|
||||
{
|
||||
#if CREST_DEBUG
|
||||
if (imported.Contains(k_SettingsPath))
|
||||
if (imported.Count(x => x.StartsWithNoAlloc(k_SettingsPath)) > 0)
|
||||
{
|
||||
UnityEngine.Debug.Log($"Crest: Settings.Crest.hlsl changed during asset database update!");
|
||||
}
|
||||
@@ -81,7 +84,7 @@ namespace WaveHarmonic.Crest.Editor
|
||||
}
|
||||
|
||||
// Regenerate if file changed like re-importing.
|
||||
if (imported.Contains(k_SettingsPath))
|
||||
if (imported.Count(x => x.StartsWithNoAlloc(k_SettingsPath)) > 0)
|
||||
{
|
||||
#if CREST_DEBUG
|
||||
UnityEngine.Debug.Log($"Crest: Settings.Crest.hlsl changed!");
|
||||
@@ -94,7 +97,7 @@ namespace WaveHarmonic.Crest.Editor
|
||||
}
|
||||
}
|
||||
|
||||
[GenerateHLSL(sourcePath = "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Settings.Crest")]
|
||||
[GenerateHLSL(sourcePath = "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Settings/Settings.Crest")]
|
||||
sealed class ShaderSettings
|
||||
{
|
||||
// These two are here for compute shaders.
|
||||
@@ -126,10 +129,111 @@ namespace WaveHarmonic.Crest.Editor
|
||||
#endif
|
||||
;
|
||||
|
||||
// Active when build target is activated:
|
||||
// https://docs.unity3d.com/6000.3/Documentation/Manual/scripting-symbol-reference.html
|
||||
|
||||
public static int s_CrestPlatformStandalone =
|
||||
#if PLATFORM_STANDALONE
|
||||
1 +
|
||||
#endif
|
||||
0;
|
||||
|
||||
public static int s_CrestPlatformServer =
|
||||
#if PLATFORM_SERVER
|
||||
1 +
|
||||
#endif
|
||||
0;
|
||||
|
||||
public static int s_CrestPlatformAndroid =
|
||||
#if PLATFORM_ANDROID
|
||||
1 +
|
||||
#endif
|
||||
0;
|
||||
|
||||
public static int s_CrestPlatformIOS =
|
||||
#if PLATFORM_IOS
|
||||
1 +
|
||||
#endif
|
||||
0;
|
||||
|
||||
public static int s_CrestPlatformWeb =
|
||||
#if PLATFORM_WEBGL
|
||||
1 +
|
||||
#endif
|
||||
0;
|
||||
|
||||
public static int s_CrestPlatformTVOS =
|
||||
#if PLATFORM_TVOS
|
||||
1 +
|
||||
#endif
|
||||
0;
|
||||
|
||||
public static int s_CrestPlatformVISIONOS =
|
||||
#if PLATFORM_VISIONOS
|
||||
1 +
|
||||
#endif
|
||||
0;
|
||||
|
||||
public static int s_CrestFullPrecisionDisplacement = ProjectSettings.Instance.FullPrecisionDisplacementOnHalfPrecisionPlatforms ? 1 : 0;
|
||||
|
||||
public static int s_CrestDiscardAtmosphericScattering = ProjectSettings.Instance.RenderAtmosphericScatteringWhenUnderWater ? 0 : 1;
|
||||
|
||||
public static int s_CrestLegacyUnderwater = ProjectSettings.Instance.LegacyUnderwater ? 1 : 0;
|
||||
}
|
||||
|
||||
[@GenerateShaderSettings]
|
||||
[GenerateHLSL(sourcePath = "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Settings/Settings.Crest.Default")]
|
||||
sealed partial class ShaderSettingsDefault
|
||||
{
|
||||
static PlatformSettings Settings => ProjectSettings.Instance._PlatformSettings;
|
||||
}
|
||||
|
||||
[@GenerateShaderSettings]
|
||||
[GenerateHLSL(sourcePath = "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Settings/Settings.Crest.Standalone")]
|
||||
sealed partial class ShaderSettingsStandalone
|
||||
{
|
||||
static PlatformSettings Settings => ProjectSettings.Instance._PlatformSettingsDesktop;
|
||||
}
|
||||
|
||||
[@GenerateShaderSettings]
|
||||
[GenerateHLSL(sourcePath = "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Settings/Settings.Crest.Server")]
|
||||
sealed partial class ShaderSettingsServer
|
||||
{
|
||||
static PlatformSettings Settings => ProjectSettings.Instance._PlatformSettingsServer;
|
||||
}
|
||||
|
||||
[@GenerateShaderSettings]
|
||||
[GenerateHLSL(sourcePath = "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Settings/Settings.Crest.Android")]
|
||||
sealed partial class ShaderSettingsAndroid
|
||||
{
|
||||
static PlatformSettings Settings => ProjectSettings.Instance._PlatformSettingsAndroid;
|
||||
}
|
||||
|
||||
[@GenerateShaderSettings]
|
||||
[GenerateHLSL(sourcePath = "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Settings/Settings.Crest.iOS")]
|
||||
sealed partial class ShaderSettingsIOS
|
||||
{
|
||||
static PlatformSettings Settings => ProjectSettings.Instance._PlatformSettingsIOS;
|
||||
}
|
||||
|
||||
[@GenerateShaderSettings]
|
||||
[GenerateHLSL(sourcePath = "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Settings/Settings.Crest.Web")]
|
||||
sealed partial class ShaderSettingsWeb
|
||||
{
|
||||
static PlatformSettings Settings => ProjectSettings.Instance._PlatformSettingsWeb;
|
||||
}
|
||||
|
||||
[@GenerateShaderSettings]
|
||||
[GenerateHLSL(sourcePath = "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Settings/Settings.Crest.tvOS")]
|
||||
sealed partial class ShaderSettingsTVOS
|
||||
{
|
||||
static PlatformSettings Settings => ProjectSettings.Instance._PlatformSettingsTVOS;
|
||||
}
|
||||
|
||||
[@GenerateShaderSettings]
|
||||
[GenerateHLSL(sourcePath = "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Settings/Settings.Crest.visionOS")]
|
||||
sealed partial class ShaderSettingsVisionOS
|
||||
{
|
||||
static PlatformSettings Settings => ProjectSettings.Instance._PlatformSettingsVisionOS;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace WaveHarmonic.Crest.Attributes
|
||||
/// <summary>
|
||||
/// Override this method to customise the label.
|
||||
/// </summary>
|
||||
internal virtual GUIContent BuildLabel(GUIContent label) => label;
|
||||
internal virtual GUIContent BuildLabel(SerializedProperty property, GUIContent label, DecoratedDrawer drawer) => label;
|
||||
|
||||
/// <summary>
|
||||
/// Override this method to make your own IMGUI based GUI for the property.
|
||||
@@ -55,7 +55,7 @@ namespace WaveHarmonic.Crest.Attributes
|
||||
/// <summary>
|
||||
/// Override this method to customise the label.
|
||||
/// </summary>
|
||||
internal virtual GUIContent BuildLabel(GUIContent label) => label;
|
||||
internal virtual GUIContent BuildLabel(SerializedProperty property, GUIContent label, DecoratedDrawer drawer) => label;
|
||||
|
||||
/// <summary>
|
||||
/// Override this method to additively change the appearance of a decorated field.
|
||||
@@ -83,6 +83,37 @@ namespace WaveHarmonic.Crest.Attributes
|
||||
|
||||
namespace WaveHarmonic.Crest
|
||||
{
|
||||
sealed class CustomField : DecoratedProperty
|
||||
{
|
||||
internal override void OnGUI(Rect position, SerializedProperty property, GUIContent label, DecoratedDrawer drawer)
|
||||
{
|
||||
if (drawer._Inspector == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
drawer._Inspector.OnCustomField(position, property, label, drawer);
|
||||
}
|
||||
}
|
||||
|
||||
sealed class CustomLabel : Decorator
|
||||
{
|
||||
public override bool AlwaysVisible => false;
|
||||
|
||||
internal override GUIContent BuildLabel(SerializedProperty property, GUIContent label, DecoratedDrawer drawer)
|
||||
{
|
||||
label = base.BuildLabel(property, label, drawer);
|
||||
if (drawer._Inspector == null) return label;
|
||||
label = drawer._Inspector.OnCustomLabel(property, label, drawer);
|
||||
return label;
|
||||
}
|
||||
|
||||
internal override void Decorate(Rect position, SerializedProperty property, GUIContent label, DecoratedDrawer drawer)
|
||||
{
|
||||
// Empty
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Renders the property using EditorGUI.PropertyField.
|
||||
/// </summary>
|
||||
@@ -142,11 +173,48 @@ namespace WaveHarmonic.Crest
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
sealed class Order : Decorator
|
||||
{
|
||||
public override bool AlwaysVisible => true;
|
||||
|
||||
public readonly string _Target;
|
||||
public readonly Placement _Placement;
|
||||
|
||||
public enum Placement
|
||||
{
|
||||
Heading,
|
||||
Below,
|
||||
Above,
|
||||
}
|
||||
|
||||
public Order(string target, Placement placement = Placement.Heading)
|
||||
{
|
||||
_Target = target;
|
||||
_Placement = placement;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Renders foldout without the foldout.
|
||||
/// </summary>
|
||||
sealed class Stripped : DecoratedProperty
|
||||
{
|
||||
public enum Style
|
||||
{
|
||||
None,
|
||||
PlatformTab,
|
||||
}
|
||||
|
||||
readonly bool _KeepIndent;
|
||||
readonly Style _Style;
|
||||
|
||||
public Stripped(Style style = Style.None, bool indent = false)
|
||||
{
|
||||
_KeepIndent = indent;
|
||||
_Style = style;
|
||||
}
|
||||
|
||||
internal override bool NeedsControlRectangle(SerializedProperty property) => false;
|
||||
|
||||
internal override void OnGUI(Rect position, SerializedProperty property, GUIContent label, DecoratedDrawer drawer)
|
||||
@@ -155,11 +223,33 @@ namespace WaveHarmonic.Crest
|
||||
DecoratedDrawer.s_TemporaryColor = true;
|
||||
DecoratedDrawer.s_PreviousColor = GUI.color;
|
||||
|
||||
if (_Style == Style.PlatformTab)
|
||||
{
|
||||
EditorGUI.indentLevel += 1;
|
||||
EditorGUILayout.LabelField(label);
|
||||
EditorGUI.indentLevel -= 1;
|
||||
}
|
||||
|
||||
GUI.color = new(0, 0, 0, 0);
|
||||
|
||||
EditorGUI.indentLevel -= 1;
|
||||
if (!_KeepIndent) EditorGUI.indentLevel -= 1;
|
||||
EditorGUI.PropertyField(position, property, label, true);
|
||||
EditorGUI.indentLevel += 1;
|
||||
if (!_KeepIndent) EditorGUI.indentLevel += 1;
|
||||
|
||||
if (_Style == Style.PlatformTab)
|
||||
{
|
||||
EditorGUILayout.Space(4);
|
||||
EditorGUILayout.EndBuildTargetSelectionGrouping();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sealed class PlatformTabs : DecoratedProperty
|
||||
{
|
||||
static readonly GUIContent s_DefaultTab = new(EditorGUIUtility.IconContent("d_Settings").image, "Default");
|
||||
internal override void OnGUI(Rect position, SerializedProperty property, GUIContent label, DecoratedDrawer drawer)
|
||||
{
|
||||
property.intValue = Editor.Reflected.EditorGUILayout.BeginBuildTargetSelectionGrouping(s_DefaultTab);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -370,7 +460,7 @@ namespace WaveHarmonic.Crest
|
||||
property.floatValue = Mathf.Max(_Minimum, property.floatValue);
|
||||
break;
|
||||
case SerializedPropertyType.Integer:
|
||||
property.floatValue = Mathf.Max((int)_Minimum, property.intValue);
|
||||
property.intValue = Mathf.Max((int)_Minimum, property.intValue);
|
||||
break;
|
||||
case SerializedPropertyType.Vector2:
|
||||
var vector2Value = property.vector2Value;
|
||||
@@ -621,29 +711,15 @@ namespace WaveHarmonic.Crest
|
||||
|
||||
sealed class InlineToggle : DecoratedProperty
|
||||
{
|
||||
// Add extra y offset. Needed for foldouts in foldouts so far.
|
||||
readonly bool _Fix;
|
||||
|
||||
public InlineToggle(bool fix = false)
|
||||
{
|
||||
_Fix = fix;
|
||||
}
|
||||
|
||||
internal override bool NeedsControlRectangle(SerializedProperty property)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
internal override void OnGUI(Rect position, SerializedProperty property, GUIContent label, DecoratedDrawer drawer)
|
||||
{
|
||||
var r = position;
|
||||
r.x -= 16f;
|
||||
// Align with Space offset.
|
||||
if (drawer.Space > 0) r.y += drawer.Space + 2f;
|
||||
if (_Fix) r.y += EditorGUIUtility.singleLineHeight + 2f;
|
||||
// Seems to be needed.
|
||||
|
||||
// Prevent click events blocking next property.
|
||||
r.width = 16f * (1f + EditorGUI.indentLevel);
|
||||
r.height = EditorGUIUtility.singleLineHeight;
|
||||
|
||||
// Hide text.
|
||||
label.text = "";
|
||||
|
||||
using (new EditorGUI.PropertyScope(r, label, property))
|
||||
@@ -654,6 +730,9 @@ namespace WaveHarmonic.Crest
|
||||
property.boolValue = EditorGUI.Toggle(r, property.boolValue);
|
||||
EditorGUI.EndProperty();
|
||||
}
|
||||
|
||||
// Pull up next property. Extra space might be margin/padding.
|
||||
GUILayout.Space(-(EditorGUIUtility.singleLineHeight + 2f));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -859,9 +938,9 @@ namespace WaveHarmonic.Crest
|
||||
_Label = label;
|
||||
}
|
||||
|
||||
internal override GUIContent BuildLabel(GUIContent label)
|
||||
internal override GUIContent BuildLabel(SerializedProperty property, GUIContent label, DecoratedDrawer drawer)
|
||||
{
|
||||
label = base.BuildLabel(label);
|
||||
label = base.BuildLabel(property, label, drawer);
|
||||
label.text = _Label;
|
||||
return label;
|
||||
}
|
||||
@@ -877,7 +956,7 @@ namespace WaveHarmonic.Crest
|
||||
/// </summary>
|
||||
sealed class Heading : Decorator
|
||||
{
|
||||
readonly GUIContent _Text;
|
||||
public readonly GUIContent _Text;
|
||||
readonly string _HelpLink;
|
||||
readonly Style _Style;
|
||||
readonly bool _AlwaysVisible;
|
||||
|
||||
@@ -23,6 +23,12 @@ namespace WaveHarmonic.Crest
|
||||
|
||||
internal override void OnGUI(Rect position, SerializedProperty property, GUIContent label, DecoratedDrawer drawer)
|
||||
{
|
||||
if (drawer._Inspector != null && !drawer._Inspector._EmbeddedEditors.Contains(_Editor))
|
||||
{
|
||||
drawer._Inspector._EmbeddedEditors.Add(_Editor);
|
||||
Inspector.s_EmbeddedEditors.Add(_Editor);
|
||||
}
|
||||
|
||||
_Editor.DrawEditorCombo(this, label, drawer, property, "asset");
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ using WaveHarmonic.Crest.Editor;
|
||||
|
||||
namespace WaveHarmonic.Crest
|
||||
{
|
||||
sealed class Predicated : Decorator
|
||||
abstract class Predicated : Decorator
|
||||
{
|
||||
enum Mode
|
||||
{
|
||||
@@ -24,6 +24,7 @@ namespace WaveHarmonic.Crest
|
||||
|
||||
readonly bool _Inverted;
|
||||
readonly bool _Hide;
|
||||
readonly bool _Implicit;
|
||||
|
||||
readonly string _PropertyName;
|
||||
readonly object _DisableValue;
|
||||
@@ -38,16 +39,16 @@ namespace WaveHarmonic.Crest
|
||||
/// </summary>
|
||||
/// <param name="type">The type to call the method on. Must be either a static type or the type the field is defined on.</param>
|
||||
/// <param name="member">Member name. Method must match signature: bool MethodName(Component component). Can be any visibility and static or instance.</param>
|
||||
/// <param name="disableValue"></param>
|
||||
/// <param name="value">Disable/Hide if matches this value.</param>
|
||||
/// <param name="inverted">Flip behaviour - for example disable if a bool field is set to true (instead of false).</param>
|
||||
/// <param name="hide">Hide this component in the inspector.</param>
|
||||
public Predicated(Type type, string member, object disableValue, bool inverted = false, bool hide = false)
|
||||
public Predicated(Type type, string member, object value, bool inverted = false, bool hide = false)
|
||||
{
|
||||
_Mode = Mode.Member;
|
||||
_Inverted = inverted;
|
||||
_Hide = hide;
|
||||
_Type = type;
|
||||
_DisableValue = disableValue;
|
||||
_DisableValue = value;
|
||||
_Member = _Type.GetMember(member, Helpers.s_AnyMethod)[0];
|
||||
}
|
||||
|
||||
@@ -71,21 +72,30 @@ namespace WaveHarmonic.Crest
|
||||
_Type = type;
|
||||
}
|
||||
|
||||
public Predicated(string property, bool inverted = false, bool hide = false)
|
||||
{
|
||||
_Mode = Mode.Property;
|
||||
_Inverted = inverted;
|
||||
_Hide = hide;
|
||||
_PropertyName = property;
|
||||
_Implicit = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The field with this attribute will be drawn enabled/disabled based on another field. For example can be used
|
||||
/// to disable a field if a toggle is false.
|
||||
/// </summary>
|
||||
/// <param name="property">The name of the other property whose value dictates whether this field is enabled or not.</param>
|
||||
/// <param name="inverted">Flip behaviour - for example disable if a bool field is set to true (instead of false).</param>
|
||||
/// <param name="disableValue">If the field has this value, disable the GUI (or enable if inverted is true).</param>
|
||||
/// <param name="value">If the field has this value, disable the GUI (or enable if inverted is true).</param>
|
||||
/// <param name="hide">Hide this component in the inspector.</param>
|
||||
public Predicated(string property, bool inverted = false, object disableValue = null, bool hide = false)
|
||||
public Predicated(string property, object value, bool inverted = false, bool hide = false)
|
||||
{
|
||||
_Mode = Mode.Property;
|
||||
_Inverted = inverted;
|
||||
_Hide = hide;
|
||||
_PropertyName = property;
|
||||
_DisableValue = disableValue;
|
||||
_DisableValue = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -106,18 +116,24 @@ namespace WaveHarmonic.Crest
|
||||
|
||||
public bool GUIEnabled(SerializedProperty property)
|
||||
{
|
||||
if (_Implicit && property.propertyType is not SerializedPropertyType.Boolean and not SerializedPropertyType.ObjectReference and not SerializedPropertyType.ManagedReference)
|
||||
{
|
||||
Debug.Log($"Crest.Predicated: Implicit predicated on {property.name} cannot be used for {property.propertyType}.");
|
||||
return false;
|
||||
}
|
||||
|
||||
return _Inverted != property.propertyType switch
|
||||
{
|
||||
// Enable GUI if int value of field is not equal to 0, or whatever the disable-value is set to
|
||||
SerializedPropertyType.Integer => property.intValue != ((int?)_DisableValue ?? 0),
|
||||
// Enable GUI if disable-value is 0 and field is true, or disable-value is not 0 and field is false
|
||||
SerializedPropertyType.Boolean => property.boolValue ^ (((int?)_DisableValue ?? 0) != 0),
|
||||
SerializedPropertyType.Boolean => _Implicit ? !property.boolValue : (bool)_DisableValue == property.boolValue,
|
||||
SerializedPropertyType.Float => property.floatValue != ((float?)_DisableValue ?? 0),
|
||||
SerializedPropertyType.String => property.stringValue != ((string)_DisableValue ?? ""),
|
||||
// Must pass nameof enum entry as we are comparing names because index != value.
|
||||
SerializedPropertyType.Enum => property.enumNames[property.enumValueIndex] != ((string)_DisableValue ?? ""),
|
||||
SerializedPropertyType.ObjectReference => property.objectReferenceValue != null,
|
||||
SerializedPropertyType.ManagedReference => property.managedReferenceValue != null,
|
||||
SerializedPropertyType.ObjectReference => _Implicit ? property.objectReferenceValue == null : property.objectReferenceValue != null,
|
||||
SerializedPropertyType.ManagedReference => _Implicit ? property.managedReferenceValue == null : property.managedReferenceValue != null,
|
||||
_ => throw new ArgumentException($"Crest.Predicated: property type on <i>{property.serializedObject.targetObject}</i> not implemented yet: {property.propertyType}."),
|
||||
};
|
||||
}
|
||||
@@ -201,12 +217,12 @@ namespace WaveHarmonic.Crest
|
||||
}
|
||||
|
||||
var enabledByTypeCheck = _Type.IsAssignableFrom(type);
|
||||
if (_Inverted) enabledByTypeCheck = !enabledByTypeCheck;
|
||||
if (!_Inverted) enabledByTypeCheck = !enabledByTypeCheck;
|
||||
enabled = enabledByTypeCheck && enabled;
|
||||
}
|
||||
else if (_Mode == Mode.RenderPipeline)
|
||||
{
|
||||
enabled = RenderPipelineHelper.RenderPipeline == _RenderPipeline != _Inverted;
|
||||
enabled = RenderPipelineHelper.RenderPipeline == _RenderPipeline == _Inverted;
|
||||
}
|
||||
|
||||
// Keep current disabled state.
|
||||
@@ -216,4 +232,228 @@ namespace WaveHarmonic.Crest
|
||||
DecoratedDrawer.s_HideInInspector = DecoratedDrawer.s_HideInInspector || (_Hide && !enabled);
|
||||
}
|
||||
}
|
||||
|
||||
sealed class Show : Predicated
|
||||
{
|
||||
const bool k_Hide = true;
|
||||
const bool k_Inverted = true;
|
||||
|
||||
/// <summary>
|
||||
/// Show this field if member's (method) returned value matches provided.
|
||||
/// </summary>
|
||||
/// <inheritdoc cref="Predicated(Type, string, object, bool, bool)"/>
|
||||
public Show(Type type, string member, object value) : base(type, member, value, k_Inverted, k_Hide)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Show this field if member (method) returns true.
|
||||
/// </summary>
|
||||
/// <inheritdoc cref="Predicated(Type, string, bool, bool)"/>
|
||||
public Show(Type type, string member) : this(type, member, value: true)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Show field if owning class is of type.
|
||||
/// </summary>
|
||||
public Show(Type type) : base(type, k_Inverted, k_Hide)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Show if field is null or false if reference or boolean respectively.
|
||||
/// </summary>
|
||||
public Show(string property) : base(property, k_Inverted, k_Hide)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Show if field matches value.
|
||||
/// </summary>
|
||||
public Show(string property, object value) : base(property, value, k_Inverted, k_Hide)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Show if current render pipeline matches.
|
||||
/// </summary>
|
||||
public Show(RenderPipeline rp) : base(rp, k_Inverted, k_Hide)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
sealed class Hide : Predicated
|
||||
{
|
||||
const bool k_Hide = true;
|
||||
const bool k_Inverted = false;
|
||||
|
||||
/// <summary>
|
||||
/// Hide this field if member's (method) returned value matches provided.
|
||||
/// </summary>
|
||||
/// <inheritdoc cref="Predicated(Type, string, object, bool, bool)"/>
|
||||
public Hide(Type type, string member, object value) : base(type, member, value, k_Inverted, k_Hide)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Hide this field if member (method) returns true.
|
||||
/// </summary>
|
||||
/// <inheritdoc cref="Predicated(Type, string, bool, bool)"/>
|
||||
public Hide(Type type, string member) : this(type, member, value: true)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Hide field if owning class is of type.
|
||||
/// </summary>
|
||||
public Hide(Type type) : base(type, k_Inverted, k_Hide)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Hide if field is null or false if reference or boolean respectively.
|
||||
/// </summary>
|
||||
public Hide(string property) : base(property, k_Inverted, k_Hide)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Hide if field matches value.
|
||||
/// </summary>
|
||||
public Hide(string property, object value) : base(property, value, k_Inverted, k_Hide)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Hide if current render pipeline matches.
|
||||
/// </summary>
|
||||
public Hide(RenderPipeline rp) : base(rp, k_Inverted, k_Hide)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
sealed class Enable : Predicated
|
||||
{
|
||||
const bool k_Hide = false;
|
||||
const bool k_Inverted = true;
|
||||
|
||||
/// <summary>
|
||||
/// Enable this field if member's (method) returned value matches provided.
|
||||
/// </summary>
|
||||
/// <inheritdoc cref="Predicated(Type, string, object, bool, bool)"/>
|
||||
public Enable(Type type, string member, object value) : base(type, member, value, k_Inverted, k_Hide)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enable this field if member (method) returns true.
|
||||
/// </summary>
|
||||
/// <inheritdoc cref="Predicated(Type, string, bool, bool)"/>
|
||||
public Enable(Type type, string member) : this(type, member, value: true)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enable field if owning class is of type.
|
||||
/// </summary>
|
||||
public Enable(Type type) : base(type, k_Inverted, k_Hide)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enable if field is null or false if reference or boolean respectively.
|
||||
/// </summary>
|
||||
public Enable(string property) : base(property, k_Inverted, k_Hide)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enable if field matches value.
|
||||
/// </summary>
|
||||
public Enable(string property, object value) : base(property, value, k_Inverted, k_Hide)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enable if current render pipeline matches.
|
||||
/// </summary>
|
||||
public Enable(RenderPipeline rp) : base(rp, k_Inverted, k_Hide)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
sealed class Disable : Predicated
|
||||
{
|
||||
const bool k_Hide = false;
|
||||
const bool k_Inverted = false;
|
||||
|
||||
/// <summary>
|
||||
/// Disable this field if member's (method) returned value matches provided.
|
||||
/// </summary>
|
||||
/// <inheritdoc cref="Predicated(Type, string, object, bool, bool)"/>
|
||||
public Disable(Type type, string member, object value) : base(type, member, value, k_Inverted, k_Hide)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Disable this field if member (method) returns true.
|
||||
/// </summary>
|
||||
/// <inheritdoc cref="Predicated(Type, string, bool, bool)"/>
|
||||
public Disable(Type type, string member) : this(type, member, value: true)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Disable field if owning class is of type.
|
||||
/// </summary>
|
||||
public Disable(Type type) : base(type, k_Inverted, k_Hide)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Disable if field is null or false if reference or boolean respectively.
|
||||
/// </summary>
|
||||
public Disable(string property) : base(property, k_Inverted, k_Hide)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Disable if field matches value.
|
||||
/// </summary>
|
||||
public Disable(string property, object value) : base(property, value, k_Inverted, k_Hide)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Disable if current render pipeline matches.
|
||||
/// </summary>
|
||||
public Disable(RenderPipeline rp) : base(rp, k_Inverted, k_Hide)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using UnityEditor;
|
||||
using UnityEditorInternal;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using WaveHarmonic.Crest.Attributes;
|
||||
@@ -23,19 +24,29 @@ namespace WaveHarmonic.Crest.Editor
|
||||
internal static bool s_HideInInspector = false;
|
||||
public static bool s_IsFoldout = false;
|
||||
public static bool s_IsFoldoutOpen = false;
|
||||
public static bool s_IsList = false;
|
||||
|
||||
public static bool s_TemporaryColor;
|
||||
public static Color s_PreviousColor;
|
||||
|
||||
// If instantiating ourselves. Avoids reflection.
|
||||
public PropertyAttribute _Attribute;
|
||||
public FieldInfo _Field;
|
||||
PropertyAttribute Attribute => _Attribute ?? attribute;
|
||||
FieldInfo Field => _Field ?? fieldInfo;
|
||||
|
||||
public float Space { get; private set; }
|
||||
|
||||
internal UnityEditor.Editor _Editor;
|
||||
internal Inspector _Inspector;
|
||||
|
||||
List<object> _Decorators = null;
|
||||
List<object> Decorators
|
||||
{
|
||||
get
|
||||
{
|
||||
// Populate list with decorators.
|
||||
_Decorators ??= fieldInfo
|
||||
_Decorators ??= Field
|
||||
.GetCustomAttributes(typeof(Decorator), false)
|
||||
.ToList();
|
||||
|
||||
@@ -44,7 +55,7 @@ namespace WaveHarmonic.Crest.Editor
|
||||
}
|
||||
|
||||
List<Attributes.Validator> _Validators = null;
|
||||
List<Attributes.Validator> Validators => _Validators ??= fieldInfo
|
||||
List<Attributes.Validator> Validators => _Validators ??= Field
|
||||
.GetCustomAttributes(typeof(Attributes.Validator), false)
|
||||
.Cast<Attributes.Validator>()
|
||||
.ToList();
|
||||
@@ -63,14 +74,55 @@ namespace WaveHarmonic.Crest.Editor
|
||||
|
||||
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
|
||||
{
|
||||
var height = base.GetPropertyHeight(property, label);
|
||||
|
||||
if (property.isArray)
|
||||
{
|
||||
// Constructor caches value and this call retrieves it.
|
||||
var list = ReorderableList.GetReorderableListFromSerializedProperty(property);
|
||||
list ??= new ReorderableList(property.serializedObject, property);
|
||||
// GetHeight does not include bottom buttons height.
|
||||
height = property.isExpanded ? list.GetHeight() + list.footerHeight : height;
|
||||
}
|
||||
|
||||
// Make original control rectangle be invisible because we always create our own. Zero still adds a little
|
||||
// height which becomes noticeable once multiple properties are hidden. This could be some GUI style
|
||||
// property but could not find which one.
|
||||
return -2f;
|
||||
return s_IsList ? height : -2f;
|
||||
}
|
||||
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
// Get the owning editor.
|
||||
if (_Editor == null)
|
||||
{
|
||||
foreach (var editor in ActiveEditorTracker.sharedTracker?.activeEditors)
|
||||
{
|
||||
if (editor.serializedObject == property.serializedObject)
|
||||
{
|
||||
_Editor = editor;
|
||||
_Inspector = editor as Inspector;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Also check all embedded editors.
|
||||
foreach (var editor in Inspector.s_EmbeddedEditors)
|
||||
{
|
||||
if (editor._Editor == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (editor._Editor.serializedObject == property.serializedObject)
|
||||
{
|
||||
_Editor = editor._Editor;
|
||||
_Inspector = editor._Editor as Inspector;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Store the original GUI state so it can be reset later.
|
||||
var originalColor = GUI.color;
|
||||
var originalEnabled = GUI.enabled;
|
||||
@@ -93,7 +145,7 @@ namespace WaveHarmonic.Crest.Editor
|
||||
{
|
||||
var attribute = (Decorator)Decorators[index];
|
||||
if (attribute is Space space) Space = space._Height;
|
||||
label = attribute.BuildLabel(label);
|
||||
label = attribute.BuildLabel(property, label, this);
|
||||
}
|
||||
|
||||
if (!s_HideInInspector && (!s_IsFoldout || s_IsFoldoutOpen))
|
||||
@@ -106,8 +158,8 @@ namespace WaveHarmonic.Crest.Editor
|
||||
attribute.Decorate(position, property, label, this);
|
||||
}
|
||||
|
||||
var a = (DecoratedProperty)attribute;
|
||||
position = a.NeedsControlRectangle(property)
|
||||
var a = (DecoratedProperty)Attribute;
|
||||
position = a.NeedsControlRectangle(property) && (!s_IsList || property.isArray)
|
||||
? EditorGUILayout.GetControlRect(true, EditorGUI.GetPropertyHeight(property, label, true))
|
||||
: position;
|
||||
|
||||
@@ -117,14 +169,18 @@ namespace WaveHarmonic.Crest.Editor
|
||||
{
|
||||
var attribute = (Decorator)Decorators[index];
|
||||
if (attribute.AlwaysVisible) continue;
|
||||
label = attribute.BuildLabel(label);
|
||||
label = attribute.BuildLabel(property, label, this);
|
||||
}
|
||||
|
||||
var skipChange = fieldInfo.FieldType == typeof(UnityEvent);
|
||||
var skipChange = Field.FieldType == typeof(UnityEvent) || property.isArray;
|
||||
|
||||
var isExpanded = property.isExpanded;
|
||||
var isUndoRedo = false;
|
||||
|
||||
if (!skipChange)
|
||||
{
|
||||
EditorGUI.BeginChangeCheck();
|
||||
isUndoRedo = _Inspector != null && _Inspector._UndoRedo;
|
||||
}
|
||||
|
||||
var oldValue = skipChange ? null : property.boxedValue;
|
||||
@@ -135,13 +191,19 @@ namespace WaveHarmonic.Crest.Editor
|
||||
Validators[index].Validate(position, property, label, this, oldValue);
|
||||
}
|
||||
|
||||
// Guard against foldouts triggering change check due to changing isExpanded.
|
||||
if (!skipChange && EditorGUI.EndChangeCheck() && oldValue != property.boxedValue)
|
||||
if (!skipChange && (EditorGUI.EndChangeCheck() || isUndoRedo))
|
||||
{
|
||||
// Apply any changes.
|
||||
property.serializedObject.ApplyModifiedProperties();
|
||||
if (!isUndoRedo)
|
||||
{
|
||||
property.serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
|
||||
OnChange(property, oldValue);
|
||||
// Guard against foldouts triggering change check due to changing isExpanded.
|
||||
if (property.isExpanded == isExpanded)
|
||||
{
|
||||
OnChange(property, oldValue);
|
||||
}
|
||||
}
|
||||
|
||||
for (var index = 0; index < Decorators.Count; index++)
|
||||
@@ -206,6 +268,7 @@ namespace WaveHarmonic.Crest.Editor
|
||||
var relativePath = string.Join(".", chunks[(i + 1)..]);
|
||||
|
||||
var nestedTarget = nestedProperty.managedReferenceValue;
|
||||
if (nestedTarget == null) continue;
|
||||
var nestedTargetType = nestedTarget.GetType();
|
||||
|
||||
foreach (var (method, attribute) in OnChangeHandlers)
|
||||
|
||||
@@ -19,6 +19,7 @@ namespace WaveHarmonic.Crest.Editor
|
||||
/// </summary>
|
||||
interface IEmbeddableEditor
|
||||
{
|
||||
void SetHostComponent(object host);
|
||||
void SetTypeOfHostComponent(System.Type hostType);
|
||||
}
|
||||
|
||||
@@ -54,7 +55,7 @@ namespace WaveHarmonic.Crest.Editor
|
||||
public void OnDisable()
|
||||
{
|
||||
DestroyEditor();
|
||||
Helpers.Destroy(_DefaultTarget);
|
||||
Helpers.Destroy(_CreatedInstance);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -62,11 +63,12 @@ namespace WaveHarmonic.Crest.Editor
|
||||
/// </summary>
|
||||
public GUIContent _CreateButtonGUIContent;
|
||||
|
||||
UnityEditor.Editor _Editor = null;
|
||||
internal UnityEditor.Editor _Editor = null;
|
||||
|
||||
System.Type _Type;
|
||||
|
||||
Object _DefaultTarget;
|
||||
Object _CreatedInstance;
|
||||
FieldInfo _DefaultTargetField;
|
||||
|
||||
const int k_IndentOffset = 3;
|
||||
@@ -214,7 +216,8 @@ namespace WaveHarmonic.Crest.Editor
|
||||
{
|
||||
if (_DefaultTarget == null)
|
||||
{
|
||||
_DefaultTarget = ScriptableObject.CreateInstance(_Type);
|
||||
_CreatedInstance = ScriptableObject.CreateInstance(_Type);
|
||||
_DefaultTarget = _CreatedInstance;
|
||||
_DefaultTarget.hideFlags = HideFlags.DontSave | HideFlags.NotEditable;
|
||||
}
|
||||
}
|
||||
@@ -253,9 +256,10 @@ namespace WaveHarmonic.Crest.Editor
|
||||
_Editor = UnityEditor.Editor.CreateEditor(target);
|
||||
|
||||
// Pass through argument for editors that receive it
|
||||
if (property.serializedObject.targetObject != null)
|
||||
if (property.serializedObject.targetObject != null && _Editor is IEmbeddableEditor editor)
|
||||
{
|
||||
(_Editor as IEmbeddableEditor)?.SetTypeOfHostComponent(property.serializedObject.targetObject.GetType());
|
||||
editor.SetHostComponent(property.serializedObject.targetObject);
|
||||
editor.SetTypeOfHostComponent(property.serializedObject.targetObject.GetType());
|
||||
}
|
||||
|
||||
_OnCreateEditor?.Invoke(_Editor);
|
||||
|
||||
@@ -294,7 +294,13 @@ namespace WaveHarmonic.Crest.Editor
|
||||
width = Mathf.Max(width, minimumWidth);
|
||||
// TODO: Add option to disable this (consistent width).
|
||||
if (!hasDropDown && minimumWidth > 0) width += k_ButtonDropDownWidth;
|
||||
if (centerLabel && hasDropDown) style.padding.left += k_ButtonDropDownWidth;
|
||||
|
||||
// TODO: eyeballed based on Fix button but likely specific to it.
|
||||
if (centerLabel && hasDropDown)
|
||||
{
|
||||
style.padding.left += k_ButtonDropDownWidth / 2;
|
||||
width += k_ButtonDropDownWidth / 3;
|
||||
}
|
||||
|
||||
if (GUILayout.Button(label, style, expandWidth ? GUILayout.ExpandWidth(true) : GUILayout.Width(width)))
|
||||
{
|
||||
|
||||
@@ -18,13 +18,19 @@ namespace WaveHarmonic.Crest.Editor
|
||||
[CustomEditor(typeof(EditorBehaviour), editorForChildClasses: true)]
|
||||
partial class Inspector : UnityEditor.Editor
|
||||
{
|
||||
public const int k_FieldGroupOrder = 1000;
|
||||
public const int k_FieldGroupOrder = k_FieldHeadingOrder * 100;
|
||||
public const int k_FieldHeadingOrder = k_FieldOrder * 100;
|
||||
public const int k_FieldOrder = 1000;
|
||||
const string k_NoPrefabModeSupportWarning = "Prefab mode is not supported. Changes made in prefab mode will not be reflected in the scene view. Save this prefab to see changes.";
|
||||
|
||||
internal static Inspector Current { get; private set; }
|
||||
|
||||
readonly Dictionary<FieldInfo, object> _MaterialOwners = new();
|
||||
readonly Dictionary<Material, MaterialEditor> _MaterialEditors = new();
|
||||
readonly Dictionary<string, DecoratedDrawer> _Lists = new();
|
||||
|
||||
internal readonly List<EmbeddedAssetEditor> _EmbeddedEditors = new();
|
||||
internal static readonly List<EmbeddedAssetEditor> s_EmbeddedEditors = new();
|
||||
|
||||
public override bool RequiresConstantRepaint() => TexturePreview.s_ActiveInstance?.Open == true;
|
||||
|
||||
@@ -32,12 +38,16 @@ namespace WaveHarmonic.Crest.Editor
|
||||
.GetFieldsWithAttribute<AttachMaterialEditor>()
|
||||
.OrderBy(x => x.GetCustomAttribute<AttachMaterialEditor>().Order);
|
||||
|
||||
readonly List<string> _Headings = new();
|
||||
readonly Utility.SortedList<int, SerializedProperty> _Properties = new(Helpers.DuplicateComparison);
|
||||
|
||||
protected virtual void OnEnable()
|
||||
{
|
||||
_MaterialOwners.Clear();
|
||||
|
||||
Undo.undoRedoPerformed -= OnUndoRedo;
|
||||
Undo.undoRedoPerformed += OnUndoRedo;
|
||||
|
||||
foreach (var field in s_AttachMaterialEditors)
|
||||
{
|
||||
var target = (object)this.target;
|
||||
@@ -60,7 +70,20 @@ namespace WaveHarmonic.Crest.Editor
|
||||
GUI.enabled = (target.hideFlags & HideFlags.NotEditable) == 0;
|
||||
|
||||
RenderBeforeInspectorGUI();
|
||||
RenderInspectorGUI();
|
||||
|
||||
try
|
||||
{
|
||||
RenderInspectorGUI();
|
||||
}
|
||||
catch (InvalidOperationException exception)
|
||||
{
|
||||
// Happens when using New with embedded editor and not change the filename.
|
||||
if (exception.Message != "Stack empty.")
|
||||
{
|
||||
throw exception;
|
||||
}
|
||||
}
|
||||
|
||||
RenderValidationMessages();
|
||||
|
||||
EditorGUI.BeginDisabledGroup(target is Behaviour component && !component.isActiveAndEnabled);
|
||||
@@ -74,10 +97,23 @@ namespace WaveHarmonic.Crest.Editor
|
||||
|
||||
protected virtual void OnDisable()
|
||||
{
|
||||
Undo.undoRedoPerformed -= OnUndoRedo;
|
||||
|
||||
foreach (var (_, editor) in _MaterialEditors)
|
||||
{
|
||||
Helpers.Destroy(editor);
|
||||
}
|
||||
|
||||
foreach (var embedded in _EmbeddedEditors)
|
||||
{
|
||||
embedded?.OnDisable();
|
||||
s_EmbeddedEditors.Remove(embedded);
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void OnChange()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected virtual void RenderBeforeInspectorGUI()
|
||||
@@ -95,10 +131,13 @@ namespace WaveHarmonic.Crest.Editor
|
||||
var previous = Current;
|
||||
Current = this;
|
||||
|
||||
_Headings.Clear();
|
||||
_Properties.Clear();
|
||||
|
||||
serializedObject.Update();
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
using var iterator = serializedObject.GetIterator();
|
||||
if (iterator.NextVisible(true))
|
||||
{
|
||||
@@ -112,7 +151,7 @@ namespace WaveHarmonic.Crest.Editor
|
||||
if (iterator.name == "m_Script")
|
||||
{
|
||||
#if CREST_DEBUG
|
||||
_Properties.Add(index++, property);
|
||||
_Properties.Add(index++ * k_FieldOrder, property);
|
||||
#endif
|
||||
continue;
|
||||
}
|
||||
@@ -129,7 +168,44 @@ namespace WaveHarmonic.Crest.Editor
|
||||
// Null checking but there should always be one DecoratedProperty.
|
||||
var order = field.GetCustomAttribute<Attributes.DecoratedProperty>()?.order ?? 0;
|
||||
group = field.GetCustomAttribute<Group>()?.order * k_FieldGroupOrder ?? group;
|
||||
_Properties.Add(order + group + index++, property);
|
||||
|
||||
var headingAttribute = field.GetCustomAttribute<Heading>();
|
||||
if (headingAttribute != null)
|
||||
{
|
||||
_Headings.Add(headingAttribute._Text.text);
|
||||
}
|
||||
|
||||
var heading = Mathf.Max(0, _Headings.Count - 1);
|
||||
|
||||
var orderAttribute = field.GetCustomAttribute<Order>();
|
||||
|
||||
if (orderAttribute != null)
|
||||
{
|
||||
var target = orderAttribute._Target;
|
||||
|
||||
if (orderAttribute._Placement == Order.Placement.Heading)
|
||||
{
|
||||
heading = _Headings.FindIndex(x => x == target);
|
||||
}
|
||||
}
|
||||
|
||||
var key = order + group + heading * k_FieldHeadingOrder + index * k_FieldOrder;
|
||||
|
||||
// Override.
|
||||
if (orderAttribute != null)
|
||||
{
|
||||
var target = orderAttribute._Target;
|
||||
|
||||
switch (orderAttribute._Placement)
|
||||
{
|
||||
case Order.Placement.Below: key = _Properties.First(x => x.Value.name == target).Key + index; break;
|
||||
case Order.Placement.Above: key = _Properties.First(x => x.Value.name == target).Key - index; break;
|
||||
}
|
||||
}
|
||||
|
||||
_Properties.Add(key, property);
|
||||
|
||||
index += 1;
|
||||
}
|
||||
while (iterator.NextVisible(false));
|
||||
}
|
||||
@@ -140,6 +216,33 @@ namespace WaveHarmonic.Crest.Editor
|
||||
using (new EditorGUI.DisabledGroupScope(property.name == "m_Script"))
|
||||
#endif
|
||||
{
|
||||
// Handle lists as PropertyDrawer is not called on the list itself.
|
||||
if (property.isArray)
|
||||
{
|
||||
var field = property.GetFieldInfo(out var _);
|
||||
var attribute = field?.GetCustomAttribute<Attributes.DecoratedProperty>();
|
||||
|
||||
if (field != null && attribute != null)
|
||||
{
|
||||
var id = GetPropertyIdentifier(property);
|
||||
|
||||
if (!_Lists.ContainsKey(id))
|
||||
{
|
||||
_Lists[id] = new DecoratedDrawer()
|
||||
{
|
||||
_Attribute = attribute,
|
||||
_Field = field,
|
||||
};
|
||||
}
|
||||
|
||||
DecoratedDrawer.s_IsList = true;
|
||||
var label = new GUIContent(property.displayName);
|
||||
_Lists[id].OnGUI(Rect.zero, property, label);
|
||||
DecoratedDrawer.s_IsList = false;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// Only support top level ordering for now.
|
||||
EditorGUILayout.PropertyField(property, includeChildren: true);
|
||||
}
|
||||
@@ -148,11 +251,18 @@ namespace WaveHarmonic.Crest.Editor
|
||||
// Need to call just in case there is no decorated property.
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
OnChange();
|
||||
}
|
||||
|
||||
// Restore previous in case this is a nested editor.
|
||||
Current = previous;
|
||||
|
||||
// Fixes indented validation etc.
|
||||
EditorGUI.indentLevel = 0;
|
||||
|
||||
_UndoRedo = false;
|
||||
}
|
||||
|
||||
protected virtual void RenderBottomButtons()
|
||||
@@ -212,6 +322,55 @@ namespace WaveHarmonic.Crest.Editor
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal virtual void OnCustomField(Rect position, SerializedProperty property, GUIContent label, DecoratedDrawer drawer)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
internal virtual GUIContent OnCustomLabel(SerializedProperty property, GUIContent label, DecoratedDrawer drawer)
|
||||
{
|
||||
return label;
|
||||
}
|
||||
}
|
||||
|
||||
// Reflection
|
||||
partial class Inspector
|
||||
{
|
||||
static readonly PropertyInfo s_GUIViewCurrent = typeof(UnityEditor.Editor).Assembly.GetType("UnityEditor.GUIView").GetProperty("current", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
|
||||
static readonly PropertyInfo s_GUIViewNativeHandle = typeof(UnityEditor.Editor).Assembly.GetType("UnityEditor.GUIView").GetProperty("nativeHandle", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
|
||||
|
||||
// Adapted from:
|
||||
// https://github.com/Unity-Technologies/UnityCsReference/blob/59b03b8a0f179c0b7e038178c90b6c80b340aa9f/Editor/Mono/Inspector/ReorderableListWrapper.cs#L77-L88
|
||||
static string GetPropertyIdentifier(SerializedProperty serializedProperty)
|
||||
{
|
||||
// Property may be disposed.
|
||||
try
|
||||
{
|
||||
var handle = -1;
|
||||
var current = s_GUIViewCurrent.GetValue(null);
|
||||
|
||||
if (current != null)
|
||||
{
|
||||
handle = ((IntPtr)s_GUIViewNativeHandle.GetValue(current)).ToInt32();
|
||||
}
|
||||
|
||||
return serializedProperty?.propertyPath + serializedProperty.serializedObject.targetObject.GetEntityId() + handle;
|
||||
}
|
||||
catch (NullReferenceException)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
partial class Inspector
|
||||
{
|
||||
internal bool _UndoRedo;
|
||||
void OnUndoRedo()
|
||||
{
|
||||
_UndoRedo = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Adapted from:
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using UnityEditor.Build;
|
||||
using UnityEngine;
|
||||
|
||||
namespace WaveHarmonic.Crest.Editor.Reflected
|
||||
{
|
||||
static class BuildTargetGroup
|
||||
{
|
||||
public const int k_Server = -2;
|
||||
}
|
||||
|
||||
static class BuildPlatform
|
||||
{
|
||||
internal static readonly Type s_BuildPlatformType = Type.GetType("UnityEditor.Build.BuildPlatform,UnityEditor.CoreModule");
|
||||
internal static readonly Type s_BuildPlatformArrayType = s_BuildPlatformType.MakeArrayType();
|
||||
|
||||
static readonly FieldInfo s_NamedBuildTargetField = s_BuildPlatformType.GetField
|
||||
(
|
||||
"namedBuildTarget",
|
||||
BindingFlags.Instance | BindingFlags.Public
|
||||
);
|
||||
|
||||
public static NamedBuildTarget GetNamedBuildTarget(object platform)
|
||||
{
|
||||
return (NamedBuildTarget)s_NamedBuildTargetField.GetValue(platform);
|
||||
}
|
||||
}
|
||||
|
||||
static class BuildPlatforms
|
||||
{
|
||||
static readonly Type s_BuildPlatformsType = Type.GetType("UnityEditor.Build.BuildPlatforms,UnityEditor.CoreModule");
|
||||
static readonly PropertyInfo s_BuildPlatformsInstanceProperty = s_BuildPlatformsType.GetProperty("instance", BindingFlags.Static | BindingFlags.Public);
|
||||
static readonly MethodInfo s_GetValidPlatformsMethod = s_BuildPlatformsType.GetMethod("GetValidPlatforms", new Type[] { });
|
||||
static Array s_Platforms; // Should be safe to cache.
|
||||
|
||||
public static Array GetValidPlatforms()
|
||||
{
|
||||
if (s_Platforms == null)
|
||||
{
|
||||
var instance = s_BuildPlatformsInstanceProperty.GetValue(null);
|
||||
|
||||
// We cannot just cast to the type we want it seems.
|
||||
var enumerable = ((IEnumerable<object>)s_GetValidPlatformsMethod.Invoke(instance, null)).ToList();
|
||||
|
||||
s_Platforms = Array.CreateInstance(BuildPlatform.s_BuildPlatformType, enumerable.Count);
|
||||
|
||||
for (var i = 0; i < enumerable.Count; i++)
|
||||
{
|
||||
s_Platforms.SetValue(enumerable[i], i);
|
||||
}
|
||||
}
|
||||
|
||||
return s_Platforms;
|
||||
}
|
||||
}
|
||||
|
||||
static class EditorGUILayout
|
||||
{
|
||||
static readonly MethodInfo s_BeginPlatformGroupingMethod = typeof(UnityEditor.EditorGUILayout).GetMethod
|
||||
(
|
||||
"BeginPlatformGrouping",
|
||||
BindingFlags.Static | BindingFlags.NonPublic,
|
||||
null,
|
||||
new Type[]
|
||||
{
|
||||
BuildPlatform.s_BuildPlatformArrayType,
|
||||
typeof(GUIContent),
|
||||
},
|
||||
null
|
||||
);
|
||||
|
||||
static readonly object[] s_Parameters = new object[2];
|
||||
|
||||
public static int BeginBuildTargetSelectionGrouping(GUIContent defaultTab)
|
||||
{
|
||||
var platforms = BuildPlatforms.GetValidPlatforms();
|
||||
|
||||
s_Parameters[0] = platforms;
|
||||
s_Parameters[1] = defaultTab;
|
||||
|
||||
var index = (int)s_BeginPlatformGroupingMethod.Invoke(null, s_Parameters);
|
||||
|
||||
if (index < 0)
|
||||
{
|
||||
// Default
|
||||
return (int)UnityEditor.BuildTargetGroup.Unknown;
|
||||
}
|
||||
|
||||
var target = BuildPlatform.GetNamedBuildTarget(platforms.GetValue(index));
|
||||
|
||||
if (target == NamedBuildTarget.Server)
|
||||
{
|
||||
// Server
|
||||
return BuildTargetGroup.k_Server;
|
||||
}
|
||||
|
||||
return (int)target.ToBuildTargetGroup();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cd362a01f52cc4002857e9f549c641be
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -10,10 +10,19 @@ namespace WaveHarmonic.Crest.Editor.Settings
|
||||
{
|
||||
static class ScriptingSymbols
|
||||
{
|
||||
static NamedBuildTarget CurrentNamedBuildTarget
|
||||
// Too lazy to add separate calls just to provide a NamedBuildTarget.
|
||||
internal static bool s_OverrideCurrentNamedBuildTarget;
|
||||
internal static NamedBuildTarget s_CurrentNamedBuildTargetOverride;
|
||||
|
||||
internal static NamedBuildTarget CurrentNamedBuildTarget
|
||||
{
|
||||
get
|
||||
{
|
||||
if (s_OverrideCurrentNamedBuildTarget)
|
||||
{
|
||||
return s_CurrentNamedBuildTargetOverride;
|
||||
}
|
||||
|
||||
#if UNITY_SERVER
|
||||
return NamedBuildTarget.Server;
|
||||
#else
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace WaveHarmonic.Crest.Editor
|
||||
static Dictionary<string, string> s_Tooltips;
|
||||
static readonly GUIContent s_Label = new();
|
||||
|
||||
public static void DrawShaderGraphGUI(MaterialEditor materialEditor, IEnumerable<MaterialProperty> properties, Dictionary<string, string> tooltips)
|
||||
public static void DrawShaderGraphGUI(MaterialEditor materialEditor, IEnumerable<MaterialProperty> properties, Dictionary<string, string> tooltips, List<string> hiddenCategories)
|
||||
{
|
||||
s_Tooltips = tooltips;
|
||||
Material m = materialEditor.target as Material;
|
||||
@@ -37,7 +37,7 @@ namespace WaveHarmonic.Crest.Editor
|
||||
}
|
||||
|
||||
if (metadata != null)
|
||||
DrawShaderGraphGUI(materialEditor, properties, metadata.categoryDatas);
|
||||
DrawShaderGraphGUI(materialEditor, properties, metadata.categoryDatas, hiddenCategories);
|
||||
else
|
||||
PropertiesDefaultGUI(materialEditor, properties);
|
||||
}
|
||||
@@ -76,10 +76,15 @@ namespace WaveHarmonic.Crest.Editor
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void DrawShaderGraphGUI(MaterialEditor materialEditor, IEnumerable<MaterialProperty> properties, IEnumerable<MinimalCategoryData> categoryDatas)
|
||||
public static void DrawShaderGraphGUI(MaterialEditor materialEditor, IEnumerable<MaterialProperty> properties, IEnumerable<MinimalCategoryData> categoryDatas, List<string> hiddenCategories)
|
||||
{
|
||||
foreach (MinimalCategoryData mcd in categoryDatas)
|
||||
{
|
||||
if (hiddenCategories.Count > 0 && hiddenCategories.Contains(mcd.categoryName))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
DrawCategory(materialEditor, properties, mcd);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,10 @@ namespace WaveHarmonic.Crest.Editor
|
||||
{
|
||||
abstract class TexturePreview : ObjectPreview
|
||||
{
|
||||
static readonly System.Reflection.MethodInfo s_DrawPreview = typeof(ObjectPreview).GetMethod("DrawPreview", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic);
|
||||
static readonly object[] s_DrawPreviewArguments = new object[3];
|
||||
static readonly Object[] s_DrawPreviewTargets = new Object[1];
|
||||
|
||||
public static TexturePreview s_ActiveInstance;
|
||||
public bool Open { get; private set; }
|
||||
|
||||
@@ -101,6 +105,9 @@ namespace WaveHarmonic.Crest.Editor
|
||||
Helpers.SafeCreateRenderTexture(ref _RenderTexture, descriptor);
|
||||
_RenderTexture.Create();
|
||||
Object.DestroyImmediate(_Editor);
|
||||
// Raises both, but no way to avoid it:
|
||||
// | The targets array should not be used inside OnSceneGUI or OnPreviewGUI. Use the single target property instead.
|
||||
// | The serializedObject should not be used inside OnSceneGUI or OnPreviewGUI. Use the target property directly instead.
|
||||
_Editor = UnityEditor.Editor.CreateEditor(_RenderTexture);
|
||||
// Reset for incompatible copy.
|
||||
descriptor = _OriginalDescriptor;
|
||||
@@ -121,7 +128,13 @@ namespace WaveHarmonic.Crest.Editor
|
||||
Graphics.CopyTexture(Texture, _RenderTexture);
|
||||
}
|
||||
|
||||
_Editor.DrawPreview(rect);
|
||||
s_DrawPreviewTargets[0] = _Editor.target;
|
||||
s_DrawPreviewArguments[0] = _Editor;
|
||||
s_DrawPreviewArguments[1] = rect;
|
||||
s_DrawPreviewArguments[2] = s_DrawPreviewTargets;
|
||||
|
||||
// Use to be _Editor.DrawPreview(rect) but spammed errors with multiple selected.
|
||||
s_DrawPreview?.Invoke(null, s_DrawPreviewArguments);
|
||||
}
|
||||
|
||||
#if CREST_DEBUG
|
||||
|
||||
@@ -9,6 +9,7 @@ using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using WaveHarmonic.Crest.Editor;
|
||||
using WaveHarmonic.Crest.Internal;
|
||||
|
||||
namespace WaveHarmonic.Crest.Editor
|
||||
@@ -54,9 +55,9 @@ namespace WaveHarmonic.Crest.Editor
|
||||
new(),
|
||||
};
|
||||
|
||||
public delegate void ShowMessage(string message, string fixDescription, MessageType type, Object @object = null, FixValidation action = null, string property = null);
|
||||
public delegate void ShowMessage(string message, string fixDescription, MessageType type, Object @object = null, FixValidation action = null, string property = null, Object caller = null);
|
||||
|
||||
public static void DebugLog(string message, string fixDescription, MessageType type, Object @object = null, FixValidation action = null, string property = null)
|
||||
public static void DebugLog(string message, string fixDescription, MessageType type, Object @object = null, FixValidation action = null, string property = null, Object caller = null)
|
||||
{
|
||||
// Never log info validation to console.
|
||||
if (type == MessageType.Info)
|
||||
@@ -64,22 +65,27 @@ namespace WaveHarmonic.Crest.Editor
|
||||
return;
|
||||
}
|
||||
|
||||
message = $"Crest Validation: {message} {fixDescription} Click this message to highlight the problem object.";
|
||||
// Always link back to the caller so developers know the origin. They can always
|
||||
// use the help box "Inspect" once there to get to the object to fix. Even better,
|
||||
// they can use any available fix buttons too.
|
||||
var context = caller != null ? caller : @object;
|
||||
|
||||
message = $"<b>Crest Validation:</b> {message} {fixDescription} Click this message to highlight the problem object.";
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case MessageType.Error: Debug.LogError(message, @object); break;
|
||||
case MessageType.Warning: Debug.LogWarning(message, @object); break;
|
||||
default: Debug.Log(message, @object); break;
|
||||
case MessageType.Error: Debug.LogError(message, context); break;
|
||||
case MessageType.Warning: Debug.LogWarning(message, context); break;
|
||||
default: Debug.Log(message, context); break;
|
||||
}
|
||||
}
|
||||
|
||||
public static void HelpBox(string message, string fixDescription, MessageType type, Object @object = null, FixValidation action = null, string property = null)
|
||||
public static void HelpBox(string message, string fixDescription, MessageType type, Object @object = null, FixValidation action = null, string property = null, Object caller = null)
|
||||
{
|
||||
s_Messages[(int)type].Add(new() { _Message = message, _FixDescription = fixDescription, _Object = @object, _Action = action, _PropertyPath = property });
|
||||
}
|
||||
|
||||
public static void Suppressed(string _0, string _1, MessageType _2, Object _3 = null, FixValidation _4 = null, string _5 = null)
|
||||
public static void Suppressed(string _0, string _1, MessageType _2, Object _3 = null, FixValidation _4 = null, string _5 = null, Object _6 = null)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -291,6 +297,24 @@ namespace WaveHarmonic.Crest.Editor
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE: Nested components do not descend from Object, but they could and this
|
||||
// would work for them.
|
||||
if (target is Object @object)
|
||||
{
|
||||
foreach (var field in TypeCache.GetFieldsWithAttribute<Validated>())
|
||||
{
|
||||
if (field.DeclaringType != type)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach (var attribute in field.GetCustomAttributes<Validated>())
|
||||
{
|
||||
isValid &= attribute.Validate(@object, field, messenger);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return isValid;
|
||||
}
|
||||
|
||||
@@ -299,4 +323,89 @@ namespace WaveHarmonic.Crest.Editor
|
||||
return ExecuteValidators(target, DebugLog);
|
||||
}
|
||||
}
|
||||
|
||||
abstract class Validated : System.Attribute
|
||||
{
|
||||
public abstract bool Validate(Object target, FieldInfo property, ValidatedHelper.ShowMessage messenger);
|
||||
}
|
||||
}
|
||||
|
||||
namespace WaveHarmonic.Crest
|
||||
{
|
||||
/// <summary>
|
||||
/// Validates that field is not null.
|
||||
/// </summary>
|
||||
[System.AttributeUsage(System.AttributeTargets.Field, AllowMultiple = false)]
|
||||
sealed class Required : Validated
|
||||
{
|
||||
public override bool Validate(Object target, FieldInfo field, ValidatedHelper.ShowMessage messenger)
|
||||
{
|
||||
var isValid = true;
|
||||
|
||||
if ((Object)field.GetValue(target) == null)
|
||||
{
|
||||
var typeName = EditorHelpers.Pretty(target.GetType().Name);
|
||||
var fieldName = EditorHelpers.Pretty(field.Name);
|
||||
|
||||
messenger
|
||||
(
|
||||
$"<i>{fieldName}</i> is required for the <i>{typeName}</i> component to function.",
|
||||
$"Please set <i>{fieldName}</i>.",
|
||||
ValidatedHelper.MessageType.Error,
|
||||
target
|
||||
);
|
||||
|
||||
isValid = false;
|
||||
}
|
||||
|
||||
return isValid;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Shows a info message if field is null.
|
||||
/// </summary>
|
||||
[System.AttributeUsage(System.AttributeTargets.Field, AllowMultiple = false)]
|
||||
sealed class Optional : Validated
|
||||
{
|
||||
readonly string _Message;
|
||||
|
||||
public Optional(string message)
|
||||
{
|
||||
_Message = message;
|
||||
}
|
||||
|
||||
public override bool Validate(Object target, FieldInfo field, ValidatedHelper.ShowMessage messenger)
|
||||
{
|
||||
var value = field.GetValue(target);
|
||||
|
||||
if (value is ICollection<Object> list)
|
||||
{
|
||||
if (list != null && list.Count > 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (value is Object @object && @object != null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
var typeName = EditorHelpers.Pretty(target.GetType().Name);
|
||||
var fieldName = EditorHelpers.Pretty(field.Name);
|
||||
|
||||
messenger
|
||||
(
|
||||
$"<i>{fieldName}</i> is not set for the <i>{typeName}</i> component. " + _Message,
|
||||
string.Empty,
|
||||
ValidatedHelper.MessageType.Info,
|
||||
target
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
using UnityEngine.Rendering.HighDefinition;
|
||||
using UnityEngine.Rendering.Universal;
|
||||
using WaveHarmonic.Crest.Editor.Settings;
|
||||
using WaveHarmonic.Crest.Internal;
|
||||
using WaveHarmonic.Crest.Watercraft;
|
||||
|
||||
@@ -20,6 +21,9 @@ namespace WaveHarmonic.Crest.Editor
|
||||
{
|
||||
// HDRP sub-shader always first.
|
||||
const int k_SubShaderIndexHDRP = 0;
|
||||
const string k_NoneQueryProviderCollisionFloatingObjects = "The floating objects in the scene will use a flat horizontal plane.";
|
||||
const string k_NoneQueryProviderFlowFloatingObjects = "The floating objects in the scene will not receive motion from flow.";
|
||||
|
||||
internal static WaterRenderer Water => Utility.Water;
|
||||
static readonly System.Collections.Generic.List<Terrain> s_Terrains = new();
|
||||
static readonly ShaderTagId s_RenderPipelineShaderTagID = new("RenderPipeline");
|
||||
@@ -253,16 +257,15 @@ namespace WaveHarmonic.Crest.Editor
|
||||
return isValid;
|
||||
}
|
||||
|
||||
#if !d_Crest_LegacyUnderwater
|
||||
if (target.AllCameras)
|
||||
{
|
||||
messenger
|
||||
(
|
||||
"<i>All Cameras</i> requires <i>Legacy Underwater</i> to be enabled.",
|
||||
"Either disable <i>All Cameras</i> or enable <i>Project Settings > Crest > Legacy Underwater</i>.",
|
||||
MessageType.Warning, water
|
||||
);
|
||||
}
|
||||
#if d_Crest_SimpleTransparency
|
||||
messenger
|
||||
(
|
||||
"Currently the underwater effect will force enable both the opaque and depth texture which negates most of the benefit of simple transparency.",
|
||||
"Disable underwater.",
|
||||
MessageType.Info, water,
|
||||
(x, y) => y.boolValue = false,
|
||||
nameof(WaterRenderer._Underwater) + "." + nameof(UnderwaterRenderer._Enabled)
|
||||
);
|
||||
#endif
|
||||
|
||||
if (target.Material != null)
|
||||
@@ -448,7 +451,7 @@ namespace WaveHarmonic.Crest.Editor
|
||||
ValidateMaterialParent(target.Surface.VolumeMaterial, target.Surface.Material, messenger);
|
||||
}
|
||||
|
||||
if (Object.FindObjectsByType<WaterRenderer>(FindObjectsInactive.Exclude, FindObjectsSortMode.None).Length > 1)
|
||||
if (Helpers.FindObjectsByType<WaterRenderer>().Length > 1)
|
||||
{
|
||||
messenger
|
||||
(
|
||||
@@ -554,7 +557,7 @@ namespace WaveHarmonic.Crest.Editor
|
||||
{
|
||||
foreach (var simulation in target.Simulations)
|
||||
{
|
||||
ValidateSimulationAndMaterial(OptionalLod.Get(simulation.GetType()), messenger, water);
|
||||
ValidateSimulationAndMaterial(OptionalLod.Get(simulation.GetType()), messenger, water, target);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -568,7 +571,7 @@ namespace WaveHarmonic.Crest.Editor
|
||||
);
|
||||
}
|
||||
|
||||
if (target.Viewer == null && !target.IsRunningWithoutGraphics)
|
||||
if (target.Viewer == null && !target.IsRunningWithoutGraphics && !target.MultipleViewpoints)
|
||||
{
|
||||
messenger
|
||||
(
|
||||
@@ -692,7 +695,7 @@ namespace WaveHarmonic.Crest.Editor
|
||||
|
||||
var water = Water;
|
||||
|
||||
if (Object.FindObjectsByType<WaterRenderer>(FindObjectsInactive.Include, FindObjectsSortMode.None).Length == 0)
|
||||
if (Helpers.FindObjectsByType<WaterRenderer>(FindObjectsInactive.Include).Length == 0)
|
||||
{
|
||||
messenger
|
||||
(
|
||||
@@ -727,8 +730,7 @@ namespace WaveHarmonic.Crest.Editor
|
||||
if (target.Clipped && water != null)
|
||||
{
|
||||
// Validate main material, then overriden material.
|
||||
ValidateLod(OptionalLod.Get(typeof(ClipLod)), messenger, water);
|
||||
ValidateLod(OptionalLod.Get(typeof(ClipLod)), messenger, water, material: target._Material);
|
||||
ValidateLod(OptionalLod.Get(typeof(ClipLod)), messenger, water, material: target._Material, context: target);
|
||||
|
||||
if (water.ClipLod.DefaultClippingState == DefaultClippingState.NothingClipped)
|
||||
{
|
||||
@@ -738,7 +740,8 @@ namespace WaveHarmonic.Crest.Editor
|
||||
$"The {nameof(WaterBody.Clipped)} option will have no effect.",
|
||||
$"Disable {nameof(WaterBody.Clipped)} or set {nameof(ClipLod.DefaultClippingState)} to {DefaultClippingState.NothingClipped}.",
|
||||
MessageType.Warning,
|
||||
water
|
||||
water,
|
||||
caller: target
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -759,6 +762,8 @@ namespace WaveHarmonic.Crest.Editor
|
||||
return isValid;
|
||||
}
|
||||
|
||||
isValid &= ValidateProjectSettings(target, water, messenger, context);
|
||||
|
||||
var simulation = target.GetLod(water);
|
||||
|
||||
var dependentClause = ".";
|
||||
@@ -787,7 +792,8 @@ namespace WaveHarmonic.Crest.Editor
|
||||
simulation._Enabled = false;
|
||||
}
|
||||
},
|
||||
$"{target.PropertyName}.{nameof(Lod._Enabled)}"
|
||||
$"{target.PropertyName}.{nameof(Lod._Enabled)}",
|
||||
context
|
||||
);
|
||||
|
||||
isValid = false;
|
||||
@@ -802,20 +808,20 @@ namespace WaveHarmonic.Crest.Editor
|
||||
{
|
||||
if (material.HasProperty(target.MaterialProperty) && material.GetFloat(target.MaterialProperty) != 1f)
|
||||
{
|
||||
ShowMaterialValidationMessage(target, material, messenger);
|
||||
ShowMaterialValidationMessage(target, material, messenger, context);
|
||||
isValid = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (target.Dependency != null)
|
||||
{
|
||||
ValidateLod(OptionalLod.Get(target.Dependency), messenger, water, dependent);
|
||||
ValidateLod(OptionalLod.Get(target.Dependency), messenger, water, dependent, context: context);
|
||||
}
|
||||
|
||||
return isValid;
|
||||
}
|
||||
|
||||
static bool ValidateSignedDistanceFieldsLod(ShowMessage messenger, WaterRenderer water, string feature)
|
||||
static bool ValidateSignedDistanceFieldsLod(ShowMessage messenger, WaterRenderer water, string feature, Object context)
|
||||
{
|
||||
var isValid = true;
|
||||
|
||||
@@ -827,7 +833,8 @@ namespace WaveHarmonic.Crest.Editor
|
||||
"Enable <i>Signed Distance Fields</i>",
|
||||
MessageType.Error, water,
|
||||
(_, y) => y.boolValue = true,
|
||||
$"{nameof(WaterRenderer._DepthLod)}.{nameof(DepthLod._EnableSignedDistanceFields)}"
|
||||
$"{nameof(WaterRenderer._DepthLod)}.{nameof(DepthLod._EnableSignedDistanceFields)}",
|
||||
caller: context
|
||||
);
|
||||
|
||||
isValid = false;
|
||||
@@ -836,7 +843,7 @@ namespace WaveHarmonic.Crest.Editor
|
||||
return isValid;
|
||||
}
|
||||
|
||||
static void ShowMaterialValidationMessage(OptionalLod target, Material material, ShowMessage messenger)
|
||||
static void ShowMaterialValidationMessage(OptionalLod target, Material material, ShowMessage messenger, Object caller)
|
||||
{
|
||||
messenger
|
||||
(
|
||||
@@ -847,13 +854,43 @@ namespace WaveHarmonic.Crest.Editor
|
||||
);
|
||||
}
|
||||
|
||||
static bool ValidateSimulationAndMaterial(OptionalLod target, ShowMessage messenger, WaterRenderer water)
|
||||
static bool ValidateProjectSettings(OptionalLod target, WaterRenderer water, ShowMessage messenger, Object caller)
|
||||
{
|
||||
var isValid = true;
|
||||
|
||||
var lod = target.GetLod(water);
|
||||
|
||||
if (lod._Enabled && !target.GetProjectSettingToggle())
|
||||
{
|
||||
var platform = ScriptingSymbols.CurrentNamedBuildTarget;
|
||||
|
||||
messenger
|
||||
(
|
||||
$"<i>{target.PropertyLabel}</i> must be enabled for this platform in the project settings.",
|
||||
$"Enable <i>Project Settings > Crest > Features > Default/{platform.TargetName} > {target.PropertyLabel}</i>. " +
|
||||
$"It will be in either Default or {platform.TargetName}",
|
||||
MessageType.Error, ProjectSettings.Instance,
|
||||
caller: caller
|
||||
);
|
||||
|
||||
isValid = false;
|
||||
}
|
||||
|
||||
return isValid;
|
||||
}
|
||||
|
||||
static bool ValidateSimulationAndMaterial(OptionalLod target, ShowMessage messenger, WaterRenderer water, Object caller)
|
||||
{
|
||||
if (target == null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!ValidateProjectSettings(target, water, messenger, caller))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!target.HasMaterialToggle)
|
||||
{
|
||||
return true;
|
||||
@@ -875,7 +912,7 @@ namespace WaveHarmonic.Crest.Editor
|
||||
|
||||
if (feature._Enabled)
|
||||
{
|
||||
ShowMaterialValidationMessage(target, water.Surface.Material, messenger);
|
||||
ShowMaterialValidationMessage(target, water.Surface.Material, messenger, caller);
|
||||
}
|
||||
else if (messenger != DebugLog)
|
||||
{
|
||||
@@ -897,13 +934,16 @@ namespace WaveHarmonic.Crest.Editor
|
||||
|
||||
var water = Object.FindAnyObjectByType<WaterRenderer>(FindObjectsInactive.Include);
|
||||
|
||||
if (!target.OverrideGlobalWindSpeed && water != null && water.WindSpeedKPH < WaterRenderer.k_MaximumWindSpeedKPH)
|
||||
var windSpeedSource = target.GetWindSpeedSource();
|
||||
|
||||
if (windSpeedSource != ShapeWaves.WindSpeedSource.None)
|
||||
{
|
||||
messenger
|
||||
(
|
||||
$"The wave spectrum is limited by the <i>Global Wind Speed</i> on the <i>Water Renderer</i> to {water.WindSpeedKPH} KPH.",
|
||||
$"If you want fully developed waves, either override the wind speed on this component or increase the <i>Global Wind Speed</i>.",
|
||||
MessageType.Info
|
||||
WaveSpectrumEditor.GetWindSpeedText(target, windSpeedSource),
|
||||
WaveSpectrumEditor.GetWindSpeedFixText(windSpeedSource),
|
||||
MessageType.Info,
|
||||
caller: target
|
||||
);
|
||||
}
|
||||
|
||||
@@ -921,12 +961,29 @@ namespace WaveHarmonic.Crest.Editor
|
||||
|
||||
if (Water != null)
|
||||
{
|
||||
isValid &= ValidateLod(OptionalLod.Get(typeof(AnimatedWavesLod)), messenger, Water);
|
||||
isValid &= ValidateLod(OptionalLod.Get(typeof(AnimatedWavesLod)), messenger, Water, context: target);
|
||||
}
|
||||
|
||||
return isValid;
|
||||
}
|
||||
|
||||
[Validator(typeof(ShapeFFT))]
|
||||
static bool Validate(ShapeFFT target, ShowMessage messenger)
|
||||
{
|
||||
if (target.Spectrum != null && target.Spectrum._ShowAdvancedControls && !target.ApplyAdvancedSpectrumControls)
|
||||
{
|
||||
messenger
|
||||
(
|
||||
$"{nameof(ShapeFFT.ApplyAdvancedSpectrumControls).Pretty().Italic()} needs to be enabled for anything exposed by {nameof(target.Spectrum._ShowAdvancedControls).Pretty().Italic()} to apply.",
|
||||
string.Empty,
|
||||
MessageType.Info,
|
||||
caller: target
|
||||
);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[Validator(typeof(SphereWaterInteraction))]
|
||||
static bool Validate(SphereWaterInteraction target, ShowMessage messenger)
|
||||
{
|
||||
@@ -935,7 +992,7 @@ namespace WaveHarmonic.Crest.Editor
|
||||
// Validate require water feature.
|
||||
if (Water != null)
|
||||
{
|
||||
isValid &= ValidateLod(OptionalLod.Get(typeof(DynamicWavesLod)), messenger, Water);
|
||||
isValid &= ValidateLod(OptionalLod.Get(typeof(DynamicWavesLod)), messenger, Water, context: target);
|
||||
}
|
||||
|
||||
return isValid;
|
||||
@@ -949,19 +1006,19 @@ namespace WaveHarmonic.Crest.Editor
|
||||
// Validate require water feature.
|
||||
if (Water != null)
|
||||
{
|
||||
isValid &= !target.UsesClip || ValidateLod(OptionalLod.Get(typeof(ClipLod)), messenger, Water);
|
||||
isValid &= !target.UsesDisplacement || ValidateLod(OptionalLod.Get(typeof(AnimatedWavesLod)), messenger, Water);
|
||||
isValid &= !target.UsesClip || ValidateLod(OptionalLod.Get(typeof(ClipLod)), messenger, Water, context: target);
|
||||
isValid &= !target.UsesDisplacement || ValidateLod(OptionalLod.Get(typeof(AnimatedWavesLod)), messenger, Water, context: target);
|
||||
isValid &= !target.UsesDisplacement || ValidateCollisionLayer(CollisionLayer.AfterDynamicWaves, target, messenger, "mode", target.Mode, required: true);
|
||||
}
|
||||
|
||||
return isValid;
|
||||
}
|
||||
|
||||
internal static void FixSetCollisionSourceToCompute(SerializedObject _, SerializedProperty property)
|
||||
internal static void FixSetQuerySourceToCompute(SerializedObject _, SerializedProperty property)
|
||||
{
|
||||
if (Water != null)
|
||||
{
|
||||
property.enumValueIndex = (int)CollisionSource.GPU;
|
||||
property.enumValueIndex = (int)LodQuerySource.GPU;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -978,7 +1035,8 @@ namespace WaveHarmonic.Crest.Editor
|
||||
}
|
||||
|
||||
isValid &= ValidateCollisionLayer(target.Layer, target, messenger, "layer", target.Layer, required: false);
|
||||
isValid &= ValidateCollisionSource(target, messenger);
|
||||
isValid &= ValidateQuerySource(target, messenger, Water.AnimatedWavesLod, k_NoneQueryProviderCollisionFloatingObjects);
|
||||
isValid &= ValidateQuerySource(target, messenger, Water.FlowLod, k_NoneQueryProviderFlowFloatingObjects);
|
||||
|
||||
return isValid;
|
||||
}
|
||||
@@ -994,7 +1052,8 @@ namespace WaveHarmonic.Crest.Editor
|
||||
}
|
||||
|
||||
isValid &= ValidateCollisionLayer(target._Layer, target, messenger, "layer", target._Layer, required: false);
|
||||
isValid &= ValidateCollisionSource(target, messenger);
|
||||
isValid &= ValidateQuerySource(target, messenger, Water.AnimatedWavesLod, k_NoneQueryProviderCollisionFloatingObjects);
|
||||
isValid &= ValidateQuerySource(target, messenger, Water.FlowLod, k_NoneQueryProviderFlowFloatingObjects);
|
||||
|
||||
return isValid;
|
||||
}
|
||||
@@ -1139,12 +1198,46 @@ namespace WaveHarmonic.Crest.Editor
|
||||
// Validate that any water feature required for this input is enabled, if any
|
||||
if (Water != null)
|
||||
{
|
||||
isValid &= ValidateLod(OptionalLod.Get(target.GetType()), messenger, Water);
|
||||
isValid &= ValidateLod(OptionalLod.Get(target.GetType()), messenger, Water, context: target);
|
||||
}
|
||||
|
||||
return isValid;
|
||||
}
|
||||
|
||||
[Validator(typeof(LevelLodInput))]
|
||||
static bool ValidateLevelLodInput(LevelLodInput target, ShowMessage messenger)
|
||||
{
|
||||
var isValid = true;
|
||||
|
||||
if (target.Mode is LodInputMode.Geometry or LodInputMode.Spline)
|
||||
{
|
||||
if (target.Blend is LodInputBlend.Minimum or LodInputBlend.Maximum && target.Weight < 1f)
|
||||
{
|
||||
messenger
|
||||
(
|
||||
"Weight with minimum or maximum blend modes do not always behave correctly. " +
|
||||
"Any weight less than one will move the value in the simulation towards zero, rather than towards the existing value in the simulation. " +
|
||||
"For example, this input with a zero weight, and with a blend mode set to maximum, will replace any negative water level instead of not doing anything.",
|
||||
"", // Nothing to suggest yet, as in cases this is still valid.
|
||||
MessageType.Warning,
|
||||
target
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
var water = Water;
|
||||
|
||||
if (water == null)
|
||||
{
|
||||
return isValid;
|
||||
}
|
||||
|
||||
ValidateDisplacementPrecisionIssues(water, target, messenger);
|
||||
ValidateWaterLevelPrecisionIssues(water, target, messenger);
|
||||
|
||||
return isValid;
|
||||
}
|
||||
|
||||
[Validator(typeof(DepthProbe))]
|
||||
static bool Validate(DepthProbe target, ShowMessage messenger)
|
||||
{
|
||||
@@ -1223,18 +1316,6 @@ namespace WaveHarmonic.Crest.Editor
|
||||
}
|
||||
#endif // d_Unity_Terrain
|
||||
|
||||
if (target._Debug._ForceAlwaysUpdateDebug)
|
||||
{
|
||||
messenger
|
||||
(
|
||||
$"<i>Force Always Update Debug</i> option is enabled on depth probe <i>{target.gameObject.name}</i>, which means it will render every frame instead of running from the probe.",
|
||||
"Disable the <i>Force Always Update Debug</i> option.",
|
||||
MessageType.Warning, target,
|
||||
(_, y) => y.boolValue = false,
|
||||
$"{nameof(DepthProbe._Debug)}.{nameof(DepthProbe._Debug._ForceAlwaysUpdateDebug)}"
|
||||
);
|
||||
}
|
||||
|
||||
if (target._Resolution < 4)
|
||||
{
|
||||
messenger
|
||||
@@ -1312,7 +1393,8 @@ namespace WaveHarmonic.Crest.Editor
|
||||
$"This can cause the <i>{nameof(DepthProbe)}</i> not to work. " +
|
||||
$"Unity fixed this in 2022.3.23f1.",
|
||||
$"If you are experiencing problems, disable depth priming or upgrade Unity.",
|
||||
MessageType.Info, urpRenderer
|
||||
MessageType.Info, urpRenderer,
|
||||
caller: target
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1326,7 +1408,8 @@ namespace WaveHarmonic.Crest.Editor
|
||||
$"This can cause the <i>{nameof(DepthProbe)}</i> not to work. " +
|
||||
$"Unity fixed this in 2022.3.23f1.",
|
||||
$"If you are experiencing problems, disable SSAO or upgrade Unity.",
|
||||
MessageType.Info, urpRenderer
|
||||
MessageType.Info, urpRenderer,
|
||||
caller: target
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1349,7 +1432,8 @@ namespace WaveHarmonic.Crest.Editor
|
||||
"It is not expected that a depth probe object has a Renderer component in its hierarchy." +
|
||||
"The probe is typically attached to an empty GameObject. Please refer to the example content.",
|
||||
"Remove the Renderer component from this object or its children.",
|
||||
MessageType.Warning, renderer
|
||||
MessageType.Warning, renderer,
|
||||
caller: target
|
||||
);
|
||||
|
||||
// Reporting only one renderer at a time will be enough to avoid overwhelming user and UI.
|
||||
@@ -1364,11 +1448,11 @@ namespace WaveHarmonic.Crest.Editor
|
||||
// Validate require water feature.
|
||||
if (water != null)
|
||||
{
|
||||
isValid = isValid && ValidateLod(OptionalLod.Get(typeof(DepthLod)), messenger, water);
|
||||
isValid = isValid && ValidateLod(OptionalLod.Get(typeof(DepthLod)), messenger, water, context: target);
|
||||
|
||||
if (!water._DepthLod._EnableSignedDistanceFields && target._GenerateSignedDistanceField)
|
||||
{
|
||||
isValid = isValid && ValidateSignedDistanceFieldsLod(messenger, water, "Generate Signed Distance Field");
|
||||
isValid = isValid && ValidateSignedDistanceFieldsLod(messenger, water, "Generate Signed Distance Field", target);
|
||||
}
|
||||
|
||||
if (water.DepthLod.IncludeTerrainHeight && Object.FindAnyObjectByType<Terrain>(FindObjectsInactive.Include) != null)
|
||||
@@ -1380,7 +1464,8 @@ namespace WaveHarmonic.Crest.Editor
|
||||
"But typically, if you are using a DepthProbe, it is best to capture the terrain too, as it is more accurate. " +
|
||||
"One reason to use a DepthProbe together with the auto capture is for better real-time/on-demand depth capture performance.",
|
||||
string.Empty,
|
||||
MessageType.Info, water
|
||||
MessageType.Info, water,
|
||||
caller: target
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1397,14 +1482,15 @@ namespace WaveHarmonic.Crest.Editor
|
||||
|
||||
if (!target._DistanceFromEdge.IsEmpty())
|
||||
{
|
||||
isValid = isValid && ValidateLod(OptionalLod.Get(typeof(DepthLod)), messenger, water);
|
||||
isValid = isValid && ValidateSignedDistanceFieldsLod(messenger, water, "Distance From Edge");
|
||||
isValid = isValid && ValidateLod(OptionalLod.Get(typeof(DepthLod)), messenger, water, context: target);
|
||||
isValid = isValid && ValidateSignedDistanceFieldsLod(messenger, water, "Distance From Edge", target);
|
||||
}
|
||||
|
||||
if (!target._DistanceFromSurface.IsEmpty())
|
||||
{
|
||||
isValid &= ValidateCollisionLayer(target._Layer, target, messenger, "layer", target._Layer, required: false);
|
||||
isValid &= ValidateCollisionSource(target, messenger);
|
||||
isValid &= ValidateQuerySource(target, messenger, Water.AnimatedWavesLod, k_NoneQueryProviderCollisionFloatingObjects);
|
||||
isValid &= ValidateQuerySource(target, messenger, Water.FlowLod, k_NoneQueryProviderFlowFloatingObjects);
|
||||
}
|
||||
|
||||
return isValid;
|
||||
@@ -1459,34 +1545,45 @@ namespace WaveHarmonic.Crest.Editor
|
||||
var isValid = true;
|
||||
|
||||
#if !d_CrestCPUQueries
|
||||
if (target.CollisionSource == CollisionSource.CPU)
|
||||
if (target.QuerySource == LodQuerySource.CPU)
|
||||
{
|
||||
messenger
|
||||
(
|
||||
"Collision Source is set to CPU but the <i>CPU Queries</i> package is not installed.",
|
||||
"Install the <i>CPU Queries</i> package or switch to GPU queries.",
|
||||
MessageType.Warning, target.Water,
|
||||
FixSetCollisionSourceToCompute
|
||||
FixSetQuerySourceToCompute
|
||||
);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (target.CollisionSource == CollisionSource.None)
|
||||
{
|
||||
messenger
|
||||
(
|
||||
"Collision Source in Water Renderer is set to None. The floating objects in the scene will use a flat horizontal plane.",
|
||||
"Set collision source to GPU.",
|
||||
MessageType.Warning, target.Water,
|
||||
FixSetCollisionSourceToCompute,
|
||||
$"{nameof(WaterRenderer._AnimatedWavesLod)}.{nameof(AnimatedWavesLod._CollisionSource)}"
|
||||
|
||||
);
|
||||
}
|
||||
isValid &= ValidateQuerySource(target.Water, messenger, target, k_NoneQueryProviderCollisionFloatingObjects);
|
||||
|
||||
return isValid;
|
||||
}
|
||||
|
||||
[Validator(typeof(LevelLod))]
|
||||
static bool Validate(LevelLod target, ShowMessage messenger)
|
||||
{
|
||||
var water = Water;
|
||||
|
||||
if (water == null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
ValidateDisplacementPrecisionIssues(water, water, messenger);
|
||||
ValidateWaterLevelPrecisionIssues(water, water, messenger);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
[Validator(typeof(FlowLod))]
|
||||
static bool Validate(FlowLod target, ShowMessage messenger)
|
||||
{
|
||||
return ValidateQuerySource(target.Water, messenger, target, k_NoneQueryProviderFlowFloatingObjects);
|
||||
}
|
||||
|
||||
[Validator(typeof(ScatteringLod))]
|
||||
static bool Validate(ScatteringLod target, ShowMessage messenger)
|
||||
{
|
||||
@@ -1539,7 +1636,8 @@ namespace WaveHarmonic.Crest.Editor
|
||||
messenger
|
||||
(
|
||||
$"No water present. {nameof(CutsceneTimeProvider)} will have no effect.",
|
||||
"", MessageType.Warning
|
||||
"", MessageType.Warning,
|
||||
caller: target
|
||||
);
|
||||
|
||||
isValid = false;
|
||||
@@ -1552,7 +1650,8 @@ namespace WaveHarmonic.Crest.Editor
|
||||
(
|
||||
$"No {nameof(UnityEngine.Playables.PlayableDirector)} component assigned. {nameof(CutsceneTimeProvider)} will have no effect.",
|
||||
$"Add a {nameof(UnityEngine.Playables.PlayableDirector)}",
|
||||
MessageType.Error
|
||||
MessageType.Error,
|
||||
caller: target
|
||||
);
|
||||
|
||||
isValid = false;
|
||||
@@ -1562,7 +1661,8 @@ namespace WaveHarmonic.Crest.Editor
|
||||
(
|
||||
$"This component requires the com.unity.modules.director built-in module to function.",
|
||||
$"Enable the com.unity.modules.director built-in module.",
|
||||
MessageType.Error
|
||||
MessageType.Error,
|
||||
caller: target
|
||||
);
|
||||
|
||||
isValid = false;
|
||||
@@ -1587,6 +1687,19 @@ namespace WaveHarmonic.Crest.Editor
|
||||
);
|
||||
}
|
||||
|
||||
if (water.RenderBeforeTransparency && !SurfaceRenderer.IsTransparent(material))
|
||||
{
|
||||
messenger
|
||||
(
|
||||
$"The {nameof(WaterRenderer.InjectionPoint).Pretty()} on the {nameof(WaterRenderer).Pretty()} is set to {nameof(WaterInjectionPoint.BeforeTransparent).Pretty()}, but it requires the water surface material to be set to transparent. " +
|
||||
"The water will not render.",
|
||||
$"Set to transparent or set {nameof(WaterRenderer.InjectionPoint).Pretty()} to {nameof(WaterInjectionPoint.Default).Pretty()}.",
|
||||
MessageType.Warning,
|
||||
material,
|
||||
caller: water
|
||||
);
|
||||
}
|
||||
|
||||
return isValid;
|
||||
}
|
||||
|
||||
@@ -1625,7 +1738,8 @@ namespace WaveHarmonic.Crest.Editor
|
||||
(
|
||||
$"{typeof(T).Name} requires a {typeof(C).Name} to be set or present on same object.",
|
||||
$"Set the {typeof(C).Name} property or add a {typeof(C).Name}.",
|
||||
MessageType.Error
|
||||
MessageType.Error,
|
||||
caller: target
|
||||
);
|
||||
|
||||
isValid = false;
|
||||
@@ -1659,9 +1773,10 @@ namespace WaveHarmonic.Crest.Editor
|
||||
(
|
||||
$"The {value} {label} requires the {flag} layer which is not enabled.",
|
||||
fix,
|
||||
required ? MessageType.Error : MessageType.Warning, messenger == DebugLog ? target : Water,
|
||||
required ? MessageType.Error : MessageType.Warning, Water,
|
||||
(_, y) => y.intValue = (int)(layers | flag),
|
||||
$"{nameof(WaterRenderer._AnimatedWavesLod)}.{nameof(WaterRenderer._AnimatedWavesLod._CollisionLayers)}"
|
||||
$"{nameof(WaterRenderer._AnimatedWavesLod)}.{nameof(WaterRenderer._AnimatedWavesLod._CollisionLayers)}",
|
||||
caller: target
|
||||
);
|
||||
|
||||
return !required;
|
||||
@@ -1670,21 +1785,28 @@ namespace WaveHarmonic.Crest.Editor
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool ValidateCollisionSource(Object target, ShowMessage messenger)
|
||||
static bool ValidateQuerySource(Object target, ShowMessage messenger, IQueryableLod<IQueryProvider> lod, string extra)
|
||||
{
|
||||
if (Water == null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Water._AnimatedWavesLod.CollisionSource == CollisionSource.None)
|
||||
if (!lod.Enabled)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (lod.QuerySource == LodQuerySource.None)
|
||||
{
|
||||
messenger
|
||||
(
|
||||
"<i>Collision Source</i> on the <i>Water Renderer</i> is set to <i>None</i>. The floating objects in the scene will use a flat horizontal plane.",
|
||||
"Set the <i>Collision Source</i> to <i>GPU</i> to incorporate waves into physics.",
|
||||
MessageType.Warning, Water,
|
||||
FixSetCollisionSourceToCompute
|
||||
$"<i>{nameof(WaterRenderer)} > {lod.Name} > {nameof(lod.QuerySource)}</i> is set to <i>None</i>. {extra}",
|
||||
$"Set the <i>{nameof(lod.QuerySource)}</i> to <i>{nameof(LodQuerySource.GPU)}</i> to use data.",
|
||||
MessageType.Info, Water,
|
||||
FixSetQuerySourceToCompute,
|
||||
$"_{lod.GetType().Name}._{nameof(lod.QuerySource)}",
|
||||
caller: target
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1727,5 +1849,39 @@ namespace WaveHarmonic.Crest.Editor
|
||||
dependencyPropertyPath
|
||||
);
|
||||
}
|
||||
|
||||
static void ValidateWaterLevelPrecisionIssues(WaterRenderer water, Object caller, ShowMessage messenger)
|
||||
{
|
||||
if (water.LevelLod.Enabled && !water.LevelLod.Blur)
|
||||
{
|
||||
messenger
|
||||
(
|
||||
$"If you are seeing bump artifacts on the water surface, try enabling {nameof(Lod.Blur)} on the {water.LevelLod.Name} simulation.",
|
||||
"Enable blur.",
|
||||
MessageType.Info,
|
||||
water,
|
||||
(x, y) => y.boolValue = true,
|
||||
nameof(water._LevelLod) + "." + Lod.k_BlurField,
|
||||
caller
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
static void ValidateDisplacementPrecisionIssues(WaterRenderer water, Object caller, ShowMessage messenger)
|
||||
{
|
||||
if (water.AnimatedWavesLod.Enabled && water.AnimatedWavesLod.TextureFormatMode != LodTextureFormatMode.Precision)
|
||||
{
|
||||
messenger
|
||||
(
|
||||
$"If you are seeing bump artifacts on the water surface, try setting {nameof(AnimatedWavesLod.TextureFormatMode)} to {LodTextureFormatMode.Precision} in {nameof(AnimatedWavesLod)}.",
|
||||
$"Set {nameof(AnimatedWavesLod.TextureFormatMode)} to {LodTextureFormatMode.Precision}.",
|
||||
MessageType.Info,
|
||||
water,
|
||||
(x, y) => y.intValue = (int)LodTextureFormatMode.Precision,
|
||||
nameof(water._AnimatedWavesLod) + "." + Lod.k_TextureFormatModeField,
|
||||
caller
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user