using System;
using UnityEngine;
using Object = UnityEngine.Object;

namespace RebootKit.Engine.Extensions {
    public static class TransformEx {
        public static void DestroyChildren(this Transform transform) {
            foreach (Transform child in transform) {
                if (child.OrNull() != null) {
                    Object.Destroy(child.gameObject);
                }
            }
        }

        public static void ForEachChild(this Transform transform, Action<Transform> action) {
            foreach (Transform child in transform) action(child);
        }
    }
}