GGJ2022/Assets/Scripts/gizmoManager.cs

42 lines
911 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
{
// Start is called before the first frame update
void Start()
{
}
void OnDrawGizmos()
{
Bounds bounds = GetChildRendererBounds(gameObject);
Gizmos.DrawWireCube(bounds.center, bounds.size);
}
Bounds GetChildRendererBounds(GameObject go)
{
Renderer[] renderers = go.GetComponentsInChildren<Renderer>();
if (renderers.Length > 0)
{
Bounds bounds = renderers[0].bounds;
for (int i = 1, ni = renderers.Length; i < ni; i++)
{
bounds.Encapsulate(renderers[i].bounds);
}
return bounds;
}
else
{
return new Bounds();
}
}
// Update is called once per frame
void Update()
{
}
}