62 lines
1.9 KiB
C#
62 lines
1.9 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using Shapes;
|
|
|
|
namespace AibisDream
|
|
{
|
|
[ExecuteAlways]public class LakeWaveGrid : ImmediateModeShapeDrawer
|
|
{
|
|
public int gridSize = 32;
|
|
public float spacing = 0.2f;
|
|
public float waveHeight = 0.2f;
|
|
public float waveSpeed = 2f;
|
|
public float lineThickness = 0.01f;
|
|
public float pointRadius = 0.02f;
|
|
|
|
public override void DrawShapes(Camera cam)
|
|
{
|
|
Draw.LineGeometry = LineGeometry.Volumetric3D;
|
|
Draw.ThicknessSpace = ThicknessSpace.Meters;
|
|
Draw.Color = Color.cyan;
|
|
|
|
float time = Time.time;
|
|
|
|
Vector3[,] points = new Vector3[gridSize, gridSize];
|
|
|
|
for (int x = 0; x < gridSize; x++)
|
|
{
|
|
for (int y = 0; y < gridSize; y++)
|
|
{
|
|
float fx = (x - gridSize / 2f) * spacing;
|
|
float fy = (y - gridSize / 2f) * spacing;
|
|
|
|
float wave = Mathf.Sin(fx * 2f + time * waveSpeed) * 0.5f +
|
|
Mathf.Cos(fy * 3f + time * waveSpeed * 1.3f) * 0.5f;
|
|
float height = wave * waveHeight;
|
|
|
|
points[x, y] = new Vector3(fx, fy + height, 0);
|
|
Draw.Disc(points[x, y], Vector3.forward, pointRadius);
|
|
}
|
|
}
|
|
|
|
for (int x = 0; x < gridSize - 1; x++)
|
|
{
|
|
for (int y = 0; y < gridSize; y++)
|
|
{
|
|
Draw.Line(points[x, y], points[x + 1, y], lineThickness);
|
|
}
|
|
}
|
|
|
|
for (int x = 0; x < gridSize; x++)
|
|
{
|
|
for (int y = 0; y < gridSize - 1; y++)
|
|
{
|
|
Draw.Line(points[x, y], points[x, y + 1], lineThickness);
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|