static ILPostProcessResult GeneratePropertyBags(AssemblyDefinition compiledAssembly, string[] defines) { var context = new Context(compiledAssembly.MainModule, defines); // TODO: collection pools var fields = new List <FieldInfo>(); var properties = new List <PropertyInfo>(); #if UNITY_2020_2_OR_NEWER var editorAssemblyPath = Assembly.GetAssembly(typeof(EditorApplication)).Location; var editorPath = editorAssemblyPath.Substring(0, editorAssemblyPath.Length - k_EditorAssemblyPathSuffix); #else var editorPath = EditorApplication.applicationContentsPath; #endif var serializableContainerTypes = new HashSet <Type>(); var assemblyExceptions = RuntimeSerializationSettingsUtils.GetAssemblyExceptions(); var namespaceExceptions = RuntimeSerializationSettingsUtils.GetNamespaceExceptions(); var typeExceptions = RuntimeSerializationSettingsUtils.GetTypeExceptions(); ReflectionUtils.ForEachAssembly(assembly => { Console.WriteLine($"Process assembly {assembly.FullName}"); if (assembly.IsDynamic) { return; } if (!CodeGenUtils.IsBuiltInAssembly(assembly, editorPath)) { return; } if (assemblyExceptions.Contains(assembly.FullName)) { return; } PostProcessAssembly(namespaceExceptions, typeExceptions, assembly, fields, properties, serializableContainerTypes); }); serializableContainerTypes.ExceptWith(k_IgnoredTypes); if (serializableContainerTypes.Count == 0) { return(null); } GeneratePropertyBagsForSerializableTypes(context, serializableContainerTypes); return(CreatePostProcessResult(compiledAssembly)); }
public override void OnGUI(string searchContext) { base.OnGUI(searchContext); GUILayout.Label("AOT Code Generation Exceptions", EditorStyles.boldLabel); var assemblyExceptions = RuntimeSerializationSettingsUtils.GetAssemblyExceptions(); var namespaceExceptions = RuntimeSerializationSettingsUtils.GetNamespaceExceptions(); var typeExceptions = RuntimeSerializationSettingsUtils.GetTypeExceptions(); DrawButtons(assemblyExceptions, "assemblies", m_ExcludeAllAssemblies, k_ClearExceptions); DrawButtons(namespaceExceptions, "namespaces", m_ExcludeAllNamespaces, k_ClearExceptions); DrawButtons(typeExceptions, "types", m_ExcludeAllTypes, k_ClearExceptions); foreach (var assemblyRow in m_AssemblyRows) { assemblyRow.Draw(assemblyExceptions, namespaceExceptions, typeExceptions); } }
static ILPostProcessResult ProcessAssembly(AssemblyDefinition compiledAssembly) { var module = compiledAssembly.MainModule; var componentTypes = new List <TypeContainer>(); #if UNITY_2020_2_OR_NEWER var editorAssemblyPath = Assembly.GetAssembly(typeof(EditorApplication)).Location; var editorPath = editorAssemblyPath.Substring(0, editorAssemblyPath.Length - k_EditorAssemblyPathSuffix); #else var editorPath = EditorApplication.applicationContentsPath; #endif var assemblyExceptions = RuntimeSerializationSettingsUtils.GetAssemblyExceptions(); var namespaceExceptions = RuntimeSerializationSettingsUtils.GetNamespaceExceptions(); var typeExceptions = RuntimeSerializationSettingsUtils.GetTypeExceptions(); ReflectionUtils.ForEachAssembly(assembly => { if (assembly.IsDynamic) { return; } if (!CodeGenUtils.IsBuiltInAssembly(assembly, editorPath) && !k_PlayerAssemblies.Contains(assembly.GetName().Name)) { return; } if (assemblyExceptions.Contains(assembly.FullName)) { return; } PostProcessAssembly(namespaceExceptions, typeExceptions, module, assembly, componentTypes); }); PostProcessGenericMethodWrapper(componentTypes, module); return(CreatePostProcessResult(compiledAssembly)); }
static void PostProcessAssembly(AssemblyDefinition assembly, HashSet <TypeDefinition> serializableTypes) { var namespaceExceptions = RuntimeSerializationSettingsUtils.GetNamespaceExceptions(); var typeExceptions = RuntimeSerializationSettingsUtils.GetTypeExceptions(); foreach (var module in assembly.Modules) { foreach (var type in module.GetTypes()) { if (type.IsAbstract || type.IsInterface) { continue; } if (type.HasGenericParameters && !type.IsGenericInstance) { continue; } var(hasSkipGenerationAttribute, hasCompilerGeneratedAttribute) = CodeGenUtils.GetSerializationAttributes(type); if (hasSkipGenerationAttribute || hasCompilerGeneratedAttribute) { continue; } if (!CodeGenUtils.IsAssignableToComponent(type)) { #if INCLUDE_ALL_SERIALIZABLE_CONTAINERS if (!CodeGenUtils.IsSerializableContainer(type)) #endif continue; } var typeName = type.FullName; if (string.IsNullOrEmpty(typeName)) { continue; } if (typeExceptions.Contains(typeName)) { continue; } var partOfNamespaceException = false; var typeNamespace = type.Namespace; if (!string.IsNullOrEmpty(typeNamespace)) { foreach (var exception in namespaceExceptions) { if (typeNamespace.Contains(exception)) { partOfNamespaceException = true; break; } } } if (partOfNamespaceException) { continue; } serializableTypes.Add(type); PostProcessType(type, serializableTypes); } } }