I've create a simple C# script capable of drawing lines, I will expand it with other usefull functions.
However I've two issues, the SetColor isn't coloring the geometry and nothing is showing in the editor's viewport while I can see it working in the game.
Any thought about this ?
using Godot;
using System;
using System.Collections.Generic;
[Tool] // Not working in editor
public class DebugUtils : ImmediateGeometry
{
public static DebugUtils instance;
List<Vector3> points = new List<Vector3>();
public override void _Ready()
{
if(instance == null)
{
instance = this;
}
else
{
GD.PrintErr("Duplication of singleton !");
}
}
private void AddLine(Vector3 a, Vector3 b)
{
points.Add(a);
points.Add(b);
}
public static void Line(Vector3 a, Vector3 b)
{
instance.AddLine(a, b);
}
public override void _Process(float delta)
{
Clear();
Begin(Mesh.PrimitiveType.Lines);
SetColor(new Color(1, 0, 0, 1)); //Not working...
if (points.Count >= 2)
{
for (int i = 0; i < points.Count - 1; i+=2)
{
AddVertex(points[i]);
AddVertex(points[i + 1]);
}
}
End();
points.Clear();
}
}