还原水插件

This commit is contained in:
2026-03-05 00:14:42 +08:00
parent 0de35591e7
commit e82f2ea6b7
270 changed files with 2773 additions and 12445 deletions

View File

@@ -1,7 +1,6 @@
// Crest Water System
// Copyright © 2024 Wave Harmonic. All rights reserved.
using System.Collections.Generic;
using UnityEngine;
// Linter does not support mixing inheritdoc plus defining own parameters.
@@ -21,7 +20,7 @@ namespace WaveHarmonic.Crest.Internal
private protected readonly Vector3[] _QueryPosition;
private protected readonly Vector3[] _QueryResult;
readonly Dictionary<int, int> _LastFrame = new();
int _LastFrame = -1;
private protected SampleHelper(int queryCount = 1)
{
@@ -30,29 +29,15 @@ namespace WaveHarmonic.Crest.Internal
}
[System.Diagnostics.Conditional("UNITY_EDITOR")]
private protected void Validate(bool allowMultipleCallsPerFrame, int id)
private protected void Validate(bool allowMultipleCallsPerFrame)
{
if (!_LastFrame.ContainsKey(id))
{
_LastFrame.Add(id, -1);
}
#if UNITY_EDITOR
// Prevent false positives spamming the console.
if (!UnityEditor.EditorApplication.isFocused || (Application.isPlaying && UnityEditor.EditorApplication.isPaused))
{
_LastFrame[id] = Time.frameCount;
return;
}
#endif
if (!Time.inFixedTimeStep && !allowMultipleCallsPerFrame && _LastFrame[id] == Time.frameCount)
if (Application.isPlaying && !Time.inFixedTimeStep && !allowMultipleCallsPerFrame && _LastFrame == Time.frameCount)
{
var type = GetType().Name;
Debug.LogWarning($"Crest: {type} sample called multiple times in one frame which is not expected. Each {type} object services a single sample per frame. To perform multiple queries, create multiple {type} objects or use the query provider API directly.");
}
_LastFrame[id] = Time.frameCount;
_LastFrame = Time.frameCount;
}
// The first method is there just to get inheritdoc to work as it does not like
@@ -118,7 +103,7 @@ namespace WaveHarmonic.Crest
var isVelocity = (options & QueryOptions.Velocity) == QueryOptions.Velocity;
var isNormal = (options & QueryOptions.Normal) == QueryOptions.Normal;
Validate(allowMultipleCallsPerFrame, id);
Validate(allowMultipleCallsPerFrame);
_QueryPosition[0] = position;
@@ -130,8 +115,7 @@ namespace WaveHarmonic.Crest
_QueryResult,
isNormal ? _QueryResultNormal : null,
isVelocity ? _QueryResultVelocity : null,
layer,
position
layer
);
if (!provider.RetrieveSucceeded(status))
@@ -250,13 +234,11 @@ namespace WaveHarmonic.Crest
return false;
}
var id = GetHashCode();
Validate(false, id);
Validate(false);
_QueryPosition[0] = position;
var status = flowProvider.Query(id, minimumLength, _QueryPosition, _QueryResult, position);
var status = flowProvider.Query(GetHashCode(), minimumLength, _QueryPosition, _QueryResult);
if (!flowProvider.RetrieveSucceeded(status))
{
@@ -277,25 +259,25 @@ namespace WaveHarmonic.Crest
/// </summary>
public sealed class SampleDepthHelper : Internal.SampleHelper
{
internal bool Sample(int id, Vector3 position, out Vector2 result, bool allowMultipleCallsPerFrame = false)
bool Sample(Vector3 position, out Vector2 result)
{
var water = WaterRenderer.Instance;
var depthProvider = water == null ? null : water.DepthLod.Provider;
if (depthProvider == null)
{
result = new(Mathf.Infinity, Mathf.Infinity);
result = Vector2.zero;
return false;
}
Validate(allowMultipleCallsPerFrame, id);
Validate(false);
_QueryPosition[0] = position;
var status = depthProvider.Query(id, minimumLength: 0, _QueryPosition, _QueryResult, position);
var status = depthProvider.Query(GetHashCode(), minimumLength: 0, _QueryPosition, _QueryResult);
if (!depthProvider.RetrieveSucceeded(status))
{
result = new(Mathf.Infinity, Mathf.Infinity);
result = Vector2.zero;
return false;
}
@@ -303,18 +285,13 @@ namespace WaveHarmonic.Crest
return true;
}
bool Sample(Vector3 position, out Vector2 result)
{
return Sample(GetHashCode(), position, out result);
}
/// <summary>
/// Sample both the water depth and water edge distance.
/// </summary>
/// <param name="depth">Filled by the water depth at the query position.</param>
/// <param name="distance">Filled by the distance to water edge at the query position.</param>
/// <inheritdoc cref="Internal.SampleHelper.Sample" />
internal bool Sample(Vector3 position, out float depth, out float distance)
bool Sample(Vector3 position, out float depth, out float distance)
{
var success = Sample(position, out var result);
depth = result.x;
@@ -335,12 +312,7 @@ namespace WaveHarmonic.Crest
/// <inheritdoc cref="Sample(Vector3, out float, out float)"/>
public bool SampleDistanceToWaterEdge(Vector3 position, out float distance)
{
return SampleDistanceToWaterEdge(GetHashCode(), position, out distance);
}
internal bool SampleDistanceToWaterEdge(int id, Vector3 position, out float distance)
{
var success = Sample(id, position, out var result);
var success = Sample(position, out var result);
distance = result.y;
return success;
}