Created
December 24, 2014 12:20
-
-
Save david-hodgetts/25e26a4699c6afc8a45a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
public static class Extensions | |
{ | |
/// <summary> | |
/// extension method on Array of T | |
/// returns true if array only contains null items | |
/// </summary> | |
/// <typeparam name="T"></typeparam> | |
/// <param name="array"></param> | |
/// <returns></returns> | |
public static bool ContainsOnlyNullItems<T>(this T[] array){ | |
foreach (var item in array){ | |
if (item != null) return false; | |
} | |
return true; | |
} | |
/// <summary> | |
/// extension method on Array of T | |
/// returns true if any item in Array is non null | |
/// </summary> | |
/// <typeparam name="T"></typeparam> | |
/// <param name="array"></param> | |
/// <returns></returns> | |
public static bool AnyNonNull<T>(this T[] array) { | |
return !array.ContainsOnlyNullItems(); | |
} | |
public static T GetInterface<T>(this GameObject inObj) where T : class | |
{ | |
if (!typeof(T).IsInterface) | |
{ | |
Debug.LogError(typeof(T).ToString() + ": is not an interface!"); | |
return null; | |
} | |
return inObj.GetComponents(typeof(MonoBehaviour)).OfType<T>().FirstOrDefault(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment