FindClass() public static method

Find a class from an assembly by name.
public static FindClass ( string assemblyName, string className ) : Type
assemblyName string Name of the assembly to search for.
className string Name of the class to find.
return System.Type
Ejemplo n.º 1
0
        /// <summary>
        /// Enable the latest VersionHandler DLL if it's not already loaded.
        /// </summary>
        private static void BootStrap()
        {
            var bootStrapping = BootStrapping;
            var implAvailable = Impl != null;

            // If the VersionHandler assembly is already loaded or we're still bootstrapping we have
            // nothing to do.
            if (bootStrapping)
            {
                BootStrapping = !implAvailable;
                return;
            }
            EditorApplication.update -= BootStrap;
            if (implAvailable)
            {
                return;
            }

            var assemblies = new List <Match>();

            foreach (string assetGuid in AssetDatabase.FindAssets("l:gvh"))
            {
                string filename = AssetDatabase.GUIDToAssetPath(assetGuid);
                var    match    = VERSION_HANDLER_FILENAME_RE.Match(filename);
                if (match.Success)
                {
                    assemblies.Add(match);
                }
            }
            if (assemblies.Count == 0)
            {
                UnityEngine.Debug.LogWarning(String.Format("No {0} DLL found to bootstrap",
                                                           VERSION_HANDLER_ASSEMBLY_NAME));
                return;
            }
            // Sort assembly paths by version number.
            string mostRecentAssembly      = null;
            var    mostRecentVersionNumber = -1;

            foreach (var match in assemblies)
            {
                var filename = match.Groups[0].Value;
                var version  = match.Groups[2].Value;
                // Convert a multi-component version number to a string.
                var components = version.Split(new [] { '.' });
                Array.Reverse(components);
                var versionNumber              = 0;
                var componentMultiplier        = 1000;
                var currentComponentMultiplier = 1;
                foreach (var component in components)
                {
                    try {
                        versionNumber += Int32.Parse(component) * currentComponentMultiplier;
                    } catch (FormatException) {
                        // Ignore the component.
                    }
                    currentComponentMultiplier *= componentMultiplier;
                }
                if (versionNumber > mostRecentVersionNumber)
                {
                    mostRecentVersionNumber = versionNumber;
                    mostRecentAssembly      = filename;
                }
            }
            if (String.IsNullOrEmpty(mostRecentAssembly))
            {
                UnityEngine.Debug.LogWarning(String.Format("Failed to get the most recent {0} DLL.  " +
                                                           "Unable to bootstrap.",
                                                           VERSION_HANDLER_ASSEMBLY_NAME));
                return;
            }
            BootStrapping = true;
            if (VersionHandler.FindClass("UnityEditor", "UnityEditor.PluginImporter") != null)
            {
                EnableEditorPlugin(mostRecentAssembly);
            }
            else
            {
                ReimportPlugin(mostRecentAssembly);
            }
        }