Unity-DebugX/Samples/Scripts/DebugXSample_LinesList.cs

50 lines
1.3 KiB
C#
Raw Normal View History

2025-03-05 15:29:50 +08:00
using UnityEngine;
namespace DCFApixels.DebugXCore.Samples
{
[SelectionBase]
public class DebugXSample_LinesList : MonoBehaviour
{
public Color Color;
2025-03-05 15:42:27 +08:00
public Vector3[] Points = new Vector3[32];
public float Frequency = 1;
2025-03-05 15:29:50 +08:00
public bool IsStrip;
#if UNITY_EDITOR
private void OnDrawGizmos()
{
Draw();
}
#else
private void Update()
{
Draw();
}
#endif
private void Draw()
{
2025-03-05 15:42:27 +08:00
if (Points == null) { return; }
float sizeX = transform.localScale.x;
float sizeY = transform.localScale.y * 0.5f;
float start = transform.position.x - sizeX * 0.5f;
float step = sizeX / Points.Length;
2025-03-05 15:29:50 +08:00
for (int i = 0; i < Points.Length; i++)
{
2025-03-05 15:42:27 +08:00
float x = step * i;
float y = Mathf.Sin(x * Frequency) * sizeY;
Points[i] = new Vector3(start + x, transform.position.y + y, transform.position.z);
2025-03-05 15:29:50 +08:00
}
if (IsStrip)
{
2025-03-05 15:42:27 +08:00
DebugX.Draw(Color).LineStrip(Points, 0, Points.Length);
2025-03-05 15:29:50 +08:00
}
else
{
2025-03-05 15:42:27 +08:00
DebugX.Draw(Color).Lines(Points, 0, Points.Length);
2025-03-05 15:29:50 +08:00
}
}
}
}