public static void ExtractAllClassesThatInheritMonoBehaviourAndScriptableObject(string path, out string[] classNamesArray, out string[] classNameSpacesArray) { List <string> list = new List <string>(); List <string> list2 = new List <string>(); ReaderParameters readerParameters = new ReaderParameters(); DefaultAssemblyResolver defaultAssemblyResolver = new DefaultAssemblyResolver(); defaultAssemblyResolver.AddSearchDirectory(Path.GetDirectoryName(path)); readerParameters.AssemblyResolver = defaultAssemblyResolver; AssemblyDefinition assemblyDefinition = AssemblyDefinition.ReadAssembly(path, readerParameters); foreach (ModuleDefinition current in assemblyDefinition.Modules) { foreach (TypeDefinition current2 in current.Types) { TypeReference baseType = current2.BaseType; if (AssemblyHelper.IsTypeMonoBehaviourOrScriptableObject(assemblyDefinition, baseType)) { list.Add(current2.Name); list2.Add(current2.Namespace); } } } classNamesArray = list.ToArray(); classNameSpacesArray = list2.ToArray(); }
private static bool IsTypeMonoBehaviourOrScriptableObject(AssemblyDefinition assembly, TypeReference type) { bool result; if (type == null) { result = false; } else if (type.FullName == "System.Object") { result = false; } else { Assembly assembly2 = null; if (type.Scope.Name == "UnityEngine") { assembly2 = typeof(MonoBehaviour).Assembly; } else if (type.Scope.Name == "UnityEditor") { assembly2 = typeof(EditorWindow).Assembly; } else if (type.Scope.Name == "UnityEngine.UI") { assembly2 = AssemblyHelper.FindLoadedAssemblyWithName("UnityEngine.UI"); } if (assembly2 != null) { string name = (!type.IsGenericInstance) ? type.FullName : (type.Namespace + "." + type.Name); Type type2 = assembly2.GetType(name); if (type2 == typeof(MonoBehaviour) || type2.IsSubclassOf(typeof(MonoBehaviour))) { result = true; return(result); } if (type2 == typeof(ScriptableObject) || type2.IsSubclassOf(typeof(ScriptableObject))) { result = true; return(result); } } TypeDefinition typeDefinition = null; try { typeDefinition = type.Resolve(); } catch (AssemblyResolutionException) { } result = (typeDefinition != null && AssemblyHelper.IsTypeMonoBehaviourOrScriptableObject(assembly, typeDefinition.BaseType)); } return(result); }
public static void ExtractAllClassesThatInheritMonoBehaviourAndScriptableObject(string path, out string[] classNamesArray, out string[] classNameSpacesArray) { List <string> list = new List <string>(); List <string> list2 = new List <string>(); ReaderParameters readerParameters = new ReaderParameters(); DefaultAssemblyResolver defaultAssemblyResolver = new DefaultAssemblyResolver(); defaultAssemblyResolver.AddSearchDirectory(Path.GetDirectoryName(path)); readerParameters.set_AssemblyResolver(defaultAssemblyResolver); AssemblyDefinition assemblyDefinition = AssemblyDefinition.ReadAssembly(path, readerParameters); using (Collection <ModuleDefinition> .Enumerator enumerator = assemblyDefinition.get_Modules().GetEnumerator()) { while (enumerator.MoveNext()) { ModuleDefinition current = enumerator.get_Current(); using (Collection <TypeDefinition> .Enumerator enumerator2 = current.get_Types().GetEnumerator()) { while (enumerator2.MoveNext()) { TypeDefinition current2 = enumerator2.get_Current(); TypeReference baseType = current2.get_BaseType(); try { if (AssemblyHelper.IsTypeMonoBehaviourOrScriptableObject(assemblyDefinition, baseType)) { list.Add(current2.get_Name()); list2.Add(current2.get_Namespace()); } } catch (Exception) { UnityEngine.Debug.LogError(string.Concat(new string[] { "Failed to extract ", current2.get_FullName(), " class of base type ", baseType.get_FullName(), " when inspecting ", path })); } } } } } classNamesArray = list.ToArray(); classNameSpacesArray = list2.ToArray(); }
private static bool IsTypeMonoBehaviourOrScriptableObject(AssemblyDefinition assembly, TypeReference type) { if (type == null) { return(false); } if (type.FullName == "System.Object") { return(false); } Assembly assembly2 = null; if (type.Scope.Name == "UnityEngine") { assembly2 = typeof(MonoBehaviour).Assembly; } else { if (type.Scope.Name == "UnityEditor") { assembly2 = typeof(EditorWindow).Assembly; } } if (assembly2 != null) { Type type2 = assembly2.GetType(type.FullName); if (type2 == typeof(MonoBehaviour) || type2.IsSubclassOf(typeof(MonoBehaviour))) { return(true); } if (type2 == typeof(ScriptableObject) || type2.IsSubclassOf(typeof(ScriptableObject))) { return(true); } } TypeDefinition typeDefinition = null; try { typeDefinition = type.Resolve(); } catch (AssemblyResolutionException) { } return(typeDefinition != null && AssemblyHelper.IsTypeMonoBehaviourOrScriptableObject(assembly, typeDefinition.BaseType)); }
public static void ExtractAllClassesThatInheritMonoBehaviourAndScriptableObject(string path, out string[] classNamesArray, out string[] classNameSpacesArray) { List <string> stringList1 = new List <string>(); List <string> stringList2 = new List <string>(); ReaderParameters readerParameters = new ReaderParameters(); DefaultAssemblyResolver assemblyResolver = new DefaultAssemblyResolver(); ((BaseAssemblyResolver)assemblyResolver).AddSearchDirectory(Path.GetDirectoryName(path)); readerParameters.set_AssemblyResolver((IAssemblyResolver)assemblyResolver); AssemblyDefinition assembly = AssemblyDefinition.ReadAssembly(path, readerParameters); using (Collection <ModuleDefinition> .Enumerator enumerator1 = assembly.get_Modules().GetEnumerator()) { // ISSUE: explicit reference operation while (((Collection <ModuleDefinition> .Enumerator)@enumerator1).MoveNext()) { // ISSUE: explicit reference operation using (Collection <TypeDefinition> .Enumerator enumerator2 = ((Collection <ModuleDefinition> .Enumerator)@enumerator1).get_Current().get_Types().GetEnumerator()) { // ISSUE: explicit reference operation while (((Collection <TypeDefinition> .Enumerator)@enumerator2).MoveNext()) { // ISSUE: explicit reference operation TypeDefinition current = ((Collection <TypeDefinition> .Enumerator)@enumerator2).get_Current(); TypeReference baseType = current.get_BaseType(); try { if (AssemblyHelper.IsTypeMonoBehaviourOrScriptableObject(assembly, baseType)) { stringList1.Add(((TypeReference)current).get_Name()); stringList2.Add(((TypeReference)current).get_Namespace()); } } catch (Exception ex) { UnityEngine.Debug.LogError((object)("Failed to extract " + ((TypeReference)current).get_FullName() + " class of base type " + baseType.get_FullName() + " when inspecting " + path)); } } } } } classNamesArray = stringList1.ToArray(); classNameSpacesArray = stringList2.ToArray(); }
private static bool IsTypeMonoBehaviourOrScriptableObject(AssemblyDefinition assembly, TypeReference type) { if (type == null || type.get_FullName() == "System.Object") { return(false); } Assembly assembly1 = (Assembly)null; if (type.get_Scope().get_Name() == "UnityEngine") { assembly1 = typeof(MonoBehaviour).Assembly; } else if (type.get_Scope().get_Name() == "UnityEditor") { assembly1 = typeof(EditorWindow).Assembly; } else if (type.get_Scope().get_Name() == "UnityEngine.UI") { assembly1 = AssemblyHelper.FindLoadedAssemblyWithName("UnityEngine.UI"); } if (assembly1 != null) { string name = !type.get_IsGenericInstance() ? type.get_FullName() : type.get_Namespace() + "." + type.get_Name(); System.Type type1 = assembly1.GetType(name); if (type1 == typeof(MonoBehaviour) || type1.IsSubclassOf(typeof(MonoBehaviour)) || (type1 == typeof(ScriptableObject) || type1.IsSubclassOf(typeof(ScriptableObject)))) { return(true); } } TypeDefinition typeDefinition = (TypeDefinition)null; try { typeDefinition = type.Resolve(); } catch (AssemblyResolutionException ex) { } if (typeDefinition != null) { return(AssemblyHelper.IsTypeMonoBehaviourOrScriptableObject(assembly, typeDefinition.get_BaseType())); } return(false); }
public static void ExtractAllClassesThatInheritMonoBehaviourAndScriptableObject(string path, out string[] classNamesArray, out string[] classNameSpacesArray) { List <string> list = new List <string>(); List <string> list2 = new List <string>(); ReaderParameters readerParameters = new ReaderParameters(); DefaultAssemblyResolver defaultAssemblyResolver = new DefaultAssemblyResolver(); defaultAssemblyResolver.AddSearchDirectory(Path.GetDirectoryName(path)); readerParameters.AssemblyResolver = defaultAssemblyResolver; AssemblyDefinition assemblyDefinition = AssemblyDefinition.ReadAssembly(path, readerParameters); foreach (ModuleDefinition current in assemblyDefinition.Modules) { foreach (TypeDefinition current2 in current.Types) { TypeReference baseType = current2.BaseType; try { if (AssemblyHelper.IsTypeMonoBehaviourOrScriptableObject(assemblyDefinition, baseType)) { list.Add(current2.Name); list2.Add(current2.Namespace); } } catch (Exception) { UnityEngine.Debug.LogError(string.Concat(new string[] { "Failed to extract ", current2.FullName, " class of base type ", baseType.FullName, " when inspecting ", path })); } } } classNamesArray = list.ToArray(); classNameSpacesArray = list2.ToArray(); }