GetAllSubGameObject.cs 648 B

12345678910111213141516171819202122232425
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public static class GetAllSubGameObject
  5. {
  6. public static List<GameObject> GetAllChildren(this GameObject gm)
  7. {
  8. List<GameObject> objects = new List<GameObject>();
  9. for (int i = 0; i < gm.transform.childCount; i++)
  10. {
  11. objects.Add(gm.transform.GetChild(i).gameObject);
  12. }
  13. return objects;
  14. }
  15. public static bool InitByIdentifier(this Transform tm, out GameObject identifier)
  16. {
  17. identifier = tm.Find(nameof(identifier))?.gameObject;
  18. if (!identifier) return false;
  19. else return true;
  20. }
  21. }