TransformExtension.cs 525 B

12345678910111213141516171819202122232425
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace JTSystems
  5. {
  6. public static class TransformExtension
  7. {
  8. public static void Clear(this Transform parent)
  9. {
  10. while (parent.childCount > 0)
  11. {
  12. Transform t = parent.GetChild(0);
  13. t.SetParent(null);
  14. #if UNITY_EDITOR
  15. Object.DestroyImmediate(t.gameObject);
  16. #else
  17. Object.Destroy(t.gameObject);
  18. #endif
  19. }
  20. }
  21. }
  22. }