移除水
This commit is contained in:
@@ -1,143 +0,0 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
using UnityEngine;
|
||||
using WaveHarmonic.Crest.Internal;
|
||||
|
||||
namespace WaveHarmonic.Crest
|
||||
{
|
||||
/// <summary>
|
||||
/// Debug draw crosses in an area around the GameObject on the water surface.
|
||||
/// </summary>
|
||||
[@ExecuteDuringEditMode]
|
||||
[AddComponentMenu(Constants.k_MenuPrefixDebug + "Collision Area Visualizer")]
|
||||
sealed class CollisionAreaVisualizer : ManagedBehaviour<WaterRenderer>
|
||||
{
|
||||
[SerializeField, HideInInspector]
|
||||
#pragma warning disable 414
|
||||
int _Version = 0;
|
||||
#pragma warning restore 414
|
||||
|
||||
[Tooltip(ICollisionProvider.k_LayerTooltip)]
|
||||
[SerializeField]
|
||||
internal CollisionLayer _Layer;
|
||||
|
||||
[SerializeField]
|
||||
float _ObjectWidth = 0f;
|
||||
|
||||
[SerializeField]
|
||||
float _StepSize = 5f;
|
||||
|
||||
[SerializeField]
|
||||
int _Steps = 10;
|
||||
|
||||
[SerializeField]
|
||||
bool _UseDisplacements;
|
||||
|
||||
[SerializeField]
|
||||
bool _UseNormals;
|
||||
|
||||
float[] _ResultHeights;
|
||||
Vector3[] _ResultDisplacements;
|
||||
Vector3[] _ResultNormals;
|
||||
Vector3[] _SamplePositions;
|
||||
|
||||
private protected override System.Action<WaterRenderer> OnUpdateMethod => OnUpdate;
|
||||
void OnUpdate(WaterRenderer water)
|
||||
{
|
||||
if (water.AnimatedWavesLod.Provider == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (_ResultHeights == null || _ResultHeights.Length != _Steps * _Steps)
|
||||
{
|
||||
_ResultHeights = new float[_Steps * _Steps];
|
||||
}
|
||||
if (_ResultDisplacements == null || _ResultDisplacements.Length != _Steps * _Steps)
|
||||
{
|
||||
_ResultDisplacements = new Vector3[_Steps * _Steps];
|
||||
}
|
||||
if (_ResultNormals == null || _ResultNormals.Length != _Steps * _Steps)
|
||||
{
|
||||
_ResultNormals = new Vector3[_Steps * _Steps];
|
||||
|
||||
for (var i = 0; i < _ResultNormals.Length; i++)
|
||||
{
|
||||
_ResultNormals[i] = Vector3.up;
|
||||
}
|
||||
}
|
||||
if (_SamplePositions == null || _SamplePositions.Length != _Steps * _Steps)
|
||||
{
|
||||
_SamplePositions = new Vector3[_Steps * _Steps];
|
||||
}
|
||||
|
||||
var collProvider = water.AnimatedWavesLod.Provider;
|
||||
|
||||
for (var i = 0; i < _Steps; i++)
|
||||
{
|
||||
for (var j = 0; j < _Steps; j++)
|
||||
{
|
||||
_SamplePositions[j * _Steps + i] = new(((i + 0.5f) - _Steps / 2f) * _StepSize, 0f, ((j + 0.5f) - _Steps / 2f) * _StepSize);
|
||||
_SamplePositions[j * _Steps + i].x += transform.position.x;
|
||||
_SamplePositions[j * _Steps + i].z += transform.position.z;
|
||||
}
|
||||
}
|
||||
|
||||
if (_UseDisplacements)
|
||||
{
|
||||
if (collProvider.RetrieveSucceeded(collProvider.Query(GetHashCode(), _ObjectWidth, _SamplePositions, _ResultDisplacements, _UseNormals ? _ResultNormals : null, null, _Layer)))
|
||||
{
|
||||
for (var i = 0; i < _Steps; i++)
|
||||
{
|
||||
for (var j = 0; j < _Steps; j++)
|
||||
{
|
||||
var result = _SamplePositions[j * _Steps + i];
|
||||
result.y = water.SeaLevel;
|
||||
result += _ResultDisplacements[j * _Steps + i];
|
||||
|
||||
var norm = _UseNormals ? _ResultNormals[j * _Steps + i] : Vector3.up;
|
||||
|
||||
DebugDrawCross(result, norm, Mathf.Min(_StepSize / 4f, 1f), Color.green);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (collProvider.RetrieveSucceeded(collProvider.Query(GetHashCode(), _ObjectWidth, _SamplePositions, _ResultHeights, _UseNormals ? _ResultNormals : null, null, _Layer)))
|
||||
{
|
||||
for (var i = 0; i < _Steps; i++)
|
||||
{
|
||||
for (var j = 0; j < _Steps; j++)
|
||||
{
|
||||
var result = _SamplePositions[j * _Steps + i];
|
||||
result.y = _ResultHeights[j * _Steps + i];
|
||||
|
||||
var norm = _UseNormals ? _ResultNormals[j * _Steps + i] : Vector3.up;
|
||||
|
||||
DebugDrawCross(result, norm, Mathf.Min(_StepSize / 4f, 1f), Color.green);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void DebugDrawCross(Vector3 pos, float r, Color col, float duration = 0f)
|
||||
{
|
||||
Debug.DrawLine(pos - Vector3.up * r, pos + Vector3.up * r, col, duration);
|
||||
Debug.DrawLine(pos - Vector3.right * r, pos + Vector3.right * r, col, duration);
|
||||
Debug.DrawLine(pos - Vector3.forward * r, pos + Vector3.forward * r, col, duration);
|
||||
}
|
||||
|
||||
public static void DebugDrawCross(Vector3 pos, Vector3 up, float r, Color col, float duration = 0f)
|
||||
{
|
||||
up.Normalize();
|
||||
var right = Vector3.Normalize(Vector3.Cross(up, Vector3.forward));
|
||||
var forward = Vector3.Cross(up, right);
|
||||
Debug.DrawLine(pos - up * r, pos + up * r, col, duration);
|
||||
Debug.DrawLine(pos - right * r, pos + right * r, col, duration);
|
||||
Debug.DrawLine(pos - forward * r, pos + forward * r, col, duration);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 02e47243a77e64c84b8a2d351386a074
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,82 +0,0 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
// NOTE: DWP2 depends on this file. Any API changes need to be communicated to the DWP2 authors in advance.
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
// Linter does not support mixing inheritdoc plus defining own parameters.
|
||||
#pragma warning disable CS1573 // Parameter has no matching param tag in the XML comment (but other parameters do)
|
||||
|
||||
namespace WaveHarmonic.Crest
|
||||
{
|
||||
/// <summary>
|
||||
/// A layer/event where queries are executed.
|
||||
/// </summary>
|
||||
public enum CollisionLayer
|
||||
{
|
||||
/// <summary>
|
||||
/// Include all displacement.
|
||||
/// </summary>
|
||||
[Tooltip("Include all displacement.")]
|
||||
Everything,
|
||||
|
||||
/// <summary>
|
||||
/// Only include Animated Waves.
|
||||
/// </summary>
|
||||
[Tooltip("Only include Animated Waves.")]
|
||||
AfterAnimatedWaves,
|
||||
|
||||
/// <summary>
|
||||
/// Include Animated Waves and Dynamic Waves.
|
||||
/// </summary>
|
||||
[Tooltip("Include Animated Waves and Dynamic Waves.")]
|
||||
AfterDynamicWaves,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Interface for an object that returns water surface displacement and height.
|
||||
/// </summary>
|
||||
public interface ICollisionProvider : IQueryProvider
|
||||
{
|
||||
internal const string k_LayerTooltip = "Which water collision layer to target.";
|
||||
|
||||
internal static NoneProvider None { get; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Gives a flat, still water.
|
||||
/// </summary>
|
||||
internal sealed class NoneProvider : ICollisionProvider
|
||||
{
|
||||
public int Query(int _0, float _1, Vector3[] _2, Vector3[] result0, Vector3[] result1, Vector3[] result2, CollisionLayer _3 = CollisionLayer.Everything)
|
||||
{
|
||||
if (result0 != null) System.Array.Fill(result0, Vector3.zero);
|
||||
if (result1 != null) System.Array.Fill(result1, Vector3.up);
|
||||
if (result2 != null) System.Array.Fill(result2, Vector3.zero);
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int Query(int _0, float _1, Vector3[] _2, float[] result0, Vector3[] result1, Vector3[] result2, CollisionLayer _3 = CollisionLayer.Everything)
|
||||
{
|
||||
if (result0 != null) System.Array.Fill(result0, WaterRenderer.Instance.SeaLevel);
|
||||
if (result1 != null) System.Array.Fill(result1, Vector3.up);
|
||||
if (result2 != null) System.Array.Fill(result2, Vector3.zero);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Query water physical data at a set of points. Pass in null to any out parameters that are not required.
|
||||
/// </summary>
|
||||
/// <param name="heights">Resulting heights (displacement Y + sea level) at the query positions. Pass null if this information is not required.</param>
|
||||
/// <param name="normals">Resulting normals at the query positions. Pass null if this information is not required.</param>
|
||||
/// <param name="velocities">Resulting velocities at the query positions. Pass null if this information is not required.</param>
|
||||
/// <inheritdoc cref="IQueryProvider.Query(int, float, Vector3[], int)" />
|
||||
int Query(int hash, float minimumLength, Vector3[] points, float[] heights, Vector3[] normals, Vector3[] velocities, CollisionLayer layer = CollisionLayer.Everything);
|
||||
|
||||
/// <param name="displacements">Resulting displacement vectors at the query positions. Add sea level to Y to get world space height.</param>
|
||||
/// <inheritdoc cref="IQueryProvider.Query(int, float, Vector3[], int)" />
|
||||
/// <inheritdoc cref="Query(int, float, Vector3[], float[], Vector3[], Vector3[], CollisionLayer)" />
|
||||
int Query(int hash, float minimumLength, Vector3[] points, Vector3[] displacements, Vector3[] normals, Vector3[] velocities, CollisionLayer layer = CollisionLayer.Everything);
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 55075bf334a1445828a0ad179248fe9c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,148 +0,0 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
namespace WaveHarmonic.Crest
|
||||
{
|
||||
/// <summary>
|
||||
/// Samples water surface shape - displacement, height, normal, velocity.
|
||||
/// </summary>
|
||||
sealed class CollisionQuery : QueryBase, ICollisionProvider
|
||||
{
|
||||
public CollisionQuery(WaterRenderer water) : base(water) { }
|
||||
protected override int Kernel => 0;
|
||||
|
||||
public int Query(int ownerHash, float minSpatialLength, Vector3[] queryPoints, Vector3[] resultDisplacements, Vector3[] resultNormals, Vector3[] resultVelocities, CollisionLayer layer = CollisionLayer.Everything)
|
||||
{
|
||||
var result = (int)QueryStatus.OK;
|
||||
|
||||
if (!UpdateQueryPoints(ownerHash, minSpatialLength, queryPoints, resultNormals != null ? queryPoints : null))
|
||||
{
|
||||
result |= (int)QueryStatus.PostFailed;
|
||||
}
|
||||
|
||||
if (!RetrieveResults(ownerHash, resultDisplacements, null, resultNormals))
|
||||
{
|
||||
result |= (int)QueryStatus.RetrieveFailed;
|
||||
}
|
||||
|
||||
if (resultVelocities != null)
|
||||
{
|
||||
result |= CalculateVelocities(ownerHash, resultVelocities);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public int Query(int ownerHash, float minimumSpatialLength, Vector3[] queryPoints, float[] resultHeights, Vector3[] resultNormals, Vector3[] resultVelocities, CollisionLayer layer = CollisionLayer.Everything)
|
||||
{
|
||||
var result = (int)QueryStatus.OK;
|
||||
|
||||
if (!UpdateQueryPoints(ownerHash, minimumSpatialLength, queryPoints, resultNormals != null ? queryPoints : null))
|
||||
{
|
||||
result |= (int)QueryStatus.PostFailed;
|
||||
}
|
||||
|
||||
if (!RetrieveResults(ownerHash, null, resultHeights, resultNormals))
|
||||
{
|
||||
result |= (int)QueryStatus.RetrieveFailed;
|
||||
}
|
||||
|
||||
if (resultVelocities != null)
|
||||
{
|
||||
result |= CalculateVelocities(ownerHash, resultVelocities);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
sealed class CollisionQueryWithPasses : ICollisionProvider, IQueryable
|
||||
{
|
||||
readonly CollisionQuery _AnimatedWaves;
|
||||
readonly CollisionQuery _DynamicWaves;
|
||||
readonly CollisionQuery _Displacement;
|
||||
readonly WaterRenderer _Water;
|
||||
|
||||
public int ResultGuidCount => _AnimatedWaves.ResultGuidCount + _DynamicWaves.ResultGuidCount + _Displacement.ResultGuidCount;
|
||||
public int RequestCount => _AnimatedWaves.RequestCount + _DynamicWaves.RequestCount + _Displacement.RequestCount;
|
||||
public int QueryCount => _AnimatedWaves.QueryCount + _DynamicWaves.QueryCount + _Displacement.QueryCount;
|
||||
|
||||
public CollisionQueryWithPasses(WaterRenderer water)
|
||||
{
|
||||
_Water = water;
|
||||
_AnimatedWaves = new(water);
|
||||
_DynamicWaves = new(water);
|
||||
_Displacement = new(water);
|
||||
}
|
||||
|
||||
// Gets the provider for the given layer, falling back to previous layer when needed.
|
||||
CollisionQuery GetProvider(CollisionLayer layer)
|
||||
{
|
||||
var layers = _Water.AnimatedWavesLod._CollisionLayers;
|
||||
|
||||
if (layers == CollisionLayers.Nothing)
|
||||
{
|
||||
return _Displacement;
|
||||
}
|
||||
|
||||
if (layer == CollisionLayer.Everything)
|
||||
{
|
||||
if (layers.HasFlag(CollisionLayers.Displacement))
|
||||
{
|
||||
return _Displacement;
|
||||
}
|
||||
}
|
||||
|
||||
if (layer >= CollisionLayer.AfterDynamicWaves)
|
||||
{
|
||||
if (layers.HasFlag(CollisionLayers.DynamicWaves) && _Water.DynamicWavesLod.Enabled)
|
||||
{
|
||||
return _DynamicWaves;
|
||||
}
|
||||
}
|
||||
|
||||
return _AnimatedWaves;
|
||||
}
|
||||
|
||||
public int Query(int hash, float minimumLength, Vector3[] points, float[] heights, Vector3[] normals, Vector3[] velocities, CollisionLayer layer = CollisionLayer.Everything)
|
||||
{
|
||||
return GetProvider(layer).Query(hash, minimumLength, points, heights, normals, velocities);
|
||||
}
|
||||
|
||||
public int Query(int hash, float minimumLength, Vector3[] points, Vector3[] displacements, Vector3[] normals, Vector3[] velocities, CollisionLayer layer = CollisionLayer.Everything)
|
||||
{
|
||||
return GetProvider(layer).Query(hash, minimumLength, points, displacements, normals, velocities);
|
||||
}
|
||||
|
||||
public void UpdateQueries(WaterRenderer water, CollisionLayer layer)
|
||||
{
|
||||
switch (layer)
|
||||
{
|
||||
case CollisionLayer.Everything: _Displacement.UpdateQueries(water); break;
|
||||
case CollisionLayer.AfterAnimatedWaves: _AnimatedWaves.UpdateQueries(water); break;
|
||||
case CollisionLayer.AfterDynamicWaves: _DynamicWaves.UpdateQueries(water); break;
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateQueries(WaterRenderer water)
|
||||
{
|
||||
_Displacement.UpdateQueries(water);
|
||||
}
|
||||
|
||||
public void CleanUp()
|
||||
{
|
||||
_AnimatedWaves.CleanUp();
|
||||
_DynamicWaves.CleanUp();
|
||||
_Displacement.CleanUp();
|
||||
}
|
||||
}
|
||||
|
||||
static partial class Extensions
|
||||
{
|
||||
public static void UpdateQueries(this ICollisionProvider self, WaterRenderer water, CollisionLayer layer) => (self as CollisionQueryWithPasses)?.UpdateQueries(water, layer);
|
||||
public static void UpdateQueries(this ICollisionProvider self, WaterRenderer water) => (self as IQueryable)?.UpdateQueries(water);
|
||||
public static void CleanUp(this ICollisionProvider self) => (self as IQueryable)?.CleanUp();
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3cddd187674954ce1a0e2e19017a744a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,98 +0,0 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
namespace WaveHarmonic.Crest
|
||||
{
|
||||
/// <summary>
|
||||
/// Helper to trace a ray against the water surface.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Works by sampling at a set of points along the ray and interpolating the
|
||||
/// intersection location.
|
||||
/// </remarks>
|
||||
public sealed class RayCastHelper : Internal.SampleHelper
|
||||
{
|
||||
readonly float _RayStepSize;
|
||||
readonly float _MinimumLength;
|
||||
|
||||
/// <summary>
|
||||
/// The length of the ray and the step size must be given here. The smaller the step size, the greater the accuracy.
|
||||
/// </summary>
|
||||
/// <param name="rayLength">Length of the ray.</param>
|
||||
/// <param name="rayStepSize">Size of the step. With length the number of steps is computed.</param>
|
||||
public RayCastHelper(float rayLength, float rayStepSize = 2f) : base(ComputeQueryCount(rayLength, ref rayStepSize))
|
||||
{
|
||||
_RayStepSize = rayStepSize;
|
||||
// Waves go max double along min length. Thats too much - only allow half of a wave per step.
|
||||
_MinimumLength = _RayStepSize * 4f;
|
||||
}
|
||||
|
||||
static int ComputeQueryCount(float rayLength, ref float rayStepSize)
|
||||
{
|
||||
Debug.Assert(rayLength > 0f);
|
||||
Debug.Assert(rayStepSize > 0f);
|
||||
|
||||
var stepCount = Mathf.CeilToInt(rayLength / rayStepSize) + 1;
|
||||
|
||||
var maxStepCount = 128;
|
||||
if (stepCount > maxStepCount)
|
||||
{
|
||||
stepCount = maxStepCount;
|
||||
rayStepSize = rayLength / (stepCount - 1f);
|
||||
Debug.LogWarning($"Crest: RayTraceHelper: ray steps exceed maximum ({maxStepCount}), step size increased to {rayStepSize} to reduce step count.");
|
||||
}
|
||||
|
||||
return stepCount;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Call this once each frame to do the query.
|
||||
/// </summary>
|
||||
/// <param name="origin">World space position of ray origin</param>
|
||||
/// <param name="direction">World space ray direction</param>
|
||||
/// <param name="distance">The distance along the ray to the first intersection with the water surface.</param>
|
||||
/// <param name="layer">The layer this ray targets.</param>
|
||||
/// <returns>True if the results have come back from the GPU, and if the ray intersects the water surface.</returns>
|
||||
public bool RayCast(Vector3 origin, Vector3 direction, out float distance, CollisionLayer layer = CollisionLayer.Everything)
|
||||
{
|
||||
distance = -1f;
|
||||
|
||||
Validate(allowMultipleCallsPerFrame: false);
|
||||
|
||||
var water = WaterRenderer.Instance;
|
||||
var provider = water == null ? null : water.AnimatedWavesLod.Provider;
|
||||
if (provider == null) return false;
|
||||
|
||||
for (var i = 0; i < _QueryPosition.Length; i++)
|
||||
{
|
||||
_QueryPosition[i] = origin + i * _RayStepSize * direction;
|
||||
}
|
||||
|
||||
var status = provider.Query(GetHashCode(), _MinimumLength, _QueryPosition, _QueryResult, null, null, layer);
|
||||
|
||||
if (!provider.RetrieveSucceeded(status))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Now that data is available, compare the height of the water to the height of each point of the ray. If
|
||||
// the ray crosses the surface, the distance to the intersection is interpolated from the heights.
|
||||
for (var i = 1; i < _QueryPosition.Length; i++)
|
||||
{
|
||||
var height0 = _QueryResult[i - 1].y + water.SeaLevel - _QueryPosition[i - 1].y;
|
||||
var height1 = _QueryResult[i].y + water.SeaLevel - _QueryPosition[i].y;
|
||||
|
||||
if (Mathf.Sign(height0) != Mathf.Sign(height1))
|
||||
{
|
||||
var prop = Mathf.Abs(height0) / (Mathf.Abs(height0) + Mathf.Abs(height1));
|
||||
distance = (i - 1 + prop) * _RayStepSize;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return distance >= 0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f1f458d6962ed46be8f00bdff45b2725
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,44 +0,0 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
using UnityEngine;
|
||||
using WaveHarmonic.Crest.Internal;
|
||||
|
||||
namespace WaveHarmonic.Crest
|
||||
{
|
||||
/// <summary>
|
||||
/// Debug draw a line trace from this gameobjects position, in this gameobjects forward direction.
|
||||
/// </summary>
|
||||
[@ExecuteDuringEditMode]
|
||||
[AddComponentMenu(Constants.k_MenuPrefixDebug + "Ray Cast Visualizer")]
|
||||
sealed class RayTraceVisualizer : ManagedBehaviour<WaterRenderer>
|
||||
{
|
||||
[SerializeField, HideInInspector]
|
||||
#pragma warning disable 414
|
||||
int _Version = 0;
|
||||
#pragma warning restore 414
|
||||
|
||||
readonly RayCastHelper _RayCast = new(50f, 2f);
|
||||
|
||||
private protected override System.Action<WaterRenderer> OnUpdateMethod => OnUpdate;
|
||||
void OnUpdate(WaterRenderer water)
|
||||
{
|
||||
if (water.AnimatedWavesLod.Provider == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Even if only a single ray trace is desired, this still must be called every frame until it returns true
|
||||
if (_RayCast.RayCast(transform.position, transform.forward, out var dist))
|
||||
{
|
||||
var endPos = transform.position + transform.forward * dist;
|
||||
Debug.DrawLine(transform.position, endPos, Color.green);
|
||||
CollisionAreaVisualizer.DebugDrawCross(endPos, 2f, Color.green, 0f);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.DrawLine(transform.position, transform.position + transform.forward * 50f, Color.red);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 159faa53a32b34aff9d79e974c14d100
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user