GGJ2022/Assets/Scripts/gizmoManager.cs

35 lines
927 B
C#
Raw Normal View History

2022-01-29 21:04:46 +00:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class gizmoManager : MonoBehaviour
{
void OnDrawGizmos()
{
if (this.gameObject != null && this.gameObject.transform.parent != null && !this.gameObject.transform.parent.name.Contains("chunk"))
2022-01-29 23:24:14 +00:00
{
Bounds bounds = GetChildRendererBounds(gameObject);
Gizmos.DrawWireCube(bounds.center, bounds.size);
}
2022-01-29 21:04:46 +00:00
}
Bounds GetChildRendererBounds(GameObject go)
{
Renderer[] renderers = go.GetComponentsInChildren<Renderer>();
if (renderers.Length > 0)
{
Bounds bounds = renderers[0].bounds;
2022-01-30 00:41:59 +00:00
for (int i = 0, ni = renderers.Length; i < ni; i++)
2022-01-29 21:04:46 +00:00
{
bounds.Encapsulate(renderers[i].bounds);
}
return bounds;
}
else
{
return new Bounds();
}
}
}