public static T GetInterface <T>(this GameObject inGameObject, bool includeInactive = false)
    {
        if (!UtilitiesReflection.IsInterface(typeof(T)))
        {
            throw new System.Exception("Specified type is not an interface!");
        }

        MonoBehaviour[] monoBehaviours = inGameObject.GetComponents <MonoBehaviour>(includeInactive);
        for (int i = 0; i < monoBehaviours.Length; i++)
        {
            MonoBehaviour mb = monoBehaviours[i];
            if (mb)
            {
                IEnumerator <System.Type> types = UtilitiesReflection.GetInterfaces(mb.GetType()).GetEnumerator();
                while (types.MoveNext())
                {
                    if (types.Current == typeof(T))
                    {
                        return((T)(object)mb);
                    }
                }
            }
        }

        return(default(T));
    }
    public static void GetInterfacesInChildrenNonAlloc <T>(this GameObject inGameObject, ref List <T> outList, bool includeChildren = false)
    {
        if (!UtilitiesReflection.IsInterface(typeof(T)))
        {
            throw new System.Exception("Specified type is not an interface!");
        }

        outList.Clear();

        MonoBehaviour[] monoBehaviours = inGameObject.GetComponentsInChildren <MonoBehaviour>(includeChildren);
        for (int i = 0; i < monoBehaviours.Length; i++)
        {
            MonoBehaviour mb = monoBehaviours[i];
            if (mb)
            {
                IEnumerator <System.Type> types = UtilitiesReflection.GetInterfaces(mb.GetType()).GetEnumerator();
                while (types.MoveNext())
                {
                    if (types.Current == typeof(T))
                    {
                        outList.Add((T)(object)mb);
                    }
                }
            }
        }
    }
    public static void CloneFields(object dest, object source)
    {
        if (dest.GetType() != source.GetType())
        {
            return;
        }

        foreach (FieldInfo field in UtilitiesReflection.GetFields(dest.GetType(), BindingFlags.Public))
        {
            field.SetValue(dest, field.GetValue(source));
        }
    }
    public static T[] GetInterfaces <T>(this GameObject inGameObject)
    {
        if (!UtilitiesReflection.IsInterface(typeof(T)))
        {
            throw new System.Exception("Specified type is not an interface!");
        }

        MonoBehaviour[] monoBehaviours = inGameObject.GetComponents <MonoBehaviour>();
        return(monoBehaviours.Where(mb => mb != null && UtilitiesReflection.GetInterfaces(mb.GetType()).Any(iType => iType == typeof(T)))
               .Select(mb => (T)(object)mb)
               .ToArray());
    }