Gizmos.DrawWireCube如何控制线的粗细
时间: 2024-02-02 14:04:41 浏览: 137
在Unity中,Gizmos.DrawWireCube()函数是用于在Scene视图中绘制一个边框框,它的线条粗细是不可控制的。无论如何,你可以通过以下方法来绘制一个自定义线条粗细的边框框:
```csharp
void OnDrawGizmos()
{
Gizmos.matrix = transform.localToWorldMatrix;
Gizmos.color = Color.red;
float thickness = 0.1f; // 线条粗细
Vector3 center = Vector3.zero; // 边框框中心点
Vector3 size = new Vector3(1, 1, 1); // 边框框尺寸
Vector3 halfSize = size * 0.5f;
// 绘制边框框的线条
Gizmos.DrawLine(center + new Vector3(-halfSize.x, -halfSize.y, -halfSize.z), center + new Vector3(halfSize.x, -halfSize.y, -halfSize.z));
Gizmos.DrawLine(center + new Vector3(halfSize.x, -halfSize.y, -halfSize.z), center + new Vector3(halfSize.x, -halfSize.y, halfSize.z));
Gizmos.DrawLine(center + new Vector3(halfSize.x, -halfSize.y, halfSize.z), center + new Vector3(-halfSize.x, -halfSize.y, halfSize.z));
Gizmos.DrawLine(center + new Vector3(-halfSize.x, -halfSize.y, halfSize.z), center + new Vector3(-halfSize.x, -halfSize.y, -halfSize.z));
Gizmos.DrawLine(center + new Vector3(-halfSize.x, halfSize.y, -halfSize.z), center + new Vector3(halfSize.x, halfSize.y, -halfSize.z));
Gizmos.DrawLine(center + new Vector3(halfSize.x, halfSize.y, -halfSize.z), center + new Vector3(halfSize.x, halfSize.y, halfSize.z));
Gizmos.DrawLine(center + new Vector3(halfSize.x, halfSize.y, halfSize.z), center + new Vector3(-halfSize.x, halfSize.y, halfSize.z));
Gizmos.DrawLine(center + new Vector3(-halfSize.x, halfSize.y, halfSize.z), center + new Vector3(-halfSize.x, halfSize.y, -halfSize.z));
Gizmos.DrawLine(center + new Vector3(-halfSize.x, -halfSize.y, -halfSize.z), center + new Vector3(-halfSize.x, halfSize.y, -halfSize.z));
Gizmos.DrawLine(center + new Vector3(halfSize.x, -halfSize.y, -halfSize.z), center + new Vector3(halfSize.x, halfSize.y, -halfSize.z));
Gizmos.DrawLine(center + new Vector3(halfSize.x, -halfSize.y, halfSize.z), center + new Vector3(halfSize.x, halfSize.y, halfSize.z));
Gizmos.DrawLine(center + new Vector3(-halfSize.x, -halfSize.y, halfSize.z), center + new Vector3(-halfSize.x, halfSize.y, halfSize.z));
}
```
这个例子展示了如何手动绘制一个边框框,并控制线条的粗细。你可以调整 thickness 变量来改变线条的粗细。
阅读全文