You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
CrowdControl/Assets/3rd/D2D_Scripts/Utilities/CodeSugar/TransformSugar.cs

31 lines
872 B
C#

3 months ago
using System.Collections.Generic;
using UnityEngine;
namespace D2D.Utilities
{
public static class TransformSugar
{
public static List<Transform> GetChildTransforms(this Transform target)
{
var childList = new List<Transform>();
foreach (Transform child in target)
{
childList.Add(child);
}
return childList;
}
public static Transform GetLastChild(this Transform target)
{
return target.childCount == 0 ? null : target.GetChild(target.childCount - 1);
}
public static void ClearChildren(this Transform target)
{
var all = target.GetChildTransforms();
for (var i = 0; i < all.Count; i++)
GameObject.DestroyImmediate(all[i].gameObject);
}
}
}