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;
        }
Exemplo n.º 2
0
 internal static void ShutdownModuleManager()
 {
     if (ModuleManager.s_PackageManager != null)
     {
         ModuleManager.s_PackageManager.Shutdown(true);
     }
     ModuleManager.s_PackageManager  = null;
     ModuleManager.s_PlatformModules = null;
     ModuleManager.s_EditorModules   = null;
 }
Exemplo n.º 3
0
 internal static void Shutdown()
 {
     if (ModuleManager.s_PackageManager != null)
     {
         ((IEditorModule)ModuleManager.s_PackageManager).Shutdown(true);
     }
     ModuleManager.s_PackageManager  = (IPackageManagerModule)null;
     ModuleManager.s_PlatformModules = (List <IPlatformSupportModule>)null;
     ModuleManager.s_EditorModules   = (List <IEditorModule>)null;
 }
        private void OnAttachToPanelDelayed()
        {
            foreach (KeyValuePair <string, IPackageManagerModule> kvp in modules)
            {
                IPackageManagerModule module = kvp.Value;
                module.Initialize();

                if (WasEnabled(module))
                {
                    module.Enable();
                }
            }
        }
        private void DisableAndDisposeModules()
        {
            foreach (KeyValuePair <string, IPackageManagerModule> kvp in modules)
            {
                IPackageManagerModule module = kvp.Value;

                if (module.IsEnabled)
                {
                    module.Disable();
                }

                module.Dispose();
            }
        }
        private void ToggleModule(DropdownMenuAction dropdownMenuAction)
        {
            IPackageManagerModule module = modules[(string)dropdownMenuAction.userData];

            if (module.IsEnabled)
            {
                module.Disable();
            }
            else
            {
                module.Enable();
            }

            EditorPrefs.SetBool(GetKey(module, KEY_ENABLED), module.IsEnabled);
        }
Exemplo n.º 7
0
        public TinyIoCContainer CreateContainerForAssembly(Assembly assembly)
        {
            IPackageManagerModule module = CreateModule(assembly);
            Type packageManagerType      = module.PackageManagerType;

            Debug.Assert(PackageManagerType.IsAssignableFrom(packageManagerType));

            var container = new TinyIoCContainer();

            module.RegisterDependencies(container);
            if (container.CanResolve <IPackageManager>())
            {
                throw new ConfigurationException("Package Manager should not be manually configured in the dependency injection container");
            }
            container.Register(PackageManagerType, packageManagerType);
            container.Register <ILogger>((c, p) => new Logger(new Context(packageManagerType.ToString()), _log));
            container.Register <IShellCommandRunner, ShellCommandRunner>();
            return(container);
        }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
0
        private static bool InitializePackageManager(Assembly assembly, Unity.DataContract.PackageInfo package)
        {
            ModuleManager.s_PackageManager = AssemblyHelper.FindImplementors <IPackageManagerModule>(assembly).FirstOrDefault <IPackageManagerModule>();
            bool result;

            if (ModuleManager.s_PackageManager == null)
            {
                result = false;
            }
            else
            {
                string location = assembly.Location;
                if (package != null)
                {
                    InternalEditorUtility.RegisterPrecompiledAssembly(Path.GetFileName(location), location);
                }
                else
                {
                    package = new Unity.DataContract.PackageInfo
                    {
                        basePath = Path.GetDirectoryName(location)
                    };
                }
                ModuleManager.s_PackageManager.moduleInfo        = package;
                ModuleManager.s_PackageManager.editorInstallPath = EditorApplication.applicationContentsPath;
                ModuleManager.s_PackageManager.unityVersion      = new PackageVersion(Application.unityVersion);
                ModuleManager.s_PackageManager.Initialize();
                foreach (Unity.DataContract.PackageInfo current in ModuleManager.s_PackageManager.playbackEngines)
                {
                    BuildTargetGroup buildTargetGroup;
                    BuildTarget      buildTarget;
                    if (ModuleManager.TryParseBuildTarget(current.name, out buildTargetGroup, out buildTarget))
                    {
                        if (ModuleManager.EnableLogging)
                        {
                            Console.WriteLine("Setting {4}:{0} v{1} for Unity v{2} to {3}", new object[]
                            {
                                buildTarget,
                                current.version,
                                current.unityVersion,
                                current.basePath,
                                buildTargetGroup
                            });
                        }
                        foreach (KeyValuePair <string, PackageFileData> current2 in from f in current.files
                                 where f.Value.type == PackageFileType.Dll
                                 select f)
                        {
                            string path = Path.Combine(current.basePath, current2.Key).NormalizePath();
                            if (!File.Exists(path))
                            {
                                UnityEngine.Debug.LogWarningFormat("Missing assembly \t{0} for {1}. Player support may be incomplete.", new object[]
                                {
                                    current.basePath,
                                    current.name
                                });
                            }
                            else
                            {
                                InternalEditorUtility.RegisterPrecompiledAssembly(Path.GetFileName(location), location);
                            }
                        }
                        BuildPipeline.SetPlaybackEngineDirectory(buildTarget, BuildOptions.None, current.basePath);
                        InternalEditorUtility.SetPlatformPath(current.basePath);
                        ModuleManager.s_PackageManager.LoadPackage(current);
                    }
                }
                result = true;
            }
            return(result);
        }
 private string GetKey(IPackageManagerModule module, string key)
 {
     return($"TNRD.PackageManagerModules.Module.{module.Identifier}.{key}");
 }
 private bool WasEnabled(IPackageManagerModule module)
 {
     return(EditorPrefs.GetBool(GetKey(module, KEY_ENABLED), false));
 }
        private DropdownMenuAction.Status GetModuleStatus(DropdownMenuAction dropdownMenuAction)
        {
            IPackageManagerModule module = modules[(string)dropdownMenuAction.userData];

            return(module.IsEnabled ? DropdownMenuAction.Status.Checked : DropdownMenuAction.Status.Normal);
        }
