private static IEnumerable <string> GetScriptGuids(Recursion recursion, Type type) { if (!recursion?.TryEnter(type) ?? false) { yield break; } if (typesToGuids.ContainsKey(type)) { foreach (var guid in typesToGuids[type]) { yield return(guid); } } // Recurse inside the type. // For example, a List<Enemy> or an Enemy[] type should return the script GUID for Enemy. if (type.IsGenericType) { foreach (var genericArgument in type.GetGenericArguments()) { foreach (var genericGuid in GetScriptGuids(recursion, genericArgument)) { yield return(genericGuid); } } } else if (type.HasElementType) { foreach (var genericGuid in GetScriptGuids(recursion, type.GetElementType())) { yield return(genericGuid); } } recursion?.Exit(type); }