|
|
|
|
|
|
|
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
#if UNITY_EDITOR
|
|
|
|
// TODO: Look into a better volume previsualization system
|
|
|
|
List<Collider> m_TempColliders; |
|
|
|
|
|
|
|
void OnDrawGizmos() |
|
|
|
{ |
|
|
|
if (m_TempColliders == null) |
|
|
|
m_TempColliders = new List<Collider>(); |
|
|
|
|
|
|
|
var colliders = m_TempColliders; |
|
|
|
GetComponents(colliders); |
|
|
|
|
|
|
|
if (isGlobal || colliders == null) |
|
|
|
return; |
|
|
|
|
|
|
|
var scale = transform.localScale; |
|
|
|
var invScale = new Vector3(1f / scale.x, 1f / scale.y, 1f / scale.z); |
|
|
|
Gizmos.matrix = Matrix4x4.TRS(transform.position, transform.rotation, scale); |
|
|
|
Gizmos.color = new Color(0f, 1f, 0.1f, 0.6f); |
|
|
|
|
|
|
|
// Draw a separate gizmo for each collider
|
|
|
|
foreach (var collider in colliders) |
|
|
|
{ |
|
|
|
if (!collider.enabled) |
|
|
|
continue; |
|
|
|
|
|
|
|
// We'll just use scaling as an approximation for volume skin. It's far from being
|
|
|
|
// correct (and is completely wrong in some cases). Ultimately we'd use a distance
|
|
|
|
// field or at least a tesselate + push modifier on the collider's mesh to get a
|
|
|
|
// better approximation, but the current Gizmo system is a bit limited and because
|
|
|
|
// everything is dynamic in Unity and can be changed at anytime, it's hard to keep
|
|
|
|
// track of changes in an elegant way (which we'd need to implement a nice cache
|
|
|
|
// system for generated volume meshes).
|
|
|
|
var type = collider.GetType(); |
|
|
|
|
|
|
|
if (type == typeof(BoxCollider)) |
|
|
|
{ |
|
|
|
var c = (BoxCollider)collider; |
|
|
|
Gizmos.DrawCube(c.center, c.size); |
|
|
|
Gizmos.DrawWireCube(c.center, c.size + invScale * blendDistance * 2f); |
|
|
|
} |
|
|
|
else if (type == typeof(SphereCollider)) |
|
|
|
{ |
|
|
|
var c = (SphereCollider)collider; |
|
|
|
Gizmos.DrawSphere(c.center, c.radius); |
|
|
|
Gizmos.DrawWireSphere(c.center, c.radius + invScale.x * blendDistance); |
|
|
|
} |
|
|
|
else if (type == typeof(MeshCollider)) |
|
|
|
{ |
|
|
|
var c = (MeshCollider)collider; |
|
|
|
|
|
|
|
// Only convex mesh colliders are allowed
|
|
|
|
if (!c.convex) |
|
|
|
c.convex = true; |
|
|
|
|
|
|
|
// Mesh pivot should be centered or this won't work
|
|
|
|
Gizmos.DrawMesh(c.sharedMesh); |
|
|
|
Gizmos.DrawWireMesh(c.sharedMesh, Vector3.zero, Quaternion.identity, Vector3.one + invScale * blendDistance * 2f); |
|
|
|
} |
|
|
|
|
|
|
|
// Nothing for capsule (DrawCapsule isn't exposed in Gizmo), terrain, wheel and
|
|
|
|
// other colliders...
|
|
|
|
} |
|
|
|
|
|
|
|
colliders.Clear(); |
|
|
|
} |
|
|
|
#endif
|
|
|
|
} |
|
|
|
} |