1
0
mirror of https://github.com/oliverbooth/X10D synced 2024-11-13 00:45:42 +00:00
X10D/X10D.Unity/src/ComponentExtensions.cs
Oliver Booth e6025b1a4c
fix: validate null arguments in X10D.Unity
The CA runs are really testing me today.
2023-04-11 17:09:14 +01:00

28 lines
1.0 KiB
C#

using UnityEngine;
namespace X10D.Unity;
/// <summary>
/// Extension methods for <see cref="Component" />.
/// </summary>
public static class ComponentExtensions
{
/// <summary>
/// Returns an array of components of the specified type, excluding components that live on the object to which this
/// component is attached.
/// </summary>
/// <param name="component">The component whose child components to retrieve.</param>
/// <typeparam name="T">The type of the components to retrieve.</typeparam>
/// <returns>An array <typeparamref name="T" /> representing the child components.</returns>
/// <exception cref="ArgumentNullException"><paramref name="component" /> is <see langword="null" />.</exception>
public static T[] GetComponentsInChildrenOnly<T>(this Component component)
{
if (component == null)
{
throw new ArgumentNullException(nameof(component));
}
return component.gameObject.GetComponentsInChildrenOnly<T>();
}
}