using System;
using UnityEngine;
namespace DTT.Utils.Extensions
{
///
/// Provides extension methods for transform instances.
///
public static class TransformExtensions
{
///
/// Returns the first child transform. Will return null if the transform has no children.
///
/// The transform to get the first child of.
/// The first child.
public static Transform FirstChild(this Transform transform)
{
if (transform == null)
throw new ArgumentNullException(nameof(transform));
if (transform.childCount == 0)
return null;
return transform.GetChild(0);
}
///
/// Returns the last child transform. Will return null if the transform has no children.
///
/// The transform to get the last child of.
/// The last child.
public static Transform LastChild(this Transform transform)
{
if (transform == null)
throw new ArgumentNullException(nameof(transform));
if (transform.childCount == 0)
return null;
return transform.GetChild(transform.childCount - 1);
}
}
}