using UnityEngine; public static class CustomExtensions{ public static void PurgeChildren(this Transform parent){ foreach(Transform child in parent.GetComponentsInChildren()){ if(child == parent){continue;} SmartDestroy(child.gameObject); } } public static void PurgeChildrenEdit(this Transform parent){ for (int i = parent.transform.childCount; i > 0; --i) GameObject.DestroyImmediate(parent.GetChild(0).gameObject); } public static void SmartDestroy(UnityEngine.Object obj) { if (obj == null) { return; } #if UNITY_EDITOR if (!Application.isPlaying) { GameObject.DestroyImmediate(obj); } else #endif { GameObject.Destroy(obj); } } }