Hey,
i am somehow having problems to see a Gizmos.DrawLine in my editor (for debugging) is there a way to let the line appear thicker?, so at the moment its just this:
Gizmos.color = new Color (0,1F,0,1F);
if (lastCompletedVectorPath != null) {
for (int i=0;i<lastCompletedVectorPath.Count-1;i++) {
Gizmos.DrawLine (lastCompletedVectorPath*,lastCompletedVectorPath[i+1]);*
Unfortunately Unity doesn’t allow to change the line width. So lines drawn are always one pixel lines.
You can either:
Draw multiple lines in parallel slightly offset.
Draw actual quads instead of lines. However this has to be done with the GL class manually.
For simple debugging it’s easier to draw multiple lines. You can create a helper method like this:
public static void DrawLine(Vector3 p1, Vector3 p2, float width)
{
int count = Mathf.CeilToInt(width); // how many lines are needed.
if(count ==1)
Gizmos.DrawLine(p1,p2);
else
{
Camera c = Camera.current;
if (c == null)
{
Debug.LogError("Camera.current is null")
return;
}
Vector3 v1 = (p2 - p1).normalized; // line direction
Vector3 v2 = (c.position - p1).normalized; // direction to camera
Vector3 n = Vector3.Cross(v1,v2); // normal vector
for(int i = 0; i < count; i++)
{
Vector3 o = n* width ((float)i/(count-1) - 0.5f);
Gizmos.DrawLine(p1+o,p2+o);
}
}
}
I haven’t tested this method as i don’t have a Unity installation at hand, but it should work.
Here is an easy way to draw thick lines in the scene view and on standard cameras in the game view. (Note that I think the ‘thickness’ is expressed in pixels).
public static void DrawThickLine(Vector3 start, Vector3 end, float thickness)
{
Camera c = Camera.current;
if (c == null) return;
// Only draw on normal cameras
if (c.clearFlags == CameraClearFlags.Depth || c.clearFlags == CameraClearFlags.Nothing)
{
return;
}
// Only draw the line when it is the closest thing to the camera
// (Remove the Z-test code and other objects will not occlude the line.)
var prevZTest = Handles.zTest;
Handles.zTest = UnityEngine.Rendering.CompareFunction.LessEqual;
Handles.color = Gizmos.color;
Handles.DrawAAPolyLine(thickness * 10, new Vector3[] { start, end });
Handles.zTest = prevZTest;
}