public static void AddComponentRecursive <T>(this GameObject gameObject, ComponentTestDelegate testDelegate) where T : Component { gameObject.AddComponent <T>(testDelegate); foreach (Transform child in gameObject.transform) { child.gameObject.AddComponentRecursive <T>(testDelegate); } }
public static T AddComponent <T>(this GameObject gameObject, ComponentTestDelegate testDelegate) where T : Component { if (testDelegate(gameObject)) { return(gameObject.AddComponent <T>()); } return(null); }