108 lines
4.0 KiB
C#
108 lines
4.0 KiB
C#
// Crest Water System
|
|
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
|
|
|
using UnityEditor;
|
|
using UnityEngine;
|
|
using WaveHarmonic.Crest.Internal;
|
|
|
|
namespace WaveHarmonic.Crest.ShallowWater.Editor
|
|
{
|
|
static class Visualizers
|
|
{
|
|
#if CREST_DEBUG
|
|
internal static Material s_VisualizeMaterial;
|
|
#endif
|
|
|
|
[DrawGizmo(GizmoType.Selected | GizmoType.NonSelected)]
|
|
static void DrawGizmos(ShallowWaterSimulation target, GizmoType type)
|
|
{
|
|
var rect = target.Rect;
|
|
if (rect != Rect.zero && type.HasFlag(GizmoType.Selected))
|
|
{
|
|
var height = target.Origin.y;
|
|
Gizmos.color = Color.magenta;
|
|
|
|
Gizmos.DrawWireCube
|
|
(
|
|
new(rect.center.x, height, rect.center.y),
|
|
new(rect.size.x, 0, rect.size.y)
|
|
);
|
|
|
|
if (target.InjectShape == ShallowWaterSimulationInjection.Level)
|
|
{
|
|
Gizmos.DrawCube
|
|
(
|
|
new(rect.center.x - rect.size.x * 0.5f + target.PaddingWidth * 0.5f, height, rect.center.y),
|
|
new(target.PaddingWidth, 0, rect.size.y)
|
|
);
|
|
|
|
Gizmos.DrawCube
|
|
(
|
|
new(rect.center.x + rect.size.x * 0.5f - target.PaddingWidth * 0.5f, height, rect.center.y),
|
|
new(target.PaddingWidth, 0, rect.size.y)
|
|
);
|
|
|
|
Gizmos.DrawCube
|
|
(
|
|
new(rect.center.x, height, rect.center.y + rect.size.y * 0.5f - target.PaddingWidth * 0.5f),
|
|
new(rect.size.x - target.PaddingWidth * 2f, 0, target.PaddingWidth)
|
|
);
|
|
|
|
Gizmos.DrawCube
|
|
(
|
|
new(rect.center.x, height, rect.center.y - rect.size.y * 0.5f + target.PaddingWidth * 0.5f),
|
|
new(rect.size.x - target.PaddingWidth * 2f, 0, target.PaddingWidth)
|
|
);
|
|
|
|
Gizmos.DrawWireCube
|
|
(
|
|
new(rect.center.x, height, rect.center.y),
|
|
new(rect.size.x - target.PaddingWidth * 2f, 0, rect.size.y - target.PaddingWidth * 2f)
|
|
);
|
|
}
|
|
}
|
|
|
|
#if CREST_DEBUG
|
|
if (target._Debug._ShowSimulationDataInScene != ShallowWaterSimulation.DebugFields.SimulationData.None)
|
|
{
|
|
var water = WaterRenderer.Instance;
|
|
|
|
if (water == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (s_VisualizeMaterial == null)
|
|
{
|
|
s_VisualizeMaterial = new(Shader.Find("Hidden/Crest/Debug/Visualize Texture"));
|
|
}
|
|
|
|
s_VisualizeMaterial.mainTexture = target._Debug._ShowSimulationDataInScene switch
|
|
{
|
|
ShallowWaterSimulation.DebugFields.SimulationData.Height => target._Height0,
|
|
ShallowWaterSimulation.DebugFields.SimulationData.Ground => target._GroundHeight,
|
|
ShallowWaterSimulation.DebugFields.SimulationData.VelocityX => target._VelocityX,
|
|
ShallowWaterSimulation.DebugFields.SimulationData.VelocityY => target._VelocityY,
|
|
ShallowWaterSimulation.DebugFields.SimulationData.Mask => target._Mask,
|
|
ShallowWaterSimulation.DebugFields.SimulationData.WaterLevel => target._WaterLevel,
|
|
_ => throw new System.NotImplementedException(),
|
|
};
|
|
|
|
if (s_VisualizeMaterial.mainTexture == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
s_VisualizeMaterial.SetPass(0);
|
|
|
|
Graphics.DrawMeshNow
|
|
(
|
|
Helpers.QuadMesh,
|
|
Matrix4x4.TRS(target.Origin.XNZ(water.SeaLevel) + Vector3.up, Quaternion.Euler(90f, 0, 0), Vector3.one * target._Width)
|
|
);
|
|
}
|
|
#endif
|
|
}
|
|
}
|
|
}
|