Last active
January 3, 2016 05:17
-
-
Save yKimisaki/3fd0ab0c12cdb56be21a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.Generic; | |
using UnityEngine; | |
namespace Unity.Extensions | |
{ | |
public static class GameObjectExtensions | |
{ | |
public static IEnumerable<TComponent> SelectComponents<TComponent>(this IEnumerable<GameObject> source) where TComponent : Component | |
{ | |
foreach (var go in source) | |
{ | |
var component = go.GetComponent<TComponent>(); | |
if (component == null) | |
continue; | |
yield return component; | |
} | |
} | |
public static TComponent FirstOrDefaultComponent<TComponent>(this IEnumerable<GameObject> source) where TComponent : Component | |
{ | |
foreach (var go in source) | |
{ | |
var component = go.GetComponent<TComponent>(); | |
if (component == null) | |
continue; | |
return component; | |
} | |
return default(TComponent); | |
} | |
} | |
} |
Author
yKimisaki
commented
Jan 3, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment