while (collidersObjects.Count != 0)
{
GameObject parent = collidersObjects.Dequeue();
AddGameObjectCollider(parent);
for (int j = 0; j < parent.transform.childCount; j++)
{
collidersObjects.Enqueue(parent.transform.GetChild(j).gameObject);
}
}
}
}为了验证所有功能,我们在Assets/Scripts/Editor文件下创建一个BatchGenerateBoxColliders.cs的脚本,把所有的脚本放进去:
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
public class BatchGenerateBoxColliders : Editor
{
[MenuItem(&#34;添加碰撞体/创建&#34;)]
static void AddSingleBoxCollider()
{
for (int i = 0; i < Selection.gameObjects.Length; i++)
{
AddGameObjectCollider(Selection.gameObjects);
}
}
[MenuItem(&#34;添加碰撞体/递归创建&#34;)]
static void AddMultipleBoxCollider()
{
for (int i = 0; i < Selection.gameObjects.Length; i++)
{
Queue<GameObject> collidersObjects = new Queue<GameObject>();