UnityEditor.CodeStrippingUtils.CollectManagedTypeReferencesFromRoots C# (CSharp) Method

CollectManagedTypeReferencesFromRoots() private static method

private static CollectManagedTypeReferencesFromRoots ( string directory, string rootAssemblies ) : HashSet
directory string
rootAssemblies string
return HashSet
        private static HashSet<string> CollectManagedTypeReferencesFromRoots(string directory, string[] rootAssemblies)
        {
            HashSet<string> set = new HashSet<string>();
            AssemblyReferenceChecker checker = new AssemblyReferenceChecker();
            bool withMethods = false;
            bool ignoreSystemDlls = false;
            checker.CollectReferencesFromRoots(directory, rootAssemblies, withMethods, 0f, ignoreSystemDlls);
            string[] assemblyFileNames = checker.GetAssemblyFileNames();
            AssemblyDefinition[] assemblyDefinitions = checker.GetAssemblyDefinitions();
            foreach (AssemblyDefinition definition in assemblyDefinitions)
            {
                foreach (TypeDefinition definition2 in definition.MainModule.Types)
                {
                    if (definition2.Namespace.StartsWith("UnityEngine") && (((definition2.Fields.Count > 0) || (definition2.Methods.Count > 0)) || (definition2.Properties.Count > 0)))
                    {
                        string name = definition2.Name;
                        set.Add(name);
                    }
                }
            }
            AssemblyDefinition definition3 = null;
            for (int i = 0; i < assemblyFileNames.Length; i++)
            {
                if (assemblyFileNames[i] == "UnityEngine.dll")
                {
                    definition3 = assemblyDefinitions[i];
                }
            }
            foreach (AssemblyDefinition definition4 in assemblyDefinitions)
            {
                if (definition4 != definition3)
                {
                    IEnumerator<TypeReference> enumerator = definition4.MainModule.GetTypeReferences().GetEnumerator();
                    try
                    {
                        while (enumerator.MoveNext())
                        {
                            TypeReference current = enumerator.Current;
                            if (current.Namespace.StartsWith("UnityEngine"))
                            {
                                string item = current.Name;
                                set.Add(item);
                            }
                        }
                    }
                    finally
                    {
                        if (enumerator == null)
                        {
                        }
                        enumerator.Dispose();
                    }
                }
            }
            return set;
        }

Usage Example

示例#1
0
        private static HashSet <UnityType> CollectNativeClassListFromRoots(string directory, string[] rootAssemblies, StrippingInfo strippingInfo)
        {
            HashSet <string>        source     = CodeStrippingUtils.CollectManagedTypeReferencesFromRoots(directory, rootAssemblies, strippingInfo);
            IEnumerable <UnityType> collection = from name in source
                                                 select UnityType.FindTypeByName(name) into klass
                                                     where klass != null && klass.baseClass != null
                                                 select klass;

            return(new HashSet <UnityType>(collection));
        }
All Usage Examples Of UnityEditor.CodeStrippingUtils::CollectManagedTypeReferencesFromRoots