Files
2025-05-08 16:17:49 +08:00

59 lines
1.7 KiB
C#

using UnityEngine;
using System.Collections.Generic;
using Shapes;
public class GridGenerator
{
private float fieldSize;
private int pointCount;
private float pointSize;
private float lineWidth;
private float edgeLineLength;
public GridGenerator(float fieldSize, int pointCount, float pointSize, float lineWidth, float edgeLineLength)
{
this.fieldSize = fieldSize;
this.pointCount = pointCount;
this.pointSize = pointSize;
this.lineWidth = lineWidth;
this.edgeLineLength = edgeLineLength;
}
public List<Vector3> GenerateGridPoints()
{
List<Vector3> points = new List<Vector3>();
float step = fieldSize / (pointCount - 1);
float halfSize = fieldSize / 2f;
for (int i = 0; i < pointCount; i++)
{
for (int j = 0; j < pointCount; j++)
{
float x = j * step - halfSize;
float z = i * step - halfSize;
points.Add(new Vector3(x, 0f, z));
}
}
return points;
}
public void DrawGridPoint(Vector3 position, float size, Color color)
{
Draw.Sphere(position, size, color);
}
public void DrawGridLine(Vector3 start, Vector3 end, float width, Color color)
{
Draw.Line(start, end, width, color);
}
public void DrawEdgeLine(Vector3 start, Vector3 end, float width, Color color)
{
Vector3 direction = (end - start).normalized;
Vector3 normal = Vector3.Cross(direction, Vector3.up).normalized;
Vector3 offset = normal * edgeLineLength;
Draw.Line(start + offset, end + offset, width, color);
}
}