diff --git a/crest/Assets/Crest/Crest-Examples/Shared/Scripts/UnderwaterEnvironmentalLighting.cs b/crest/Assets/Crest/Crest-Examples/Shared/Scripts/UnderwaterEnvironmentalLighting.cs
index 67bdff489..789483688 100644
--- a/crest/Assets/Crest/Crest-Examples/Shared/Scripts/UnderwaterEnvironmentalLighting.cs
+++ b/crest/Assets/Crest/Crest-Examples/Shared/Scripts/UnderwaterEnvironmentalLighting.cs
@@ -15,9 +15,12 @@ namespace Crest
/// (directional light, reflections, ambient etc) with the underwater depth. This works with vanilla lighting, but
/// uncommon or custom lighting will require a custom solution (use this for reference).
///
+ [DefaultExecutionOrder(k_DefaultExecutionOrder)]
[AddComponentMenu(Internal.Constants.MENU_PREFIX_EXAMPLE + "Underwater Environmental Lighting")]
public class UnderwaterEnvironmentalLighting : MonoBehaviour
{
+ public const int k_DefaultExecutionOrder = OceanRenderer.k_DefaultExecutionOrder + 1;
+
///
/// The version of this asset. Can be used to migrate across versions. This value should
/// only be changed when the editor upgrades the version.
diff --git a/crest/Assets/Crest/Crest-Examples/Shared/Scripts/UnderwaterEnvironmentalLighting.cs.meta b/crest/Assets/Crest/Crest-Examples/Shared/Scripts/UnderwaterEnvironmentalLighting.cs.meta
index 078be726a..affd3380c 100644
--- a/crest/Assets/Crest/Crest-Examples/Shared/Scripts/UnderwaterEnvironmentalLighting.cs.meta
+++ b/crest/Assets/Crest/Crest-Examples/Shared/Scripts/UnderwaterEnvironmentalLighting.cs.meta
@@ -4,7 +4,7 @@ MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
- executionOrder: 201
+ executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
diff --git a/crest/Assets/Crest/Crest/Scripts/BuildCommandBuffer.cs.meta b/crest/Assets/Crest/Crest/Scripts/BuildCommandBuffer.cs.meta
index 812e4fcc3..227c37679 100644
--- a/crest/Assets/Crest/Crest/Scripts/BuildCommandBuffer.cs.meta
+++ b/crest/Assets/Crest/Crest/Scripts/BuildCommandBuffer.cs.meta
@@ -4,7 +4,7 @@ MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
- executionOrder: 100
+ executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
diff --git a/crest/Assets/Crest/Crest/Scripts/Helpers/FloatingOrigin.cs b/crest/Assets/Crest/Crest/Scripts/Helpers/FloatingOrigin.cs
index 5615492ed..369dd2b96 100644
--- a/crest/Assets/Crest/Crest/Scripts/Helpers/FloatingOrigin.cs
+++ b/crest/Assets/Crest/Crest/Scripts/Helpers/FloatingOrigin.cs
@@ -37,9 +37,12 @@ public interface IFloatingOrigin
/// script should normally be attached to the viewpoint, typically the main camera.
///
[AddComponentMenu(Internal.Constants.MENU_PREFIX_SCRIPTS + "Floating Origin")]
+ [DefaultExecutionOrder(k_DefaultExecutionOrder)]
[HelpURL(Internal.Constants.HELP_URL_BASE_USER + "other-features.html" + Internal.Constants.HELP_URL_RP + "#floating-origin")]
public class FloatingOrigin : MonoBehaviour
{
+ public const int k_DefaultExecutionOrder = -200;
+
///
/// The version of this asset. Can be used to migrate across versions. This value should
/// only be changed when the editor upgrades the version.
diff --git a/crest/Assets/Crest/Crest/Scripts/Helpers/FloatingOrigin.cs.meta b/crest/Assets/Crest/Crest/Scripts/Helpers/FloatingOrigin.cs.meta
index 357dafa0e..a37f940e5 100644
--- a/crest/Assets/Crest/Crest/Scripts/Helpers/FloatingOrigin.cs.meta
+++ b/crest/Assets/Crest/Crest/Scripts/Helpers/FloatingOrigin.cs.meta
@@ -4,7 +4,7 @@ MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
- executionOrder: -200
+ executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
diff --git a/crest/Assets/Crest/Crest/Scripts/LodData/OceanDepthCache.cs b/crest/Assets/Crest/Crest/Scripts/LodData/OceanDepthCache.cs
index bc5744314..ef9a7b557 100644
--- a/crest/Assets/Crest/Crest/Scripts/LodData/OceanDepthCache.cs
+++ b/crest/Assets/Crest/Crest/Scripts/LodData/OceanDepthCache.cs
@@ -16,10 +16,13 @@ namespace Crest
/// This should be used for static geometry, dynamic objects should be tagged with the Render Ocean Depth component.
///
[ExecuteAlways]
+ [DefaultExecutionOrder(k_DefaultExecutionOrder)]
[HelpURL(Internal.Constants.HELP_URL_BASE_USER + "shallows-and-shorelines.html" + Internal.Constants.HELP_URL_RP)]
[AddComponentMenu(Internal.Constants.MENU_PREFIX_SCRIPTS + "Ocean Depth Cache")]
public partial class OceanDepthCache : MonoBehaviour
{
+ public const int k_DefaultExecutionOrder = OceanRenderer.k_DefaultExecutionOrder + 1;
+
///
/// The version of this asset. Can be used to migrate across versions. This value should
/// only be changed when the editor upgrades the version.
@@ -90,12 +93,6 @@ public enum OceanDepthCacheRefreshMode
void Start()
{
- if (OceanRenderer.Instance == null)
- {
- enabled = false;
- return;
- }
-
#if UNITY_EDITOR
if (EditorApplication.isPlaying && _runValidationOnStart)
{
@@ -643,6 +640,17 @@ public bool Validate(OceanRenderer ocean, ValidatedHelper.ShowMessage showMessag
isValid = false;
}
+ if (ocean == null)
+ {
+ showMessage
+ (
+ "The Ocean Depth Cache uses the Ocean Renderer height which is not present. " +
+ "The transform height will be used instead.",
+ "", // Leave fix message blank as this could be a valid option.
+ ValidatedHelper.MessageType.Info, this
+ );
+ }
+
if (ocean != null && ocean.Root != null && !Mathf.Approximately(transform.position.y, ocean.Root.position.y))
{
showMessage
diff --git a/crest/Assets/Crest/Crest/Scripts/OceanRenderer.cs b/crest/Assets/Crest/Crest/Scripts/OceanRenderer.cs
index a42dc797e..a8557655e 100644
--- a/crest/Assets/Crest/Crest/Scripts/OceanRenderer.cs
+++ b/crest/Assets/Crest/Crest/Scripts/OceanRenderer.cs
@@ -23,10 +23,14 @@ namespace Crest
/// and moves/scales the ocean based on the viewpoint. It also hosts a number of global settings that can be tweaked here.
///
[ExecuteAlways, SelectionBase]
+ [DefaultExecutionOrder(k_DefaultExecutionOrder)]
[AddComponentMenu(Internal.Constants.MENU_PREFIX_SCRIPTS + "Ocean Renderer")]
[HelpURL(Constants.HELP_URL_GENERAL)]
public partial class OceanRenderer : MonoBehaviour
{
+ // Update ocean after Cinemachine.
+ public const int k_DefaultExecutionOrder = 200;
+
///
/// The version of this asset. Can be used to migrate across versions. This value should
/// only be changed when the editor upgrades the version.
diff --git a/crest/Assets/Crest/Crest/Scripts/OceanRenderer.cs.meta b/crest/Assets/Crest/Crest/Scripts/OceanRenderer.cs.meta
index 5b631f74e..f1c688bc3 100644
--- a/crest/Assets/Crest/Crest/Scripts/OceanRenderer.cs.meta
+++ b/crest/Assets/Crest/Crest/Scripts/OceanRenderer.cs.meta
@@ -13,7 +13,7 @@ MonoImporter:
- _simSettingsFlow: {instanceID: 0}
- _primaryLight: {instanceID: 0}
- _simSettingsShadow: {instanceID: 0}
- executionOrder: 200
+ executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
diff --git a/crest/Assets/Crest/Crest/Scripts/Reflection/OceanPlanarReflection.cs b/crest/Assets/Crest/Crest/Scripts/Reflection/OceanPlanarReflection.cs
index 009d919bf..ef10cf640 100644
--- a/crest/Assets/Crest/Crest/Scripts/Reflection/OceanPlanarReflection.cs
+++ b/crest/Assets/Crest/Crest/Scripts/Reflection/OceanPlanarReflection.cs
@@ -77,9 +77,13 @@ static void InitStatics()
///
/// Attach to a camera to generate a reflection texture which can be sampled in the ocean shader.
///
+ [RequireComponent(typeof(Camera))]
+ [DefaultExecutionOrder(k_DefaultExecutionOrder)]
[AddComponentMenu(Internal.Constants.MENU_PREFIX_SCRIPTS + "Ocean Planar Reflections")]
- public class OceanPlanarReflection : MonoBehaviour
+ public partial class OceanPlanarReflection : MonoBehaviour
{
+ public const int k_DefaultExecutionOrder = OceanRenderer.k_DefaultExecutionOrder + 1;
+
///
/// The version of this asset. Can be used to migrate across versions. This value should
/// only be changed when the editor upgrades the version.
@@ -125,33 +129,21 @@ public class OceanPlanarReflection : MonoBehaviour
const int CULL_DISTANCE_COUNT = 32;
float[] _cullDistances = new float[CULL_DISTANCE_COUNT];
- private void Start()
+ void OnEnable()
{
- if (OceanRenderer.Instance == null)
+ if (_camViewpoint == null)
{
- enabled = false;
- return;
+ _camViewpoint = GetComponent();
}
- _camViewpoint = GetComponent();
- if (!_camViewpoint)
+ if (_camViewpointSkybox == null)
{
- Debug.LogWarning("Crest: Disabling planar reflections as no camera found on gameobject to generate reflection from.", this);
- enabled = false;
- return;
+ _camViewpointSkybox = _camViewpoint.GetComponent();
}
- _camViewpointSkybox = _camViewpoint?.GetComponent();
// This is anyway called in OnPreRender, but was required here as there was a black reflection
// for a frame without this earlier setup call.
CreateWaterObjects(_camViewpoint);
-
-#if UNITY_EDITOR
- if (!OceanRenderer.Instance.OceanMaterial.IsKeywordEnabled("_PLANARREFLECTIONS_ON"))
- {
- Debug.LogWarning("Crest: Planar reflections are not enabled on the current ocean material and will not be visible.", this);
- }
-#endif
}
bool RequestRefresh(long frame)
@@ -401,4 +393,27 @@ private void OnDisable()
}
}
}
+
+#if UNITY_EDITOR
+ public partial class OceanPlanarReflection : IValidated
+ {
+ public bool Validate(OceanRenderer ocean, ValidatedHelper.ShowMessage showMessage)
+ {
+ var isValid = true;
+
+ if (ocean != null && !ocean.OceanMaterial.IsKeywordEnabled("_PLANARREFLECTIONS_ON"))
+ {
+ showMessage
+ (
+ "Crest: Planar reflections are not enabled on the current ocean material and will not be visible.",
+ "Enable planar reflections.",
+ ValidatedHelper.MessageType.Warning,
+ this
+ );
+ }
+
+ return isValid;
+ }
+ }
+#endif
}
diff --git a/crest/Assets/Crest/Crest/Scripts/Underwater/UnderwaterRenderer.cs b/crest/Assets/Crest/Crest/Scripts/Underwater/UnderwaterRenderer.cs
index 38eed4b08..60077ac7b 100644
--- a/crest/Assets/Crest/Crest/Scripts/Underwater/UnderwaterRenderer.cs
+++ b/crest/Assets/Crest/Crest/Scripts/Underwater/UnderwaterRenderer.cs
@@ -16,10 +16,13 @@ namespace Crest
/// For convenience, all shader material settings are copied from the main ocean shader.
///
[RequireComponent(typeof(Camera))]
+ [DefaultExecutionOrder(k_DefaultExecutionOrder)]
[AddComponentMenu(Internal.Constants.MENU_PREFIX_SCRIPTS + "Underwater Renderer")]
[HelpURL(Internal.Constants.HELP_URL_BASE_USER + "underwater.html" + Internal.Constants.HELP_URL_RP)]
public partial class UnderwaterRenderer : MonoBehaviour
{
+ public const int k_DefaultExecutionOrder = OceanRenderer.k_DefaultExecutionOrder + 1;
+
///
/// The version of this asset. Can be used to migrate across versions. This value should
/// only be changed when the editor upgrades the version.
diff --git a/crest/Assets/Crest/Crest/Scripts/Underwater/UnderwaterRenderer.cs.meta b/crest/Assets/Crest/Crest/Scripts/Underwater/UnderwaterRenderer.cs.meta
index 80d33d7f3..8783d1641 100644
--- a/crest/Assets/Crest/Crest/Scripts/Underwater/UnderwaterRenderer.cs.meta
+++ b/crest/Assets/Crest/Crest/Scripts/Underwater/UnderwaterRenderer.cs.meta
@@ -8,7 +8,7 @@ MonoImporter:
type: 2}
- _oceanMaskMaterial: {fileID: 2100000, guid: 2ddd9bab6a9ad7542a419bcaeff337a8,
type: 2}
- executionOrder: 202
+ executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName: