LayerProcGen v0.5.0
Layer-based infinite procedural generation
Loading...
Searching...
No Matches
DebugDrawer

A utility for drawing lines for debug visualizations. More...

Inherits MonoBehaviour, and IOriginHandler.

Public Member Functions

void HandleOriginShift (Point3 oldOrigin, Point3 newOrigin)
 An origin handler can either be authoritative or delta-based.
 

Static Public Member Functions

static void DrawArrow (DPoint3 start, Vector3 dir, Color color, float arrowHeadLength=0.25f, float arrowHeadAngle=20, float duration=0, bool depthTest=false)
 
static void DrawArrow (Vector3 start, Vector3 dir, Color color, float arrowHeadLength=0.25f, float arrowHeadAngle=20, float duration=0, bool depthTest=false)
 
static void DrawCircle (DPoint pos, float radius, int segments, Color color, float duration=0, bool depthTest=false)
 
static void DrawCircle (DPoint3 pos, float radius, int segments, Color color, float duration=0, bool depthTest=false)
 
static void DrawCircle (DPoint3 pos, float radius, Quaternion rotation, int segments, Color color, float duration=0, bool depthTest=false)
 
static void DrawCircle (Vector2 pos, float radius, int segments, Color color, float duration=0, bool depthTest=false)
 
static void DrawCircle (Vector3 pos, float radius, int segments, Color color, float duration=0, bool depthTest=false)
 
static void DrawCircle (Vector3 pos, float radius, Quaternion rotation, int segments, Color color, float duration=0, bool depthTest=false)
 
static void DrawCross (DPoint pos, float size, Color color, float duration=0, bool depthTest=false)
 
static void DrawCross (DPoint3 pos, float size, Color color, float duration=0, bool depthTest=false)
 
static void DrawCross (Vector2 pos, float size, Color color, float duration=0, bool depthTest=false)
 
static void DrawCross (Vector3 pos, float size, Color color, float duration=0, bool depthTest=false)
 
static void DrawCube (DPoint3 pos, Vector3 scale, Color color, Vector3? rot=null, float duration=0, bool depthTest=false)
 
static void DrawCube (Matrix4x4 matrix, Color color, float duration=0, bool depthTest=false)
 
static void DrawCube (Vector3 pos, Vector3 scale, Color color, Vector3? rot=null, float duration=0, bool depthTest=false)
 
static void DrawLine (DPoint3 start, DPoint3 end)
 
static void DrawLine (DPoint3 worldStart, DPoint3 worldEnd, Color color, float duration=0, bool depthTest=false)
 
static void DrawLine (Vector3 start, Vector3 end)
 
static void DrawLine (Vector3 start, Vector3 end, Color color, float duration=0, bool depthTest=false)
 
static void DrawLineArrow (DPoint3 start, DPoint3 end, Color color, float arrowHeadLength=0.25f, float arrowHeadAngle=20, float duration=0, bool depthTest=false)
 
static void DrawLineArrow (Vector3 start, Vector3 end, Color color, float arrowHeadLength=0.25f, float arrowHeadAngle=20, float duration=0, bool depthTest=false)
 
static void DrawRay (DPoint3 start, DPoint3 dir)
 
static void DrawRay (DPoint3 start, DPoint3 dir, Color color, float duration=0, bool depthTest=false)
 
static void DrawRay (Vector3 start, Vector3 dir)
 
static void DrawRay (Vector3 start, Vector3 dir, Color color, float duration=0, bool depthTest=false)
 
static void DrawRect (DFloat xMin, DFloat yMin, DFloat xMax, DFloat yMax, Color color)
 
static void DrawRect (DPoint min, DPoint max, DFloat depth, Color color, float duration=0, bool depthTest=false)
 
static void DrawRect (float xMin, float yMin, float xMax, float yMax, Color color)
 
static void DrawRect (Vector2 min, Vector2 max, float depth, Color color, float duration=0, bool depthTest=false)
 
static void DrawSquare (DPoint3 pos, Vector3 scale, Color color, Vector3? rot=null, float duration=0, bool depthTest=false)
 
static void DrawSquare (Matrix4x4 matrix, Color color, float duration=0, bool depthTest=false)
 
static void DrawSquare (Vector3 pos, Vector3 scale, Color color, Vector3? rot=null, float duration=0, bool depthTest=false)
 

Public Attributes

LayerMask debugLayers = ~0
 
bool display = true
 
Shader shaderZOff
 
Shader shaderZOn
 

Static Public Attributes

static float alpha = 1f
 
static Matrix4x4 matrix = Matrix4x4.identity
 
static bool xzMode = false
 

Detailed Description

A utility for drawing lines for debug visualizations.

Functions that take Vector3 parameters draw in 3D space. Functions that take Vector2 parameters draw in either the XY or XZ plane depending on whether the xzMode property is set to true.

Member Function Documentation

◆ HandleOriginShift()

void HandleOriginShift ( Point3 oldOrigin,
Point3 newOrigin )

An origin handler can either be authoritative or delta-based.

An authoritative handler knows an object's world position in fixed point coordinates and calculates a new scene position based on that, disregarding the old origin parameter.

DPoint3 worldPosition;
public void HandleOriginShift(Point3 oldOrigin, Point3 newOrigin) {
Vector3 scenePosition = (Vector3)(worldPosition - newOrigin);
transform.position = scenePosition;
}
void HandleOriginShift(Point3 oldOrigin, Point3 newOrigin)
An origin handler can either be authoritative or delta-based.
Definition DebugDrawer.cs:145
Definition DPoint3.cs:14
Definition Point3.cs:15

A delta-based handler only knows an object's current scene position and subtracts a delta from it which is the new origin minus the old one.

public void HandleOriginShift(Point3 oldOrigin, Point3 newOrigin) {
if (newOrigin == oldOrigin)
return;
Vector3 delta = (Vector3)(newOrigin - oldOrigin);
transform.position = transform.position - delta;
}

The two approaches produce almost identical results, but the delta-based approach can lead to subtle drifting. This is typically not a problem for dynamically moving objects like the player or NPCs.

Parameters
oldOriginThe old scene origin in world space.
newOriginThe new scene origin in world space.

Implements IOriginHandler.