public ModulesMenu()
        {
            SetMenuName();
            SetMenuStyle();

            List <Type> types = AppDomain.CurrentDomain.GetAssemblies()
                                .SelectMany(x => x.GetTypes())
                                .Where(x => !x.IsAbstract && Utilities.ImplementsOrInherits(x, typeof(IPackageManagerModule)))
                                .ToList();

            if (types.Count == 0)
            {
                menu.AppendAction("No modules available", null);
                return;
            }

            foreach (Type type in types)
            {
                IPackageManagerModule module = (IPackageManagerModule)Activator.CreateInstance(type);
                modules.Add(module.Identifier, module);

                menu.AppendAction(module.DisplayName, ToggleModule, GetModuleStatus, module.Identifier);

                module.Initialize();
                if (WasEnabled(module))
                {
                    module.Enable();
                }
            }

            RegisterCallback <AttachToPanelEvent>(OnAttachToPanel, TrickleDown.TrickleDown);
            RegisterCallback <DetachFromPanelEvent>(OnDetachFromPanel, TrickleDown.TrickleDown);
            CompilationPipeline.compilationStarted += OnStartCompiling;
        }
        private void OnAttachToPanelDelayed()
        {
            foreach (KeyValuePair <string, IPackageManagerModule> kvp in modules)
            {
                IPackageManagerModule module = kvp.Value;
                module.Initialize();

                if (WasEnabled(module))
                {
                    module.Enable();
                }
            }
        }
예제 #3
0
        static bool InitializePackageManager(Assembly assembly, Unity.DataContract.PackageInfo package)
        {
            s_PackageManager = AssemblyHelper.FindImplementors <IPackageManagerModule>(assembly).FirstOrDefault();

            if (s_PackageManager == null)
            {
                return(false);
            }

            string dllpath = assembly.Location;

            // if we have a package, it's because it came from the locator, which means we need to setup the dll
            // for loading on the next domain reloads
            if (package != null)
            {
                InternalEditorUtility.RegisterPrecompiledAssembly(Path.GetFileName(dllpath), dllpath);
            }

            else // just set the package with the path to the loaded assembly so package manager can get its information from there
            {
                package = new Unity.DataContract.PackageInfo()
                {
                    basePath = Path.GetDirectoryName(dllpath)
                }
            };

            s_PackageManager.moduleInfo        = package;
            s_PackageManager.editorInstallPath = EditorApplication.applicationContentsPath;
            s_PackageManager.unityVersion      = new PackageVersion(Application.unityVersion);

            s_PackageManager.Initialize();
            foreach (Unity.DataContract.PackageInfo engine in s_PackageManager.playbackEngines)
            {
                BuildTargetGroup buildTargetGroup;
                BuildTarget      target;
                if (!TryParseBuildTarget(engine.name, out buildTargetGroup, out target))
                {
                    continue;
                }

                if (EnableLogging)
                {
                    Console.WriteLine("Setting {4}:{0} v{1} for Unity v{2} to {3}", target, engine.version, engine.unityVersion, engine.basePath, buildTargetGroup);
                }
                foreach (var file in engine.files.Where(f => f.Value.type == PackageFileType.Dll))
                {
                    string fullPath = Paths.NormalizePath(Path.Combine(engine.basePath, file.Key));
                    if (!File.Exists(fullPath))
                    {
                        Debug.LogWarningFormat("Missing assembly \t{0} for {1}. Player support may be incomplete.", engine.basePath, engine.name);
                    }
                    else
                    {
                        InternalEditorUtility.RegisterPrecompiledAssembly(Path.GetFileName(dllpath), dllpath);
                    }
                }
                BuildPipeline.SetPlaybackEngineDirectory(target, BuildOptions.None /* TODO */, engine.basePath);
                InternalEditorUtility.SetPlatformPath(engine.basePath);
                s_PackageManager.LoadPackage(engine);
            }
            return(true);
        }