Skip to content

Commit 9db79ce

Browse files
committed
Add generic collider gizmo function (fixes #42 )
1 parent c6e2208 commit 9db79ce

1 file changed

Lines changed: 50 additions & 2 deletions

File tree

Runtime/ExtraGizmos.cs

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,33 @@ public static void DrawCombinedCubeBetween(Vector3 a, Vector3 b, float fillAlpha
196196
var size = (b - a).Abs();
197197
DrawCombinedCube(center, size, fillAlpha);
198198
}
199+
200+
/// <summary>
201+
/// Draws a combined wireframe and solid mesh gizmo.
202+
/// </summary>
203+
public static void DrawCombinedMesh(Mesh mesh, Vector3 position, Quaternion rotation, Vector3 scale, float fillAlpha)
204+
{
205+
Gizmos.DrawWireMesh(mesh, position, rotation, scale);
206+
using(new GizmoColorScope(Gizmos.color.MultiplyAlpha(fillAlpha)))
207+
{
208+
Gizmos.DrawMesh(mesh, position, rotation, scale);
209+
}
210+
}
211+
212+
/// <summary>
213+
/// Draws a combined wireframe and solid mesh gizmo.
214+
/// </summary>
215+
public static void DrawCombinedMesh(Mesh mesh, Matrix4x4 matrix, float fillAlpha)
216+
{
217+
var lMatrix = Gizmos.matrix;
218+
Gizmos.matrix *= matrix;
219+
Gizmos.DrawWireMesh(mesh);
220+
using(new GizmoColorScope(Gizmos.color.MultiplyAlpha(fillAlpha)))
221+
{
222+
Gizmos.DrawMesh(mesh);
223+
}
224+
Gizmos.matrix = lMatrix;
225+
}
199226

200227
#endregion
201228

@@ -1038,12 +1065,33 @@ public static void DrawTerrainProjectedRectangle(Vector3 from, Vector3 to, float
10381065
#endregion
10391066

10401067
#region Colliders
1068+
1069+
/// <summary>
1070+
/// Draws a combined gizmo representing the given collider.
1071+
/// </summary>
1072+
public static void DrawCollider(Collider collider, float fillAlpha)
1073+
{
1074+
if(collider is BoxCollider boxCollider)
1075+
{
1076+
DrawBoxCollider(boxCollider, fillAlpha);
1077+
}
1078+
else if(collider is SphereCollider sphereCollider)
1079+
{
1080+
DrawSphereCollider(sphereCollider, fillAlpha);
1081+
}
1082+
else if(collider is CapsuleCollider capsuleCollider)
1083+
{
1084+
DrawCapsuleCollider(capsuleCollider, fillAlpha);
1085+
}
1086+
else if(collider is MeshCollider meshCollider)
1087+
{
1088+
DrawMeshCollider(meshCollider, fillAlpha);
1089+
}
1090+
}
10411091

10421092
/// <summary>
10431093
/// Draws a combined gizmo representing the given BoxCollider.
10441094
/// </summary>
1045-
/// <param name="boxCollider"></param>
1046-
/// <param name="fillAlpha"></param>
10471095
public static void DrawBoxCollider(BoxCollider boxCollider, float fillAlpha)
10481096
{
10491097
if(!boxCollider) return;

0 commit comments

Comments
 (0)