Exemplo n.º 13
0
        private static bool InitializePackageManager(Assembly assembly, PackageInfo package)
        {
            ModuleManager.s_PackageManager = AssemblyHelper.FindImplementors <IPackageManagerModule>(assembly).FirstOrDefault <IPackageManagerModule>();
            if (ModuleManager.s_PackageManager == null)
            {
                return(false);
            }
            string location = assembly.Location;

            if (PackageInfo.op_Inequality(package, (PackageInfo)null))
            {
                InternalEditorUtility.SetupCustomDll(Path.GetFileName(location), location);
            }
            else
            {
                package = new PackageInfo()
                {
                    basePath = (__Null)Path.GetDirectoryName(location)
                }
            };
            ((IEditorModule)ModuleManager.s_PackageManager).set_moduleInfo(package);
            ModuleManager.s_PackageManager.set_editorInstallPath(EditorApplication.applicationContentsPath);
            ModuleManager.s_PackageManager.set_unityVersion(PackageVersion.op_Implicit(new PackageVersion(Application.unityVersion)));
            ((IEditorModule)ModuleManager.s_PackageManager).Initialize();
            using (IEnumerator <PackageInfo> enumerator1 = ModuleManager.s_PackageManager.get_playbackEngines().GetEnumerator())
            {
                while (((IEnumerator)enumerator1).MoveNext())
                {
                    PackageInfo current1 = enumerator1.Current;
                    BuildTarget target   = BuildTarget.StandaloneWindows;
                    if (ModuleManager.TryParseBuildTarget((string)current1.name, out target))
                    {
                        Console.WriteLine("Setting {0} v{1} for Unity v{2} to {3}", new object[4]
                        {
                            (object)target,
                            (object)current1.version,
                            (object)current1.unityVersion,
                            (object)current1.basePath
                        });
                        using (IEnumerator <KeyValuePair <string, PackageFileData> > enumerator2 = ((IEnumerable <KeyValuePair <string, PackageFileData> >)current1.get_files()).Where <KeyValuePair <string, PackageFileData> >((Func <KeyValuePair <string, PackageFileData>, bool>)(f => f.Value.type == 3)).GetEnumerator())
                        {
                            while (((IEnumerator)enumerator2).MoveNext())
                            {
                                KeyValuePair <string, PackageFileData> current2 = enumerator2.Current;
                                if (!File.Exists(Path.Combine((string)current1.basePath, current2.Key).NormalizePath()))
                                {
                                    UnityEngine.Debug.LogWarningFormat("Missing assembly \t{0} for {1}. Player support may be incomplete.", new object[2]
                                    {
                                        (object)current1.basePath,
                                        (object)current1.name
                                    });
                                }
                                else
                                {
                                    InternalEditorUtility.SetupCustomDll(Path.GetFileName(location), location);
                                }
                            }
                        }
                        BuildPipeline.SetPlaybackEngineDirectory(target, BuildOptions.None, (string)current1.basePath);
                        InternalEditorUtility.SetPlatformPath((string)current1.basePath);
                        ModuleManager.s_PackageManager.LoadPackage(current1);
                    }
                }
            }
            return(true);
        }