using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
/// <summary>
/// 挂载物体到关节joint下
/// </summary>
public class AddObjToAttach : MonoBehaviour
{
public GameObject addObj;
public List<GameObject> addList = new List<GameObject>();
public void Add()
{
foreach( var item in addList)
{
DestroyImmediate(item);
}
addList.Clear();
foreach (Transform item in transform)
{
foreach(Transform child in item.GetComponentsInChildren<Transform>())
{
if(child==item)
{
continue;
}
GameObject temp= Instantiate(addObj, child);
addList.Add(temp);
}
}
Debug.Log("00002");
}
}
[CustomEditor(typeof(AddObjToAttach))]
public class AddObjToAttachEditor:Editor
{
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
//生成一个按钮 在Inspector
if (GUILayout.Button("挂载物体到所有的关节下面"))
{
Debug.Log("00001");
//调用 AddObjToAttach 的add方法
(target as AddObjToAttach).Add();
}
}
}
|