diff --git a/src/CoreLibrary/Assets/Scripts/CoreLibrary/Base/ComponentQueryExtensions.cs b/src/CoreLibrary/Assets/Scripts/CoreLibrary/Base/ComponentQueryExtensions.cs index 618da3b..05043b2 100644 --- a/src/CoreLibrary/Assets/Scripts/CoreLibrary/Base/ComponentQueryExtensions.cs +++ b/src/CoreLibrary/Assets/Scripts/CoreLibrary/Base/ComponentQueryExtensions.cs @@ -148,6 +148,23 @@ public static bool Is(this Collision col, out T result, Search where = Search { return col.gameObject.Is(out result, where); } + + /// + public static bool Is(this TSource obj, out TResult ret, Search where = Search.InObjectOnly) + where TResult : class + { + // `obj is TResult t` only works with C# 7.1 or higher. + if (obj is TResult) { + ret = obj as TResult; + return true; + } + // Same as above. + if (obj is Component) { + return (obj as Component).Is(out ret, where); + } + ret = null; + return false; + } /// Optional search scope if the object itself does not have the component. /// The type of the component to find. @@ -169,6 +186,14 @@ public static bool Is(this Collision col, Search where = Search.InObjectOnly) { return col.gameObject.Is(where); } + + /// + public static bool Is(this TSource obj, Search where = Search.InObjectOnly) + where TResult : class + { + TResult unused; + return obj.Is(out unused, where); + } /// Optional search scope if the object itself does not have the component. /// The type of the component to find.