ToolTipsEditor.cs 984 B

1234567891011121314151617181920212223242526
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEditor;
  5. public class ToolTipsEditor : Editor
  6. {
  7. [MenuItem("GameObject/Chiva/ToolTips/给子级添加TooltipsElement", priority = 0)]
  8. public static void AddToolTipsForChild()
  9. {
  10. Transform obj = Selection.activeGameObject.transform;
  11. for (int i = 0; i < obj.childCount; i++)
  12. {
  13. Transform tempChild = obj.GetChild(i);
  14. ToolTipsElement tempElement = tempChild.GetComponent<ToolTipsElement>() == null
  15. ? tempChild.gameObject.AddComponent<ToolTipsElement>()
  16. : tempChild.GetComponent<ToolTipsElement>();
  17. tempElement.toolName = tempChild.gameObject.name;
  18. }
  19. foreach (var item in obj.GetComponentsInChildren<MeshRenderer>())
  20. {
  21. if (item.transform.GetComponent<MeshCollider>() == null)
  22. item.gameObject.AddComponent<MeshCollider>();
  23. }
  24. }
  25. }