欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

unity 子物体包围盒

程序员文章站 2024-03-16 18:24:28
...
 public static Vector3 GetCenter(Transform tans)
    {
        maxBound = new Bounds();
        if (tans.childCount > 0)
        {
            if (tans.GetChild(0).childCount > 0)
            {
                if (tans.GetChild(0).GetChild(0).GetComponent<Renderer>() != null)
                {
                    maxBound = tans.GetChild(0).GetChild(0).GetComponent<Renderer>().bounds;
                    for (int i = 1; i < tans.childCount; i++)
                    {
                        Transform child = tans.GetChild(i);
                        if (child.childCount > 0)
                        {
                            Renderer render = child.GetChild(0).GetComponent<Renderer>();
                            maxBound.Encapsulate(render.bounds);
                        }
                    }
                }

            }

        }

        return maxBound.center;
    }

 

相关标签: unity