包围盒
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using ZYF;
public class BoundsGet : MonoBehaviour
{
private void OnDrawGizmos()
{
var bounds = GetMaxBounds(gameObject);
Gizmos.color = Color.red;
Gizmos.DrawWireCube(center: bounds.center,size:bounds.size);
}
private Bounds GetMaxBounds(GameObject g)
{
Renderer[] rs = g.GetComponentsInChildren<Renderer>();
if (rs.Length > 0)
{
Bounds b = rs[0].bounds;
for (int i = 1; i < rs.Length; i++)
{
b.Encapsulate(rs[i].bounds);
}
return b;
}
else
{
return new Bounds();
}
}
}