using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEditor; public class ToolTipsEditor : Editor { [MenuItem("GameObject/Chiva/ToolTips/给子级添加TooltipsElement", priority = 0)] public static void AddToolTipsForChild() { Transform obj = Selection.activeGameObject.transform; for (int i = 0; i < obj.childCount; i++) { Transform tempChild = obj.GetChild(i); ToolTipsElement tempElement = tempChild.GetComponent() == null ? tempChild.gameObject.AddComponent() : tempChild.GetComponent(); tempElement.toolName = tempChild.gameObject.name; } foreach (var item in obj.GetComponentsInChildren()) { if (item.transform.GetComponent() == null) item.gameObject.AddComponent(); } } }